Adjust folding range end lines for lineFoldingOnly clients#2772
Adjust folding range end lines for lineFoldingOnly clients#2772DanielRosenwasser merged 4 commits intomainfrom
Conversation
When VS Code sends lineFoldingOnly: true, it hides lines from startLine+1 to endLine. Without adjustment, closing brackets (}, ], ), etc.) would be hidden when folding. This mirrors the VS Code TypeScript extension's adjustFoldingEnd behavior (workaround for vscode#47240). Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR aligns the Go language server’s folding range behavior with VS Code’s lineFoldingOnly semantics, preventing closing braces/brackets/tags from being hidden when a fold is applied (matching the stable TypeScript extension behavior referenced in vscode#47240).
Changes:
- Adjust folding range
endLineforlineFoldingOnlyclients when the fold ends on a closing pair character (},],),`,>). - Add fourslash helper
VerifyFoldingRangeLinesto assert folding behavior using only start/end lines. - Add an integration test covering the reported reproduction case with
lineFoldingOnly: true.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/ls/folding.go | Applies lineFoldingOnly end-line adjustment to keep closing delimiters visible when folding. |
| internal/fourslash/fourslash.go | Adds a line-only folding range verifier for lineFoldingOnly scenarios. |
| internal/fourslash/tests/foldingRangeLineFoldingOnly_test.go | New fourslash integration test validating adjusted end lines for nested blocks/functions. |
|
I guess I'll link to microsoft/vscode#281660 as well |
internal/ls/folding.go
Outdated
| // When lineFoldingOnly is true, VS Code hides lines from startLine+1 to endLine. To keep closing | ||
| // brackets/braces visible, we subtract 1 from endLine when the range ends with a closing pair character. |
There was a problem hiding this comment.
| // When lineFoldingOnly is true, VS Code hides lines from startLine+1 to endLine. To keep closing | |
| // brackets/braces visible, we subtract 1 from endLine when the range ends with a closing pair character. | |
| // When lineFoldingOnly is true, we hide lines from startLine+1 to endLine. And to keep closing | |
| // brackets/braces visible, we subtract 1 from endLine when the range ends with a closing pair character. |
|
Did you test this out on |
|
I didn't, no. @copilot Address the above comments, including adding a test which uses regions too. |
Update comment wording per DanielRosenwasser's suggestion. Add TestFoldingRangeLineFoldingOnlyWithRegions to verify that #region/#endregion spans are NOT adjusted (they don't end with closing pair characters), while code blocks within regions are. Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Added |
|
Tested, and the above is what Strada in VS Code does, so this PR I think is fine. Note: https://github.com/microsoft/vscode/blob/b5f3937f1211ce4b8ee7f614645b88a6464a9cb0/extensions/typescript-language-features/src/languageFeatures/folding.ts#L58 |
|
I guess they can't intersect anyway, but it was probably good to have something here. |
|
Needs a format I guess |


adjustFoldingEndwhen converting outlining spans to FoldingRange - it subtracts 1 from endLine when the range ends with a closing pair character (},],),`,>). The Go LSP server returns FoldingRanges directly without this adjustment, causing VS Code (which hidesendLine) to also hide the closing bracket line.adjustFoldingEndininternal/ls/folding.gothat mirrors the VS Code TypeScript extension's behaviorlineFoldingOnly: trueVerifyFoldingRangeLinesmethod to fourslash test frameworkOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.