Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ public ImmutableArray<FoldingRange> GetFoldingRanges(RazorCodeDocument codeDocum
foreach (var node in nodes)
{
var (start, end) = sourceText.GetLinePositionSpan(node.Span);

// Razor nodes can include the line break after their closing brace. Folding that line break
// pulls the following content onto the collapsed line.
if (end.Character == 0 && end.Line > start.Line)
{
var previousLine = sourceText.Lines[end.Line - 1];
end = new(end.Line - 1, previousLine.Span.Length);
}

var foldingRange = new FoldingRange()
{
StartCharacter = start.Character,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public Task BadLooseFileUri()
<div>
Hello World
</div>
}
|]</div>
}|]
</div>

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

@if (true) {[|
}|]
""",
Expand All @@ -52,20 +52,35 @@ public Task IfStatements(bool miscellaneousFile)
<div>
Hello World
</div>
}
|]</div>
}|]
</div>

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

@if (true) {[|
}|]
""",
miscellaneousFile: miscellaneousFile);

[Fact]
public Task IfStatements_Adjacent()
=> VerifyFoldingRangesAsync("""
@if (true) {[|
<div>
Hello World
</div>
}|]
@if (false) {[|
<div>
Goodbye World
</div>
}|]
""");

[Fact]
public Task LockStatement()
=> VerifyFoldingRangesAsync("""
Expand All @@ -92,8 +107,7 @@ Hello World
<div>
Goodbye World
</div>
}|]
|] }
}|]|]
</div>
""");

Expand Down Expand Up @@ -285,8 +299,7 @@ Hello World
<div>
Goodbye World
</div>
|] }
|] }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test had an errant extra close brace, so removed that too

|] }|]
</div>

@code[|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private void IncrementCount()
""");
}

[IdeFact(Skip = "https://github.com/dotnet/razor/issues/10860")] // FUSE changes whitespace on folding ranges
[IdeFact]
public async Task CodeFolding_IfBlock()
{
await TestServices.SolutionExplorer.AddFileAsync(
Expand Down
Loading