Skip to content

Folding Range Persistence Not Working for C# Extension #239789

@deepakrathore33

Description

@deepakrathore33

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)

Image

[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)

Image

[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:

  1. Install the C# extension.
  2. Open a C# file in VS Code containing code structures that would create overlapping folding ranges (e.g., nested if/else blocks).
  3. Attempt to fold the regions.
  4. Observe that folding behaves inconsistently, failing when startLine and endLine overlap.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions