Skip to content

Conversation

@dibarbet
Copy link
Member

@dibarbet dibarbet commented Oct 29, 2025

Fixes dotnet/vscode-csharp#7974
Unblocks #80944 (comment)

VSCode sets the lineFoldingOnly LSP capability, indicating it cannot handle multiple folding ranges that start on the same line as another range starts or ends on. Folding ranges that are not compatible are simply dropped.

While we cannot always do anything more than drop one of the ranges, we can choose which range to drop and we can sometimes adjust ranges so that they will not be dropped:

  1. If two ranges start on the same line, we want to pick the inner range for folding.
  2. If a range ends on the same line as another starts, we can attempt to shrink it by one line to handle common cases like an else block starting on the same line as the if block ended:
if (blah) {
    ...
} else {
    ...
}

This is done as a post processing step of the ranges. This seemed reasonable as the service generally independently constructs folding ranges based on the syntax and has little knowledge of what the other ranges will be produced (to know if they overlap)

folding_ranges_overlap

@dibarbet dibarbet requested a review from a team as a code owner October 29, 2025 23:56
@dibarbet dibarbet merged commit 01d9867 into dotnet:main Oct 30, 2025
25 checks passed
@dibarbet dibarbet deleted the line_overlap_folding branch October 30, 2025 20:05
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Oct 30, 2025
davidwengier added a commit to dotnet/razor that referenced this pull request Nov 3, 2025
Three things I've been tracking from Roslyn:

1. Auto insert support for raw string literals:
dotnet/roslyn#80871
2. Line Folding Only support in VS Code:
dotnet/roslyn#80955 (fixes
#12414)
	* We already did this in our folding range response anyway
3. Allow FormattingLogTest can use real types, and remove our temporary
equivalent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overlapping line folding ranges are sent to VS Code

2 participants