How to use the vscode-textmate/release/main.Registry function in vscode-textmate

To help you get started, we’ve selected a few vscode-textmate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / TypeScript-TmLanguage / tests / build.ts View on Github external
ts = 'source.ts',
    tsx = 'source.tsx'
}
const grammarFileNames: Record = {
    [GrammarKind.ts]: "TypeScript.tmLanguage",
    [GrammarKind.tsx]: "TypeScriptReact.tmLanguage"
};
function grammarPath(kind: GrammarKind) {
    return path.join(__dirname, '..', grammarFileNames[kind]);
}
const grammarPaths = {
    [GrammarKind.ts]: grammarPath(GrammarKind.ts),
    [GrammarKind.tsx]: grammarPath(GrammarKind.tsx)
};

const registery = new vt.Registry({
    loadGrammar: function (scopeName: GrammarKind) {
        const path = grammarPaths[scopeName];
        if (path) {
            return new Promise((resolve, reject) => {
                fs.readFile(path, (error, content) => {
                    if (error) {
                        reject(error);
                    } else {
                        const rawGrammar = vt.parseRawGrammar(content.toString(), path);
                        resolve(rawGrammar);
                    }
                });
            });
        }

        return Promise.resolve(null);