dotnet / razor

Compiler and tooling experience for Razor ASP.NET Core apps in Visual Studio, Visual Studio for Mac, and VS Code.
https://asp.net
MIT License
498 stars 191 forks source link

Cannot collapse @if blocks in razor files #10443

Closed lonix1 closed 4 months ago

lonix1 commented 4 months ago

In any .cs file it's possible to collapse an if block. In a razor file that isn't possible:

@if (foo) {
  <div>
    ...
  </div>
}

When the document is collapsed, that code block remains expanded.

It would be nice to be able to collapse that if to have the same behaviour for both code and markup files.

Interestingly, the html within the block can be collapsed, but not the if block itself.

ryzngard commented 4 months ago

Thanks @lonix1 for filing. I'm not seeing this behavior locally. Do you have a repro here? This is what I'm seeing for what is available to be folded

image

lonix1 commented 4 months ago

Thanks.

I don't know why you can't repro. Strange. I'm using:

Suppose I create a new file and paste just this:


<div>
  @if (true) {
    <div>
      Hello World
    </div>
  }
</div>

@if (true) {
  <div>
    Hello World
  </div>
}

@if (true) {
}

None of those @if blocks are collapsible, though the outside/inside markup is collapsible. Also it does not seem to make a difference if I use end-of-line or next-line opening braces.

If you can't repro please close the issue, maybe someone will be able to add more detail (or a complete demo project) at a later date.

davidwengier commented 4 months ago

Turns out we don't support this, but VS does all on its own, presumably based on TextMate scopes or something. That at least explains why it works in VS not VS Code

ryzngard commented 4 months ago

Turns out we don't support this, but VS does all on its own, presumably based on TextMate scopes or something. That at least explains why it works in VS not VS Code

Interesting. Is this hard to add because of complexities in @if single vs multiline?

davidwengier commented 4 months ago

Nah, just a matter of finding the right nodes in the tree. PR in 5.