Skip to content

Fix on-type and code action formatting on Razor explicit statements - #84699

Merged
davidwengier merged 3 commits into
dotnet:mainfrom
davidwengier:test-razor-invert-if-block
Jul 30, 2026
Merged

Fix on-type and code action formatting on Razor explicit statements#84699
davidwengier merged 3 commits into
dotnet:mainfrom
davidwengier:test-razor-invert-if-block

Conversation

@davidwengier

@davidwengier davidwengier commented Jul 30, 2026

Copy link
Copy Markdown
Member

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

davidwengier and others added 3 commits July 30, 2026 11:37
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
@davidwengier
davidwengier requested a review from a team as a code owner July 30, 2026 02:37
Copilot AI review requested due to automatic review settings July 30, 2026 02:37
@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.

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’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 CSharpOnTypeFormattingPass to 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 If code 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.

@davidwengier
davidwengier merged commit dc1db3e into dotnet:main Jul 30, 2026
27 checks passed
@davidwengier
davidwengier deleted the test-razor-invert-if-block branch July 30, 2026 21:46
@jjonescz jjonescz added this to the 18.11 milestone Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants