Fix on-type and code action formatting on Razor explicit statements - #84699
Merged
davidwengier merged 3 commits intoJul 30, 2026
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 43fe0e8f-fe50-416d-8f56-bcbfe4420e4e
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 43fe0e8f-fe50-416d-8f56-bcbfe4420e4e
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 43fe0e8f-fe50-416d-8f56-bcbfe4420e4e
|
Azure Pipelines: Successfully started running 2 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts Razor’s C# on-type formatting indentation logic to special-case explicit statement delimiters (@{ ... }) so they don’t get incorrectly re-indented based on C# source mappings, and adds regression coverage across on-type formatting, document formatting, and code-action formatting paths.
Changes:
- Update
CSharpOnTypeFormattingPassto detect explicit statement delimiters and apply only Razor/HTML indentation (skipping C# source-mapped indentation). - Add an on-type formatting regression test covering
}formatting within an explicit statement block. - Add regression tests ensuring document formatting and the
Invert Ifcode action preserve/correct explicit-statement indentation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Razor/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.UnitTests/Cohost/Formatting/OnTypeFormattingTest.cs | Adds on-type formatting regression test for explicit statement scenarios. |
| src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.UnitTests/Formatting/DocumentFormattingTest.cs | Adds document-formatting regression tests covering mis-indented explicit statement opening braces. |
| src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.UnitTests/CodeActions/CSharpCodeActionTests.cs | Adds code-action regression test ensuring Invert If produces correctly formatted output within explicit statements. |
| src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/Passes/CSharpOnTypeFormattingPass.cs | Implements explicit-statement delimiter indentation handling by bypassing C# source-mapped indentation. |
chsienki
approved these changes
Jul 30, 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.
Noticed this today while testing something completely unrelated.
Review commit at a time if you want to see the current behaviour versus the fix, but its not a huge PR so up to you whether you care :)
Microsoft Reviewers: Open in CodeFlow