Skip to content

Commit 888875f

Browse files
authored
Syntax cleanup (angular#1953)
* refactor(extension): clean up embedded language configuration The embeddedLanguages configuration of a grammer is meant to map scope name to the name of the language for that scope. * refactor(syntaxes): Only inject template scopes to html 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`.
1 parent b742190 commit 888875f

File tree

4 files changed

+21
-26
lines changed

4 files changed

+21
-26
lines changed

.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU=

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
.npmrc=974837034
55
pnpm-lock.yaml=943190807
66
yarn.lock=-1098466397
7-
package.json=-90176185
7+
package.json=619455070
88
pnpm-workspace.yaml=1711114604

package.json

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -164,42 +164,22 @@
164164
{
165165
"path": "./syntaxes/template.json",
166166
"scopeName": "template.ng",
167-
"injectTo": [
168-
"text.html.derivative",
169-
"source.ts"
170-
],
171-
"embeddedLanguages": {
172-
"text.html": "html",
173-
"source.css": "css"
174-
}
167+
"injectTo": ["text.html.derivative"]
175168
},
176169
{
177170
"path": "./syntaxes/template-blocks.json",
178171
"scopeName": "template.blocks.ng",
179-
"injectTo": [
180-
"text.html.derivative",
181-
"source.ts"
182-
],
183-
"embeddedLanguages": {
184-
"text.html": "html",
185-
"expression.ng": "javascript"
186-
}
172+
"injectTo": ["text.html.derivative"]
187173
},
188174
{
189175
"path": "./syntaxes/let-declaration.json",
190176
"scopeName": "template.let.ng",
191-
"injectTo": [
192-
"text.html.derivative",
193-
"source.ts"
194-
]
177+
"injectTo": [ "text.html.derivative" ]
195178
},
196179
{
197180
"path": "./syntaxes/template-tag.json",
198181
"scopeName": "template.tag.ng",
199-
"injectTo": [
200-
"text.html.derivative",
201-
"source.ts"
202-
]
182+
"injectTo": ["text.html.derivative"]
203183
},
204184
{
205185
"path": "./syntaxes/expression.json",

syntaxes/inline-template.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@
6969
},
7070
{
7171
"include": "template.ng"
72+
},
73+
{
74+
"include": "template.blocks.ng"
75+
},
76+
{
77+
"include": "template.tag.ng"
78+
},
79+
{
80+
"include": "template.let.ng"
7281
}
7382
]
7483
}

syntaxes/src/inline-template.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ export const InlineTemplate: GrammarDefinition = {
3737
end: /\1/,
3838
endCaptures: {0: {name: 'string'}},
3939
contentName: 'text.html',
40-
patterns: [{include: 'text.html.derivative'}, {include: 'template.ng'}]
40+
patterns: [
41+
{include: 'text.html.derivative'},
42+
{include: 'template.ng'},
43+
{include: 'template.blocks.ng'},
44+
{include: 'template.tag.ng'},
45+
{include: 'template.let.ng'},
46+
]
4147
}
4248
}
4349
};

0 commit comments

Comments
 (0)