Skip to content

Preserve line breaks after collapsed Razor blocks - #84630

Merged
davidwengier merged 2 commits into
dotnet:mainfrom
davidwengier:fix-razor-collapse-line
Jul 27, 2026
Merged

davidwengier merged 2 commits into
dotnet:mainfrom
davidwengier:fix-razor-collapse-line

Conversation

@davidwengier

@davidwengier davidwengier commented Jul 27, 2026

Copy link
Copy Markdown
Member

Fixes #84617
Fixes dotnet/razor#10860

This broke with FUSE, and we logged the Razor issue to follow up, but I think we weren't sure what the "right" behaviour was. Well, the users have decided and for folding ranges at least, our current behaviour is wrong. So this fixes that. Sadly its really hard to see in tests that the current behaviour was ugly.

Microsoft Reviewers: Open in CodeFlow

davidwengier and others added 2 commits July 27, 2026 11:41
Razor syntax nodes can include the line break after their closing brace. Keep it outside the folding range so following content stays on its own line.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f41854b7-faf2-4b17-bf28-bd817df1cf31
Restore range ends at closing braces, cover adjacent @if blocks, and re-enable the integration test for dotnet/razor#10860.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f41854b7-faf2-4b17-bf28-bd817df1cf31
Copilot AI review requested due to automatic review settings July 27, 2026 01:42
@davidwengier
davidwengier requested a review from a team as a code owner July 27, 2026 01:42
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts Razor folding range calculation so that a trailing newline immediately after a folded Razor block is not included in the folding range, preventing subsequent content from being visually pulled onto the collapsed line. It also updates/extends folding-range test baselines and re-enables a previously skipped VS integration folding test.

Changes:

  • Update Razor syntax-node folding ranges to exclude a trailing line break when the node span ends at the start of the next line.
  • Update cohosting folding-range unit test baselines to match the revised end positions and add coverage for adjacent @if blocks.
  • Re-enable the Visual Studio Razor integration folding test that was previously skipped.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/FoldingRanges/AbstractSyntaxNodeFoldingProvider.cs Adjusts end positions for syntax-node folding ranges to keep trailing newlines outside the fold.
src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.UnitTests/Endpoints/CohostFoldingRangeEndpointTest.cs Updates folding range baseline markup and adds an adjacent @if regression case.
src/Razor/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/CodeFoldingTests.cs Removes the skip to re-run the @if folding integration test.

@davidwengier
davidwengier merged commit d9e3ded into dotnet:main Jul 27, 2026
27 checks passed
@davidwengier
davidwengier deleted the fix-razor-collapse-line branch July 27, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

when i collapse an @if in a .razor file, i get the subsequent stuff in the same line [FUSE] Folding range whitespace differences at the end of blocks

3 participants