Repository navigation
When nested folding ranges end on the same line, the outer range is incorrectly truncated #5750
Copy link
Copy link
Closed
Labels
in editorRelates to code editing or language featuresRelates to code editing or language featuresin lsp/analysis serverSomething to be fixed in the Dart 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 availableSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
Milestone
Description
Describe the bug
Switch case folding doesn't fold until the next case if a function has parameters that span multiple lines (I think that is the issue, but maybe something similar at least?).
To Reproduce
Add a file with this sample:
Future<void> f() async {
switch (1) {
case 1:
print('something');
someBigFunctionName(
someReallyReallyLongNameHereSoItHasToSplit: 1234567,
);
case 2:
print('another thing');
print('yet another thing');
case 3:
print('more things');
}
}
void someBigFunctionName({
int? someReallyReallyLongNameHereSoItHasToSplit,
}) {}Try to fold at case 1 and see that it doesn't fold someBigFunctionName.
Expected behavior
It folds someBigFunctionName.
Please complete the following information:
Workspace Environment
Dart Code extension: 3.121.20250930
Flutter extension: 3.121.20250930 (activated)
App: Visual Studio Code
App Host: desktop
Version: win 1.105.0
Workspace type: Dart (LSP)
Workspace name: bug
Dart (3.11.0-edge.1974c2360e1ee4345b9cb15929b1a2465559dc18): C:\Users\felip_0vh5fa6\dart
Flutter (3.35.5): C:\Users\felip_0vh5fa6\.puro\envs\stable\flutter (No device)
Output from 'dart info'
C:\Users\felip_0vh5fa6\dart\bin\dart.exe info
If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.
General info
- Dart 3.11.0-edge.1974c2360e1ee4345b9cb15929b1a2465559dc18 (main) (Mon Oct 6 18:46:13 2025 -0700) on "windows_x64"
- on windows / "Windows 11 Pro" 10.0 (Build 26100)
- locale is pt-BR
Project info
- sdk constraint: '^3.9.0'
- dependencies: analyzer, bloc, meta
- dev_dependencies: lints, test, test_reflective_loader, very_good_analysis
Process info
| Memory | CPU | Elapsed time | Command line |
|---|---|---|---|
| 0 MB | -- | dart.exe | |
| 0 MB | -- | dart.exe | |
| 0 MB | -- | dart.exe | |
| 0 MB | -- | dart.exe | |
| 0 MB | -- | dart.exe | |
| 0 MB | -- | dart.exe | |
| 0 MB | -- | dart.exe | |
| 0 MB | -- | dart.exe | |
| 0 MB | -- | dart.exe | |
| 0 MB | -- | dartvm.exe | |
| 0 MB | -- | dartvm.exe | |
| 0 MB | -- | dartvm.exe | |
| 0 MB | -- | dartvm.exe |
- Operating System and version:
- VS Code version:
- Dart extension version:
- Dart/Flutter SDK version:
- Target device (if the issue relates to Flutter debugging):
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
in editorRelates to code editing or language featuresRelates to code editing or language featuresin lsp/analysis serverSomething to be fixed in the Dart 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 availableSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
Activity
FMorschel commentedon Oct 13, 2025
I've tried adding some tests to the same files you edited for https://dart-review.googlesource.com/c/sdk/+/431281, but I could not create a test that would fail even with the above example:
pkg/analysis_server/test/src/computer/folding_computer_test.dartpkg/analysis_server/test/lsp/folding_test.dartDanTup commentedon Oct 14, 2025
@FMorschel I think the second test you pasted is incorrect (just the same as the first?) and doesn't compile.
My first guess would be that this is related to line folding.. After computing the folding ranges, we have to do some work to merge/exclude some if the client only supports line-folding (which VS Code does) - see
_compensateForLineFolding. If it is, I think it's a bug though, because on the surface I don't see why we wouldn't produce the outer range as you'd expect.DanTup commentedon Oct 14, 2025
(I assume you're looking at this, but if you want me to, just let me know!)
FMorschel commentedon Oct 14, 2025
I ran both tests locally, and they passed. I'm not sure what you meant.
One thing I noticed was, if you close that section and reload the VS Code window (
Developer: Reload Window), it shows as fully folded until the extension and server start. At that point, it automatically moves out the invocation outside the folded region.I tried looking at this, yes, but since I had no luck reproducing on a test, you may have a better chance of figuring this one out, so please continue this, but feel free to ask for more guidance if you need any. Or if you're having trouble reproducing this.
DanTup commentedon Oct 14, 2025
I think you copied the same test twice into your comment above - the one you marked as LSP doesn't compile in the LSP file.
But if you're not looking at it, I'm happy to look, thanks!
FMorschel commentedon Oct 14, 2025
Oh, yeah, that's probably it hahaha. Here is the correct test:
[-]Switch case folding doesn't fold until the next `case`[/-][+]When nested folding ranges end on the same line, the outer range is incorrectly truncated[/+]DanTup commentedon Oct 14, 2025
Off-by-one error 😐
Got a fix at https://dart-review.googlesource.com/c/sdk/+/454920
folding.mp4
[analysis_server] Fix folding ranges when nested ranges end on the sa…
DanTup commentedon Oct 16, 2025
Fixed by dart-lang/sdk@ceb6b5f, ships in the SDK :-)