Skip to content

Commit 72b0688

Browse files
author
Jordi Ramos
authored
TextMate bug: recognize codeblocks with curly braces in switch statements (#7929)
1 parent 361fcb6 commit 72b0688

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

src/razor/syntaxes/aspnetcorerazor.tmLanguage.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,9 @@
16341634
{
16351635
"include": "source.cs#switch-label"
16361636
},
1637+
{
1638+
"include": "#csharp-code-block"
1639+
},
16371640
{
16381641
"include": "#razor-codeblock-body"
16391642
}

src/razor/syntaxes/aspnetcorerazor.tmLanguage.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ repository:
816816
1: { name: 'punctuation.curlybrace.open.cs' }
817817
patterns:
818818
- include: 'source.cs#switch-label'
819+
- include: '#csharp-code-block'
819820
- include: '#razor-codeblock-body'
820821
end: '(\})'
821822
endCaptures:

test/razor/razorTests/Microsoft.AspNetCore.Razor.VSCode.Grammar.Test/tests/__snapshots__/grammarTests.test.ts.snap

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3385,6 +3385,60 @@ exports[`Grammar tests @switch ( ... ) { ... } Single line 1`] = `
33853385
"
33863386
`;
33873387

3388+
exports[`Grammar tests @switch ( ... ) { ... } comment in HTML text node 1`] = `
3389+
"Line: @switch (true)
3390+
- token from 0 to 1 (@) with scopes text.aspnetcorerazor, meta.statement.switch.razor, keyword.control.cshtml.transition
3391+
- token from 1 to 7 (switch) with scopes text.aspnetcorerazor, meta.statement.switch.razor, keyword.control.switch.cs
3392+
- token from 7 to 8 ( ) with scopes text.aspnetcorerazor, meta.statement.switch.razor
3393+
- token from 8 to 9 (() with scopes text.aspnetcorerazor, meta.statement.switch.razor, punctuation.parenthesis.open.cs
3394+
- token from 9 to 13 (true) with scopes text.aspnetcorerazor, meta.statement.switch.razor, constant.language.boolean.true.cs
3395+
- token from 13 to 14 ()) with scopes text.aspnetcorerazor, meta.statement.switch.razor, punctuation.parenthesis.close.cs
3396+
3397+
Line: {
3398+
- token from 0 to 1 ({) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, punctuation.curlybrace.open.cs
3399+
3400+
Line: case true:
3401+
- token from 0 to 4 ( ) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch
3402+
- token from 4 to 8 (case) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, keyword.control.case.cs
3403+
- token from 8 to 9 ( ) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch
3404+
- token from 9 to 13 (true) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, constant.language.boolean.true.cs
3405+
- token from 13 to 14 (:) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, punctuation.separator.colon.cs
3406+
3407+
Line: {
3408+
- token from 0 to 4 ( ) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch
3409+
- token from 4 to 5 ({) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock, punctuation.curlybrace.open.cs
3410+
3411+
Line: <p>this is a text https://example.org<h3>Test</h3></p>
3412+
- token from 0 to 8 ( ) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock
3413+
- token from 8 to 9 (<) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock, punctuation.definition.tag.begin.html
3414+
- token from 9 to 10 (p) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock, entity.name.tag.html
3415+
- token from 10 to 11 (>) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock, punctuation.definition.tag.end.html
3416+
- token from 11 to 45 (this is a text https://example.org) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock
3417+
- token from 45 to 46 (<) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock, punctuation.definition.tag.begin.html
3418+
- token from 46 to 48 (h3) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock, entity.name.tag.html
3419+
- token from 48 to 49 (>) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock, punctuation.definition.tag.end.html
3420+
- token from 49 to 53 (Test) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock
3421+
- token from 53 to 55 (</) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock, punctuation.definition.tag.begin.html
3422+
- token from 55 to 57 (h3) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock, entity.name.tag.html
3423+
- token from 57 to 58 (>) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock, punctuation.definition.tag.end.html
3424+
- token from 58 to 60 (</) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock, punctuation.definition.tag.begin.html
3425+
- token from 60 to 61 (p) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock, entity.name.tag.html
3426+
- token from 61 to 62 (>) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock, punctuation.definition.tag.end.html
3427+
3428+
Line: }
3429+
- token from 0 to 4 ( ) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock
3430+
- token from 4 to 5 (}) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, meta.structure.razor.csharp.codeblock, punctuation.curlybrace.close.cs
3431+
3432+
Line: break;
3433+
- token from 0 to 8 ( ) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch
3434+
- token from 8 to 13 (break) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, keyword.control.flow.break.cs
3435+
- token from 13 to 14 (;) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, punctuation.terminator.statement.cs
3436+
3437+
Line: }
3438+
- token from 0 to 1 (}) with scopes text.aspnetcorerazor, meta.statement.switch.razor, meta.structure.razor.csharp.codeblock.switch, punctuation.curlybrace.close.cs
3439+
"
3440+
`;
3441+
33883442
exports[`Grammar tests @tagHelperPrefix directive Incomplete parameter 1`] = `
33893443
"Line: @tagHelperPrefix "
33903444
- token from 0 to 1 (@) with scopes text.aspnetcorerazor, meta.directive, keyword.control.cshtml.transition

test/razor/razorTests/Microsoft.AspNetCore.Razor.VSCode.Grammar.Test/tests/switchStatement.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,18 @@ export function RunSwitchStatementSuite() {
7777
</div>`
7878
);
7979
});
80+
81+
it('comment in HTML text node', async () => {
82+
await assertMatchesSnapshot(
83+
`@switch (true)
84+
{
85+
case true:
86+
{
87+
<p>this is a text https://example.org<h3>Test</h3></p>
88+
}
89+
break;
90+
}`
91+
);
92+
});
8093
});
8194
}

0 commit comments

Comments
 (0)