From 24165dba26d6224fefcb0066c20ceeebc3877a22 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Sun, 17 Aug 2025 12:35:54 -0400 Subject: [PATCH 1/5] Fix Razor @{ } blocks Also, the Razor bracket code makes more sense now. --- Razor/C# (Razor).sublime-syntax | 19 +++------------ Razor/tests/syntax_test_cshtml.cshtml | 35 +++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Razor/C# (Razor).sublime-syntax b/Razor/C# (Razor).sublime-syntax index a09ba7c..4f855d8 100644 --- a/Razor/C# (Razor).sublime-syntax +++ b/Razor/C# (Razor).sublime-syntax @@ -28,19 +28,8 @@ contexts: - include: Packages/HTML (C#)/Razor/Razor.sublime-syntax#comments - include: Packages/HTML (C#)/Razor/Razor.sublime-syntax#html - stray-braces: - - match: (\})(\s*\n)? - scope: meta.embedded.cs - captures: - 1: punctuation.section.embedded.end.cs-razor - 2: meta.html-newline-after-csharp.cs-razor # used by indentation rules - # - match: \} - # scope: invalid.illegal.stray.cs - - stray-brackets: - - match: \] - scope: invalid.illegal.stray.cs - - stray-parens: - - match: \) + stray_close_bracket: + - match: \]|\) scope: invalid.illegal.stray.cs + - match: (?=}) + pop: 1 diff --git a/Razor/tests/syntax_test_cshtml.cshtml b/Razor/tests/syntax_test_cshtml.cshtml index eae238a..4bf3877 100644 --- a/Razor/tests/syntax_test_cshtml.cshtml +++ b/Razor/tests/syntax_test_cshtml.cshtml @@ -120,13 +120,36 @@ else } *@ + @{ } + + + + + + @{ var quote = "The future depends on what you do today. - Mahatma Gandhi"; - + + + + + + + } -

@quote

+

@quote

