Skip to content

Commit

Permalink
refactor(syntaxes): Only inject template scopes to html
Browse files Browse the repository at this point in the history
Template scopes do not need to be injected directly to source.ts.
Instead, template scopes apply when inline templates have been matched
in TS files and are included as patterns under that match.

The Angular template syntaxes _could_ be directly injected into TS like
they are now. This would apply them to any embedded `text.html` in a TS file.
This change applies Angular template grammars only to embedded HTML
matched by the inline template grammar (strings under `template:` of a
decorator).

`injectTo` applies only to the top-level file language and not embedded
labguages. So our `injectTo` `text.html` will not automatically apply to
inline templates simply by setting the `contentName` and language.

It would also be nice to further limit our grammars to apply only to
files that we know are Angular templates rather than injecting to every
to-level `.html` file.
In the future we might want to explore _not_ injecting into all top-level
`html` and then using `injectionSelector` to control from there. This
approach makes it difficult for environments that support
many frameworks/languages (stackblitz/textmate#4).

We might be able to create an "angular" language for `.component.html` and `.ng.html` files and use
our grammars only for those extensions rather than injecting them into
any and all `html`.
  • Loading branch information
atscott committed Nov 6, 2023
1 parent 066c1d6 commit 252a9c2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
.npmrc=974837034
pnpm-lock.yaml=-1547217849
yarn.lock=1378739518
package.json=-817439735
package.json=-1172598069
pnpm-workspace.yaml=1711114604
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,13 @@
"path": "./syntaxes/template.json",
"scopeName": "template.ng",
"injectTo": [
"text.html.derivative",
"source.ts"
"text.html.derivative"
]
},
{
"path": "./syntaxes/template-blocks.json",
"scopeName": "template.blocks.ng",
"injectTo": [
"text.html.derivative",
"source.ts"
]
"injectTo": ["text.html.derivative"]
},
{
"path": "./syntaxes/expression.json",
Expand Down
3 changes: 3 additions & 0 deletions syntaxes/inline-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
},
{
"include": "template.ng"
},
{
"include": "template.blocks.ng"
}
]
}
Expand Down
4 changes: 3 additions & 1 deletion syntaxes/src/inline-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export const InlineTemplate: GrammarDefinition = {
end: /\1/,
endCaptures: {0: {name: 'string'}},
contentName: 'text.html',
patterns: [{include: 'text.html.derivative'}, {include: 'template.ng'}]
patterns: [
{include: 'text.html.derivative'}, {include: 'template.ng'}, {include: 'template.blocks.ng'}
]
}
}
};

0 comments on commit 252a9c2

Please sign in to comment.