How to use the vscode-textmate.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 jeff-hykin / cpp-textmate-grammar / test / source / registry.js View on Github external
function getRegistry(getOnigLib) {
    return new vsctm.Registry({
        loadGrammar: sourceName => {
            if (sourceName == null) {
                console.error(
                    `I can't find the language for ${fixtureExtension}`
                );
                process.exit();
            }
            let grammarPath = pathFor.jsonSyntax(
                sourceName.replace(/^source\./, "")
            );
            // check if the syntax exists
            if (!fs.existsSync(grammarPath)) {
                if (
                    ![
                        "source.asm",
                        "source.x86",
github dotnet / csharp-tmLanguage / test / utils / tokenize.ts View on Github external
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { ITokenizeLineResult, Registry, StackElement, parseRawGrammar } from 'vscode-textmate';
import { readFile } from 'fs';
import { resolve } from 'path';

const registry = new Registry({
    loadGrammar: async (scopeName) => {
        if (scopeName === 'source.cs') {
            scopeName //?
            // https://github.com/textmate/javascript.tmbundle/blob/master/Syntaxes/JavaScript.plist
            const response = await new Promise((resolve, reject) => {
                readFile('./grammars/csharp.tmLanguage', (e, v) => e ? reject(e) : resolve(v.toString()));
            });
            const g = parseRawGrammar(response, resolve('./grammars/csharp.tmLanguage'));
            g //?
            return g;
        }
        console.log(`Unknown scope name: ${scopeName}`);
        return null;
    }
});
github eclipse-theia / theia / packages / monaco / src / browser / textmate / monaco-theme-registry.ts View on Github external
result.rules.push(...parentTheme.rules);
                result.settings.push(...parentTheme.settings);
            }
        }
        if (json.tokenColors) {
            result.settings.push(...json.tokenColors);
        }
        if (json.colors) {
            Object.assign(result.colors, json.colors);
            result.encodedTokensColors = Object.keys(result.colors).map(key => result.colors[key]);
        }
        if (monacoBase && givenName) {
            for (const setting of result.settings) {
                this.transform(setting, rule => result.rules.push(rule));
            }
            const reg = new Registry();
            reg.setTheme(result);
            result.encodedTokensColors = reg.getColorMap();
            // index 0 has to be set to null as it is 'undefined' by default, but monaco code expects it to be null
            // tslint:disable-next-line:no-null-keyword
            result.encodedTokensColors[0] = null!;
            // index 1 and 2 are the default colors
            if (result.colors && result.colors['editor.foreground']) {
                result.encodedTokensColors[1] = result.colors['editor.foreground'];
            }
            if (result.colors && result.colors['editor.background']) {
                result.encodedTokensColors[2] = result.colors['editor.background'];
            }
            this.setTheme(givenName, result);
        }
        return result;
    }
github OmniSharp / omnisharp-vscode / test / syntaxes / utils / tokenize.ts View on Github external
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { ITokenizeLineResult, Registry, StackElement } from 'vscode-textmate';

const registry = new Registry();
const grammar = registry.loadGrammarFromPathSync('syntaxes/csharp.tmLanguage');
const excludedTypes = ['source.cs', 'meta.interpolation.cs', 'meta.preprocessor.cs', 'meta.tag.cs', 'meta.type.parameters.cs']

export function tokenize(input: string | Input, excludeTypes: boolean = true): Token[] {
    if (typeof input === "string") {
        input = Input.FromText(input);
    }

    let tokens: Token[] = [];
    let previousStack: StackElement = null;

    for (let lineIndex = 0; lineIndex < input.lines.length; lineIndex++) {
        const line = input.lines[lineIndex];

        let lineResult = grammar.tokenizeLine(line, previousStack);
        previousStack = lineResult.ruleStack;
github andrewbranch / gatsby-remark-vscode / src / createGetRegistry.js View on Github external
async function getRegistry(cache, rootScopeName) {
    if (!registry) {
      const grammars = getAllGrammars(await cache.get('grammars'));
      registry = new Registry({
        loadGrammar: async scopeName => {
          const grammarInfo = getGrammar(scopeName, grammars);
          const fileName = grammarInfo && getGrammarLocation(grammarInfo);
          if (fileName) {
            const contents = await readFile(fileName, 'utf8');
            return parseRawGrammar(contents, fileName);
          }
          warnMissingLanguageFile(scopeName, rootScopeName);
        },
        getInjections: scopeName => {
          return Object.keys(grammars).reduce((acc, s) => {
            const grammar = grammars[s];
            if (grammar.injectTo && grammar.injectTo.includes(scopeName)) {
              acc.push(s);
            }
            return acc;
github onflow / cadence / docs / highlight.js View on Github external
static async fromOptions({languageScopes, grammarPaths, themePath}) {
        const registry = new vsctm.Registry()

        for (let grammarPath of grammarPaths) {
            const grammar = await Highlighter.loadGrammar(grammarPath)
            await registry.addGrammar(grammar)
        }

        const theme = await Highlighter.loadTheme(themePath)
        registry.setTheme(theme)

        return new Highlighter(registry, languageScopes)
    }