From 9ea83b343ec122d0bb94798411db46970b91f160 Mon Sep 17 00:00:00 2001 From: David Wengier Date: Fri, 7 Feb 2025 09:15:02 +1100 Subject: [PATCH] Fix formatting of escaped at signs --- ...pFormattingPass.CSharpDocumentGenerator.cs | 11 ++++ .../DocumentFormattingTest.cs | 52 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/Passes/New/CSharpFormattingPass.CSharpDocumentGenerator.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/Passes/New/CSharpFormattingPass.CSharpDocumentGenerator.cs index 7458c1158ea..2749cf9efc8 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/Passes/New/CSharpFormattingPass.CSharpDocumentGenerator.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/Passes/New/CSharpFormattingPass.CSharpDocumentGenerator.cs @@ -323,7 +323,18 @@ public override LineInfo VisitRazorMetaCode(RazorMetaCodeSyntax node) return EmitCurrentLineAsCSharp(); } + public override LineInfo VisitMarkupEphemeralTextLiteral(MarkupEphemeralTextLiteralSyntax node) + { + // A MarkupEphemeralTextLiteral is an escaped @ sign, eg in CSS "@@font-face". We just treat it like markup text + return VisitMarkupLiteral(); + } + public override LineInfo VisitMarkupTextLiteral(MarkupTextLiteralSyntax node) + { + return VisitMarkupLiteral(); + } + + private LineInfo VisitMarkupLiteral() { // For markup text literal, we always want to honour the Html formatter, so we supply the Html indent. // Normally that would only happen if we were inside a markup element diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/DocumentFormattingTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/DocumentFormattingTest.cs index fac7463775a..e1ce1ec6e9d 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/DocumentFormattingTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/DocumentFormattingTest.cs @@ -5854,4 +5854,56 @@ void Foo() { } @Foo.ToString(1) """); } + + [FormattingTestFact] + public async Task EscapedAtSignsInCSS() + { + await RunFormattingTestAsync( + input: """ + @page "/" + @model IndexModel + + + + + + @if (RendererInfo.IsInteractive) + { +