From 68eb5d0a8729036dd6be9ecf2aa7787bd1d08e42 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Dec 2025 04:56:21 +0000 Subject: [PATCH 1/2] Initial plan From 05818137f430cd2a51fa6821d606b83fdfce25c2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Dec 2025 05:09:45 +0000 Subject: [PATCH 2/2] Fix JavaScript syntax highlighting after C# if statements without braces in Razor files Co-authored-by: davidwengier <754264+davidwengier@users.noreply.github.com> --- .../syntaxes/aspnetcorerazor.tmLanguage.json | 38 +++--- .../syntaxes/aspnetcorerazor.tmLanguage.yml | 38 +++--- .../__snapshots__/grammarTests.test.ts.snap | 123 ++++++++++++++++++ .../tests/codeBlock.ts | 25 ++++ 4 files changed, 186 insertions(+), 38 deletions(-) diff --git a/src/razor/syntaxes/aspnetcorerazor.tmLanguage.json b/src/razor/syntaxes/aspnetcorerazor.tmLanguage.json index 15f67bc324..1498da095d 100644 --- a/src/razor/syntaxes/aspnetcorerazor.tmLanguage.json +++ b/src/razor/syntaxes/aspnetcorerazor.tmLanguage.json @@ -1298,7 +1298,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "using-statement-with-optional-transition": { "name": "meta.statement.using.razor", @@ -1326,7 +1326,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "if-statement": { "name": "meta.statement.if.razor", @@ -1354,7 +1354,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "if-statement-with-optional-transition": { "name": "meta.statement.if.razor", @@ -1382,7 +1382,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "else-part": { "name": "meta.statement.else.razor", @@ -1406,7 +1406,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "for-statement": { "name": "meta.statement.for.razor", @@ -1434,7 +1434,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "for-statement-with-optional-transition": { "name": "meta.statement.for.razor", @@ -1462,7 +1462,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "foreach-statement": { "name": "meta.statement.foreach.razor", @@ -1497,7 +1497,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "foreach-statement-with-optional-transition": { "name": "meta.statement.foreach.razor", @@ -1532,7 +1532,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "foreach-condition": { "begin": "\\(", @@ -1618,7 +1618,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "do-statement-with-optional-transition": { "name": "meta.statement.do.razor", @@ -1646,7 +1646,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "while-statement": { "name": "meta.statement.while.razor", @@ -1707,7 +1707,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "switch-statement-with-optional-transition": { "name": "meta.statement.switch.razor", @@ -1735,7 +1735,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "switch-code-block": { "name": "meta.structure.razor.csharp.codeblock.switch", @@ -1789,7 +1789,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "lock-statement-with-optional-transition": { "name": "meta.statement.lock.razor", @@ -1817,7 +1817,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "try-statement": { "patterns": [ @@ -1871,7 +1871,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "try-block-with-optional-transition": { "name": "meta.statement.try.razor", @@ -1899,7 +1899,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "catch-clause": { "name": "meta.statement.catch.razor", @@ -1923,7 +1923,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "catch-condition": { "begin": "\\(", @@ -1972,7 +1972,7 @@ "include": "#razor-codeblock-body" } ], - "end": "(?<=})" + "end": "(?<=})|(?<=;)|(?=^\\s*\\})" }, "await-prefix": { "name": "keyword.other.await.cs", diff --git a/src/razor/syntaxes/aspnetcorerazor.tmLanguage.yml b/src/razor/syntaxes/aspnetcorerazor.tmLanguage.yml index 43af7ee5da..f55e528460 100644 --- a/src/razor/syntaxes/aspnetcorerazor.tmLanguage.yml +++ b/src/razor/syntaxes/aspnetcorerazor.tmLanguage.yml @@ -628,7 +628,7 @@ repository: - include: '#csharp-condition' - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' using-statement-with-optional-transition: name: 'meta.statement.using.razor' @@ -640,7 +640,7 @@ repository: - include: '#csharp-condition' - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' #>>>>> @if (...) { ... } <<<<< @@ -654,7 +654,7 @@ repository: - include: '#csharp-condition' - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' if-statement-with-optional-transition: name: 'meta.statement.if.razor' @@ -666,7 +666,7 @@ repository: - include: '#csharp-condition' - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' #>>>>> else [if (...)] { ... } <<<<< @@ -680,7 +680,7 @@ repository: - include: '#csharp-condition' - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' #>>>>> @for (...) { ... } <<<<< @@ -694,7 +694,7 @@ repository: - include: '#csharp-condition' - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' for-statement-with-optional-transition: name: 'meta.statement.for.razor' @@ -706,7 +706,7 @@ repository: - include: '#csharp-condition' - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' #>>>>> @foreach (...) { ... } <<<<< @@ -721,7 +721,7 @@ repository: - include: '#foreach-condition' - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' foreach-statement-with-optional-transition: name: 'meta.statement.foreach.razor' @@ -734,7 +734,7 @@ repository: - include: '#foreach-condition' - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' # This condition is pulled directly from the C# grammar for foreach statements foreach-condition: @@ -803,7 +803,7 @@ repository: - include: '#csharp-condition' - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' do-statement-with-optional-transition: name: 'meta.statement.do.razor' @@ -815,7 +815,7 @@ repository: - include: '#csharp-condition' - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' #>>>>> @while (...) { ... } <<<<< @@ -845,7 +845,7 @@ repository: - include: '#csharp-condition' - include: '#switch-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' switch-statement-with-optional-transition: name: 'meta.statement.switch.razor' @@ -857,7 +857,7 @@ repository: - include: '#csharp-condition' - include: '#switch-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' switch-code-block: name: 'meta.structure.razor.csharp.codeblock.switch' @@ -884,7 +884,7 @@ repository: - include: '#csharp-condition' - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' lock-statement-with-optional-transition: name: 'meta.statement.lock.razor' @@ -896,7 +896,7 @@ repository: - include: '#csharp-condition' - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' #>>>>> @try { ... } [catch|finally] (...) { ... } <<<<< @@ -922,7 +922,7 @@ repository: - include: '#csharp-condition' - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' try-block-with-optional-transition: name: 'meta.statement.try.razor' @@ -934,7 +934,7 @@ repository: - include: '#csharp-condition' - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' catch-clause: name: 'meta.statement.catch.razor' @@ -946,7 +946,7 @@ repository: - include: 'source.cs#when-clause' - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' # This condition is pulled directly from the C# grammar for catch clauses catch-condition: @@ -993,7 +993,7 @@ repository: patterns: - include: '#csharp-code-block' - include: '#razor-codeblock-body' - end: '(?<=})' + end: '(?<=})|(?<=;)|(?=^\s*\})' # ---------- Misc C# ------------ diff --git a/test/razor/razorTests/Microsoft.AspNetCore.Razor.VSCode.Grammar.Test/tests/__snapshots__/grammarTests.test.ts.snap b/test/razor/razorTests/Microsoft.AspNetCore.Razor.VSCode.Grammar.Test/tests/__snapshots__/grammarTests.test.ts.snap index 108d7dd909..87ae34beb7 100644 --- a/test/razor/razorTests/Microsoft.AspNetCore.Razor.VSCode.Grammar.Test/tests/__snapshots__/grammarTests.test.ts.snap +++ b/test/razor/razorTests/Microsoft.AspNetCore.Razor.VSCode.Grammar.Test/tests/__snapshots__/grammarTests.test.ts.snap @@ -6827,6 +6827,129 @@ exports[`Grammar tests Razor code blocks @{ ... } Empty code block 1`] = ` " `; +exports[`Grammar tests Razor code blocks @{ ... } If statement without braces followed by HTML 1`] = ` +"Line: @{ + - token from 0 to 1 (@) with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, keyword.control.cshtml.transition + - token from 1 to 2 ({) with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, keyword.control.razor.directive.codeblock.open + +Line: if (true) + - token from 0 to 4 ( ) with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, source.cs, meta.statement.if.razor + - token from 4 to 6 (if) with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, source.cs, meta.statement.if.razor, keyword.control.conditional.if.cs + - token from 6 to 7 ( ) with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, source.cs, meta.statement.if.razor + - token from 7 to 8 (() with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, source.cs, meta.statement.if.razor, punctuation.parenthesis.open.cs + - token from 8 to 12 (true) with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, source.cs, meta.statement.if.razor, constant.language.boolean.true.cs + - token from 12 to 13 ()) with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, source.cs, meta.statement.if.razor, punctuation.parenthesis.close.cs + +Line: Console.WriteLine("test"); + - token from 0 to 8 ( ) with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, source.cs, meta.statement.if.razor + - token from 8 to 15 (Console) with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, source.cs, meta.statement.if.razor, variable.other.object.cs + - token from 15 to 16 (.) with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, source.cs, meta.statement.if.razor, punctuation.accessor.cs + - token from 16 to 25 (WriteLine) with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, source.cs, meta.statement.if.razor, entity.name.function.cs + - token from 25 to 26 (() with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, source.cs, meta.statement.if.razor, punctuation.parenthesis.open.cs + - token from 26 to 27 (") with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, source.cs, meta.statement.if.razor, string.quoted.double.cs, punctuation.definition.string.begin.cs + - token from 27 to 31 (test) with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, source.cs, meta.statement.if.razor, string.quoted.double.cs + - token from 31 to 32 (") with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, source.cs, meta.statement.if.razor, string.quoted.double.cs, punctuation.definition.string.end.cs + - token from 32 to 33 ()) with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, source.cs, meta.statement.if.razor, punctuation.parenthesis.close.cs + - token from 33 to 34 (;) with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, source.cs, meta.statement.if.razor, punctuation.terminator.statement.cs + +Line: } + - token from 0 to 1 (}) with scopes text.aspnetcorerazor, meta.structure.razor.codeblock, keyword.control.razor.directive.codeblock.close + +Line: