提交 890d41f7 编写于 作者: M Matt Bierner 提交者: GitHub

Allow injection grammars to specify embedded languages (#34327)

Fixes #34316

Enables contributed injection grammars to specify an embedded language for their injection targets:

```json
"grammars": [
  {
	"scopeName": "meta.embedded.css",
	"path": "./syntaxes/injection.json",
	"injectTo": [
	  "source.js",
	  "source.jsx",
	  "source.ts",
	  "source.tsx"
	],
	"embeddedLanguages": {
	  "meta.embedded.css": "css"
	}
  }
]
```
上级 4c566f05
......@@ -105,6 +105,8 @@ export class TextMateService implements ITextMateService {
private _themeService: IWorkbenchThemeService;
private _scopeRegistry: TMScopeRegistry;
private _injections: { [scopeName: string]: string[]; };
private _injectedEmbeddedLanguages: { [scopeName: string]: IEmbeddedLanguagesMap[]; };
private _languageToScope: Map<string, string>;
private _styleElement: HTMLStyleElement;
......@@ -123,6 +125,7 @@ export class TextMateService implements ITextMateService {
this._scopeRegistry = new TMScopeRegistry();
this.onDidEncounterLanguage = this._scopeRegistry.onDidEncounterLanguage;
this._injections = {};
this._injectedEmbeddedLanguages = {};
this._languageToScope = new Map<string, string>();
this._grammarRegistry = new Registry({
......@@ -237,6 +240,16 @@ export class TextMateService implements ITextMateService {
}
injections.push(syntax.scopeName);
}
if (syntax.embeddedLanguages) {
for (let injectScope of syntax.injectTo) {
let injectedEmbeddedLanguages = this._injectedEmbeddedLanguages[injectScope];
if (!injectedEmbeddedLanguages) {
this._injectedEmbeddedLanguages[injectScope] = injectedEmbeddedLanguages = [];
}
injectedEmbeddedLanguages.push(syntax.embeddedLanguages);
}
}
}
let modeId = syntax.language;
......@@ -271,6 +284,15 @@ export class TextMateService implements ITextMateService {
return TPromise.wrapError<ICreateGrammarResult>(new Error(nls.localize('no-tm-grammar', "No TM Grammar registered for this language.")));
}
let embeddedLanguages = this._resolveEmbeddedLanguages(languageRegistration.embeddedLanguages);
let injectedEmbeddedLanguages = this._injectedEmbeddedLanguages[scopeName];
if (injectedEmbeddedLanguages) {
for (const injected of injectedEmbeddedLanguages.map(this._resolveEmbeddedLanguages.bind(this))) {
for (const scope of Object.keys(injected)) {
embeddedLanguages[scope] = injected[scope];
}
}
}
let languageId = this._modeService.getLanguageIdentifier(modeId).id;
let containsEmbeddedLanguages = (Object.keys(embeddedLanguages).length > 0);
return new TPromise<ICreateGrammarResult>((c, e, p) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册