Preserve line breaks after collapsed Razor blocks - #84630
Merged
Merged
Conversation
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
|
Azure Pipelines: Successfully started running 2 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
davidwengier
commented
Jul 27, 2026
| Goodbye World | ||
| </div> | ||
| |] } | ||
| |] } |
Member
Author
There was a problem hiding this comment.
This test had an errant extra close brace, so removed that too
Contributor
There was a problem hiding this comment.
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
@ifblocks. - 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. |
chsienki
approved these changes
Jul 27, 2026
This was referenced Jul 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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