Skip to content

Awfully misleading code folding on if statements. #6270

@StringEpsilon

Description

@StringEpsilon

Environment data

VS Code version: Version: 1.81.1 (user setup)
C# Extension version: v2.0.436

Steps to reproduce

  1. Create a new .cs file with the following code:
long foo = new Random().Next(1,10);
if (foo == 1) {
	Console.WriteLine("Foo is totally one");
} else {
	Console.WriteLine("Foo is absolutely not one").
}

Note: The bracket style is important.

  1. Fold the if statement.

Expected behavior

Line 3, with the "Foo is totally one" writeline gets folded in and hidden, while preserving the } else { to make it clear when the still visible line 5 is executed.

Actual behavior

The code fold is really misleading if one does not notice that the fold is active:

Before:
grafik

After:
grafik

Additional context

I know that the bracketing style in this example is not the recommended style. But there is no reason for the folding to behave like this. :)

I also tried the same scenario in JavaScript in VS Code and the misleading fold does not happen there.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions