Skip to content

Commit

Permalink
Bundle grammars (#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecarbs authored and code-asher committed Apr 22, 2019
1 parent 2a565bc commit 285a7f6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/vscode/src/fill/vscodeTextmate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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);
},
});
}
};
Expand Down

0 comments on commit 285a7f6

Please sign in to comment.