-
Notifications
You must be signed in to change notification settings - Fork 38.2k
Description
Does this issue occur when all extensions are disabled?: No
VS Code Version: 1.96.4
OS Version: Windows_NT x64 10.0.26100
Extension: C#
Related Issue: vscode-chsarp:#6270
Description:
Folding regions in C# files are not persisting correctly. This issue seems related to the C# extension and specifically occurs when the startLine of a folding range overlaps with the endLine of another folding range. When this overlap happens, the folding for the "else" condition (or similar block) is unavailable. If there is no overlap, folding works as expected.
Details:
I've observed this behavior by examining the LSP traffic. Below are examples of the textDocument/foldingRange requests and responses, demonstrating the difference between overlapping and non-overlapping scenarios.
Scenario 1: Start Line Overlaps End Line (Folding Fails)
[Trace - 3:35:08 PM] Sending request 'textDocument/foldingRange - (19)'.
Params: {
"textDocument": {
"uri": "file:///q:/source/ConsoleApp2/ConsoleApp2/Program.cs"
}
}
[Trace - 3:35:08 PM] Received response 'textDocument/foldingRange - (19)' in 327ms.
Result: [
{
"startLine": 3,
"startCharacter": 6,
"endLine": 5,
"endCharacter": 1,
"collapsedText": "..."
},
{
"startLine": 1,
"startCharacter": 9,
"endLine": 3,
"endCharacter": 1,
"collapsedText": "..."
}
]Scenario 2: Start Line Does Not Overlap End Line (Folding Works)
[Trace - 4:45:53 PM] Sending request 'textDocument/foldingRange - (86)'.
Params: {
"textDocument": {
"uri": "file:///q:/source/ConsoleApp2/ConsoleApp2/Program.cs"
}
}
[Trace - 4:45:53 PM] Received response 'textDocument/foldingRange - (86)' in 4ms.
Result: [
{
"startLine": 4,
"startCharacter": 4,
"endLine": 6,
"endCharacter": 1,
"collapsedText": "..."
},
{
"startLine": 1,
"startCharacter": 13,
"endLine": 3,
"endCharacter": 1,
"collapsedText": "..."
}
]Steps to Reproduce:
- Install the C# extension.
- Open a C# file in VS Code containing code structures that would create overlapping folding ranges (e.g., nested
if/elseblocks). - Attempt to fold the regions.
- Observe that folding behaves inconsistently, failing when
startLineandendLineoverlap.

