Skip to content

Commit

Permalink
fix(syntaxes): inject template tags to top-level source.ts (#2058)
Browse files Browse the repository at this point in the history
note: template.tag.ng isn't used here and needs to be directly injected into source.ts scopes
at the top level because it relies entirely on the injectionSelector to filter its matching
out of non-html tag contexts. Since we don't have any scopes that match HTML tags, we rely
entirely on the text.html.derivative pattern matching and apply the tag scope via injectionSelector
only rather than being able to include it in a pattern list of another match.

fixes #2053
  • Loading branch information
atscott committed Jul 9, 2024
1 parent 888875f commit 5fe5214
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
.npmrc=974837034
pnpm-lock.yaml=943190807
yarn.lock=-1098466397
package.json=619455070
package.json=1654749565
pnpm-workspace.yaml=1711114604
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"source.ts"
],
"embeddedLanguages": {
"text.html": "html",
"text.html.derivative": "html",
"source.css": "css",
"source.js": "javascript"
}
Expand Down Expand Up @@ -174,12 +174,15 @@
{
"path": "./syntaxes/let-declaration.json",
"scopeName": "template.let.ng",
"injectTo": [ "text.html.derivative" ]
"injectTo": ["text.html.derivative"]
},
{
"path": "./syntaxes/template-tag.json",
"scopeName": "template.tag.ng",
"injectTo": ["text.html.derivative"]
"injectTo": [
"text.html.derivative",
"source.ts"
]
},
{
"path": "./syntaxes/expression.json",
Expand Down
5 changes: 1 addition & 4 deletions syntaxes/inline-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"name": "string"
}
},
"contentName": "text.html",
"contentName": "text.html.derivative",
"patterns": [
{
"include": "text.html.derivative"
Expand All @@ -73,9 +73,6 @@
{
"include": "template.blocks.ng"
},
{
"include": "template.tag.ng"
},
{
"include": "template.let.ng"
}
Expand Down
15 changes: 9 additions & 6 deletions syntaxes/src/inline-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ export const InlineTemplate: GrammarDefinition = {
beginCaptures: {1: {name: 'string'}},
end: /\1/,
endCaptures: {0: {name: 'string'}},
contentName: 'text.html',
contentName: 'text.html.derivative',
patterns: [
{include: 'text.html.derivative'},
{include: 'template.ng'},
{include: 'template.blocks.ng'},
{include: 'template.tag.ng'},
{include: 'template.let.ng'},
{include: 'text.html.derivative'}, {include: 'template.ng'},
{include: 'template.blocks.ng'}, {include: 'template.let.ng'},
// note: template.tag.ng isn't used here and needs to be directly injected into source.ts
// scopes at the top level because it relies entirely on the injectionSelector to filter its
// matching out of non-html tag contexts. Since we don't have any scopes that match HTML
// tags, we rely entirely on the text.html.derivative pattern matching and apply the tag
// scope via injectionSelector only rather than being able to include it in a pattern list
// of another match.
]
}
}
Expand Down
18 changes: 9 additions & 9 deletions syntaxes/test/data/inline-template.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# ^ inline-template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
# ^ inline-template.ng
# ^ inline-template.ng string
# ^^^^^^^^^^^ inline-template.ng text.html
# ^^^^^^^^^^^ inline-template.ng text.html.derivative
# ^ inline-template.ng string
# ^^ inline-template.ng
>
Expand All @@ -25,7 +25,7 @@
# ^ inline-template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
# ^ inline-template.ng
# ^ inline-template.ng string
# ^^^^^^^^^^^ inline-template.ng text.html
# ^^^^^^^^^^^ inline-template.ng text.html.derivative
# ^ inline-template.ng string
# ^^ inline-template.ng
> template: "<div></div>",
Expand All @@ -34,7 +34,7 @@
# ^ inline-template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
# ^ inline-template.ng
# ^ inline-template.ng string
# ^^^^^^^^^^^ inline-template.ng text.html
# ^^^^^^^^^^^ inline-template.ng text.html.derivative
# ^ inline-template.ng string
# ^^ inline-template.ng
> template: '<div></div>',
Expand All @@ -43,7 +43,7 @@
# ^ inline-template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
# ^ inline-template.ng
# ^ inline-template.ng string
# ^^^^^^^^^^^ inline-template.ng text.html
# ^^^^^^^^^^^ inline-template.ng text.html.derivative
# ^ inline-template.ng string
# ^^ inline-template.ng
>
Expand All @@ -60,7 +60,7 @@
# ^ inline-template.ng meta.brace.round.ts
# ^ inline-template.ng
# ^ inline-template.ng string
# ^^^^^^^^^^^ inline-template.ng text.html
# ^^^^^^^^^^^ inline-template.ng text.html.derivative
# ^ inline-template.ng string
# ^ inline-template.ng
# ^ inline-template.ng meta.brace.round.ts
Expand All @@ -77,7 +77,7 @@
# ^ inline-template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
# ^ inline-template.ng
# ^ inline-template.ng string
# ^^^^^^^^^^^ inline-template.ng text.html
# ^^^^^^^^^^^ inline-template.ng text.html.derivative
# ^ inline-template.ng string
> /*
#^^^^^ inline-template.ng
Expand Down Expand Up @@ -108,9 +108,9 @@
# ^ inline-template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
# ^ inline-template.ng
# ^ inline-template.ng string
# ^^ inline-template.ng text.html punctuation.definition.block.ts
# ^^^^^^^^ inline-template.ng text.html expression.ng variable.other.readwrite.ts
# ^^ inline-template.ng text.html punctuation.definition.block.ts
# ^^ inline-template.ng text.html.derivative punctuation.definition.block.ts
# ^^^^^^^^ inline-template.ng text.html.derivative expression.ng variable.other.readwrite.ts
# ^^ inline-template.ng text.html.derivative punctuation.definition.block.ts
# ^ inline-template.ng string
# ^^ inline-template.ng
>})
Expand Down

0 comments on commit 5fe5214

Please sign in to comment.