+ + + + + + + + + + @{ quote = "Hate cannot drive out hate, only love can do that. - Martin Luther King, Jr."; @@ -165,9 +188,17 @@ finally @{ /* C# comment */ + + + + // Another C# comment + + + } + @functions { From d0c8187c74b9a3e33a2604cac1f336dd572b667a Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Sun, 17 Aug 2025 12:37:48 -0400 Subject: [PATCH 2/5] Ask CI to tell me which versions crashed --- .github/workflows/syntax.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/syntax.yml b/.github/workflows/syntax.yml index 0b1c74b..b34e85d 100644 --- a/.github/workflows/syntax.yml +++ b/.github/workflows/syntax.yml @@ -21,6 +21,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 15 strategy: + fail-fast: false matrix: include: - build: latest From b14c07154f92954f0dfff62c4bc49aa1ed869586 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Sun, 17 Aug 2025 15:27:30 -0400 Subject: [PATCH 3/5] Fix WebForms empty and close-} blocks --- WebForms/C# (WebForms).sublime-syntax | 17 ++++-------- WebForms/tests/syntax_test_aspx.aspx | 39 +++++++++++++++++++++------ 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/WebForms/C# (WebForms).sublime-syntax b/WebForms/C# (WebForms).sublime-syntax index 12309c3..fba86c0 100644 --- a/WebForms/C# (WebForms).sublime-syntax +++ b/WebForms/C# (WebForms).sublime-syntax @@ -9,6 +9,11 @@ extends: Packages/C#/C#.sublime-syntax ############################################################################## contexts: + statements: + - meta_prepend: true + - match: (?=%>) + pop: 1 + code_block_in: - meta_prepend: true - match: (%>)(\s*\n)? @@ -27,15 +32,3 @@ contexts: pop: 1 - include: Packages/HTML (C#)/WebForms/WebForms.sublime-syntax#comments - include: Packages/HTML (C#)/WebForms/WebForms.sublime-syntax#html - - stray-braces: - - match: \} - scope: invalid.illegal.stray.cs - - stray-brackets: - - match: \] - scope: invalid.illegal.stray.cs - - stray-parens: - - match: \) - scope: invalid.illegal.stray.cs diff --git a/WebForms/tests/syntax_test_aspx.aspx b/WebForms/tests/syntax_test_aspx.aspx index 947b514..b50e726 100644 --- a/WebForms/tests/syntax_test_aspx.aspx +++ b/WebForms/tests/syntax_test_aspx.aspx @@ -102,22 +102,45 @@ + <% %> +<%--^^^^^ meta.embedded.cs --%> +<%--^^ punctuation.section.embedded.begin.cs-webforms --%> +<%-- ^ source.cs.embedded.html --%> +<%-- ^^ punctuation.section.embedded.end.cs-webforms - source --%> + + <% } %> +<%--^^^^^^^ meta.embedded.cs --%> +<%--^^ punctuation.section.embedded.begin.cs-webforms --%> +<%-- ^^^ source.cs.embedded.html --%> +<%-- ^ invalid.illegal.stray.brace.cs --%> +<%-- ^^ punctuation.section.embedded.end.cs-webforms - source --%> + <% if(3 > 10) <%--^^ punctuation.section.embedded.begin - source.cs --%> <%-- ^^^^^^^^^^ source.cs.embedded.html --%> { %> -<%-- ^ punctuation.section.block.begin --%> -<%-- ^^ punctuation.section.embedded.end --%> -<%-- ^^^^^ - source.cs.embedded.html --%> +<%--^^^^^^ meta.embedded.cs source.cs.embedded.html --%> +<%-- ^ punctuation.section.block.begin.cs --%> +<%-- ^^ text.html.cs.webforms meta.embedded.cs punctuation.section.embedded.end.cs-webforms - source --%>

Baz

<% } else { %> -<%-- ^^^^^^^^^^ source.cs.embedded.html --%> -<%-- ^ punctuation.section.block.end --%> -<%-- ^^^^ keyword.control.conditional.else --%> -<%-- ^ punctuation.section.block.begin --%> -<%-- ^^^ - source.cs.embedded.html --%> +<%--^^ text.html.cs.webforms --%> +<%--^^ meta.embedded.cs punctuation.section.embedded.begin.cs-webforms --%> +<%-- ^^^^^^^^^^ meta.embedded.cs source.cs.embedded.html --%> +<%-- ^ punctuation.section.block.end.cs --%> +<%-- ^^^^^ keyword.control.conditional.else.cs --%> +<%-- ^^ meta.block.cs --%> +<%-- ^ punctuation.section.block.begin.cs --%> +<%-- ^^ text.html.cs.webforms meta.embedded.cs punctuation.section.embedded.end.cs-webforms - source --%>

Biff

<% } %> +<%--^^ text.html.cs.webforms --%> +<%--^^ meta.embedded.cs punctuation.section.embedded.begin.cs-webforms --%> +<%-- ^^^^^ meta.embedded.cs --%> +<%-- ^^^ source.cs.embedded.html --%> +<%-- ^^ meta.block.cs --%> +<%-- ^ punctuation.section.block.end.cs --%> +<%-- ^^ punctuation.section.embedded.end.cs-webforms - source --%>

<%: variable %>

<%-- ^^^ punctuation.section.embedded.begin --%> From 74548ff3ded8472c3bce4361141254e1c9c67f98 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Sun, 17 Aug 2025 15:31:33 -0400 Subject: [PATCH 4/5] Set new minimum ST version to 4149 --- .github/workflows/syntax.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/syntax.yml b/.github/workflows/syntax.yml index b34e85d..874c1fc 100644 --- a/.github/workflows/syntax.yml +++ b/.github/workflows/syntax.yml @@ -28,7 +28,7 @@ jobs: packages: master - build: stable packages: master - - build: 4134 # Need HTML with `html` context for inclusion + - build: 4149 packages: binary steps: - uses: actions/checkout@v4 From ade6168ad4586b33782eb358ab0babf8957315c8 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Sun, 17 Aug 2025 16:28:58 -0400 Subject: [PATCH 5/5] Pop 3 times to escape HTML attributes in Razor Yes, this is suspicious. --- Razor/Razor.sublime-syntax | 10 +--------- .../C# (for C# Razor HTML attribute).sublime-syntax | 4 ++-- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Razor/Razor.sublime-syntax b/Razor/Razor.sublime-syntax index eb00a86..96b625f 100644 --- a/Razor/Razor.sublime-syntax +++ b/Razor/Razor.sublime-syntax @@ -307,17 +307,9 @@ contexts: - meta_include_prototype: false - match: '@@' scope: constant.character.escape.cs-razor - - match: '\w+@\w+' # prevent email addresses being caught etc - - match: '{{csharp_tag_interpolation_bare}}' + - match: '\B{{csharp_tag_interpolation_bare}}' scope: punctuation.section.interpolation.begin.razor push: Packages/HTML (C#)/Razor/embeddings/C# (for C# Razor HTML attribute).sublime-syntax - #push: csharp-interpolation-body - - csharp-interpolation-body: - # - clear_scopes: 1 - - meta_include_prototype: false - - include: csharp-embedded - - include: immediately-pop csharp-embedded: - meta_include_prototype: false diff --git a/Razor/embeddings/C# (for C# Razor HTML attribute).sublime-syntax b/Razor/embeddings/C# (for C# Razor HTML attribute).sublime-syntax index d37be7e..2cea750 100644 --- a/Razor/embeddings/C# (for C# Razor HTML attribute).sublime-syntax +++ b/Razor/embeddings/C# (for C# Razor HTML attribute).sublime-syntax @@ -10,9 +10,9 @@ contexts: main: - meta_prepend: true - match: (?=") - pop: 1 + pop: 3 line_of_code_in: - meta_prepend: true - match: (?=") - pop: 1 + pop: 3