Archived
1
0

Bundle grammars (#563)

This commit is contained in:
Kyle Carberry 2019-04-22 12:51:05 -05:00 committed by Asher
parent d073622629
commit e61ea796c6

View File

@ -2,6 +2,17 @@ import * as vscodeTextmate from "../../../../lib/vscode/node_modules/vscode-text
const target = vscodeTextmate as typeof vscodeTextmate;
const ctx = (require as any).context("../../../../lib/extensions", true, /.*\.tmLanguage.json$/);
// Maps grammar scope to loaded grammar
const scopeToGrammar = {} as any;
ctx.keys().forEach((key: string) => {
const value = ctx(key);
if (value.scopeName) {
scopeToGrammar[value.scopeName] = value;
}
});
target.Registry = class Registry extends vscodeTextmate.Registry {
public constructor(opts: vscodeTextmate.RegistryOptions) {
super({
@ -21,6 +32,13 @@ target.Registry = class Registry extends vscodeTextmate.Registry {
}).catch(reason => rej(reason));
});
},
loadGrammar: async (scopeName: string) => {
if (scopeToGrammar[scopeName]) {
return scopeToGrammar[scopeName];
}
return opts.loadGrammar(scopeName);
},
});
}
};