Skip to content

Code folding not working properly in certain circumstances #4121

@andrewkolos

Description

@andrewkolos

Describe the bug

At least in top-level functions, code folding can sometimes be unavailable. For example, I might be able to fold a function signature, but not the implementation block (and some but not all blocks within). While this is difficult to describe, it is most easily observed through reproduction or the videos below.

The issue does not appear to happen in Android Studio, so I'm guessing this is not an SDK issue (though VSCode can fold parameter lists, while Android Studio cannot--I'm not sure if this is intended).

To Reproduce
Steps to reproduce the behavior:

  1. Clone https://github.com/flutter/flutter (head is f477c8b184d2364fcef0a15cee6ab5c909188229 at the time of writing)
  2. Open run_hot.dart (packages/flutter_tools/lib/src)
  3. Fold all code. This can be done by opening the command palette (Cmd/Ctrl+Shift+P) and typing Fold All.
  4. You should see multiple unfolded blocks of code. As a specific example, the body _defaultReassembleHelper won't be folded, and for loops within might not be folded as well. See screenshots below.

Expected behavior
All code blocks should be folded after issuing a Fold All command. Interestingly, copying the contents of the file into a new editor and then using Fold All appears to work as expected. However, saving the file (say, to my Desktop) will unfold the code, and if I try to Fold All again, it is still slightly broken.

Screenshots
The issue happening in run_hot.dart

2022-08-25_10-39-03.mp4

The issue not happening if I copy and paste a problematic function into a new editor:
https://user-images.githubusercontent.com/9027551/186756680-939ba825-7c52-44da-9324-b183e5add931.mp4

The issue happening if I save the new file to disk:
https://user-images.githubusercontent.com/9027551/186756837-88813e9f-1048-409e-9d83-c8e4e06bf0c5.mp4

Please complete the following information:

  • Operating System and version: macOS Monterey 12.5.1
  • VS Code version: 1.70.2
  • Dart extension version: 3.46.1
  • Dart/Flutter SDK version: 2.17.6
  • Target device (if the issue relates to Flutter debugging): N/A

I have reproduced this on Windows and another MacBook. Let me know if more information on those environments is needed.

(edit: typo)

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresin lsp/analysis serverSomething to be fixed in the Dart analysis serveris bugrelies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions