Repository navigation
Fix nested script indentation in Razor - #85289
Conversation
|
Azure Pipelines: Successfully started running 2 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
An unresolved moderate indentation issue remains, along with a requested nested style regression test.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes over-indentation of nested Razor script blocks by correcting HTML/C# indentation reconciliation.
Changes:
- Tracks enclosing HTML indentation levels.
- Adds regression coverage for nested script formatting.
Outstanding feedback includes a moderate indentation issue and a requested nested style test.
File summaries
| File | Summary |
|---|---|
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/Passes/CSharpFormattingPass.CSharpDocumentGenerator.cs |
Corrects indentation mapping. |
src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.UnitTests/Formatting/DocumentFormattingTest.cs |
Adds formatting regression tests. |
Review details
Suppressed comments (1)
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/Passes/CSharpFormattingPass.CSharpDocumentGenerator.cs:706
ElementCausesIndentationis not equivalent to an emitted structural brace here:VisitStartTagreturns before calling it for significant-whitespace elements such as<pre>and<textarea>. Therefore a multiline<pre>containing a multiline<script>or<style>is counted as an extra HTML level even though no brace was emitted for the<pre>, and the subtraction inCreateLineInforemoves one level too many. Exclude significant-whitespace ancestors, or otherwise count only elements that emitEmitOpenBraceLine.
if (node is BaseMarkupElementSyntax { StartTag: { } ancestorStartTag } &&
ElementCausesIndentation(ancestorStartTag))
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
There was a problem hiding this comment.
🔵 Needs a closer look
One or more issues must be addressed before approval.
Review details
Suppressed comments (1)
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/Passes/CSharpFormattingPass.CSharpDocumentGenerator.cs:706
ElementCausesIndentationdoes not imply that a structural brace was emitted for every ancestor here.VisitStartTagreturns from theElementHasSignificantWhitespacebranch before calling it for<pre>and<textarea>(lines 654-663), so a multiline significant-whitespace ancestor that contains a multiline<script>/<style>is counted here even though it contributes no generated C# indentation level.CreateLineInfothen subtracts one level too many and can under-indent the embedded content; exclude significant-whitespace ancestors or otherwise count only ancestors that emitEmitOpenBraceLine.
if (node is BaseMarkupElementSyntax { StartTag: { } ancestorStartTag } &&
ElementCausesIndentation(ancestorStartTag))
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
Fixes #85297
We had a bad assumption when combining html indentation from script blocks with razor/c# indentation for the same area. The fix is pretty simple, and I tried to create reasonable exhaustive tests so hopefully we won't regress this in future.
Microsoft Reviewers: Open in CodeFlow