question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Code folding not working properly in certain circumstances

See original GitHub issue

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

https://user-images.githubusercontent.com/9027551/186756324-d407768f-3190-4b80-92cb-30b4d8e1ce55.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)

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
DanTupcommented, Sep 29, 2022

Working on a fix at https://dart-review.googlesource.com/c/sdk/+/261900/. I’ll close this once it lands. It’s a change in the Dart analysis server, so will ship in a future SDK release (rather than a Dart VS Code extension release).

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Problem With Code Folding - Coding Horror
Folding is used to mask excessive length. The presence of folded code can lull developers into a false sense of what clean code...
Read more >
VSCode Code folding Error - Stack Overflow
It looks like the folding does not work for else if statement. Here is what I mean: no folding for else if statement...
Read more >
Coding folding does not work properly - Sublime Forum
I have correct indentation and I still cannot fold the code. I can solve the issue by selecting the portion of code and...
Read more >
271937 – Several code folding issues - Bugs - Eclipse
the folding fails to recognize regions that are foldable and produces horrible code layout with partly folded and unfolded parts at boundaries that...
Read more >
R2021b - code folding in switch/case not fully available
I need this to come back as well. I'm on R2022a and this has made a mess on some of my code that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found