Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a token to an existing language (e.g. typescript)?

I can define tokens with setMonarchTokensProvider, but that does not really help because I can only make a new language or overwrite typescript. In either case I do not have the rest of the typescript tokens which I still want to have.

I just want to add one token, which will have a specific meaning in the context of this editor, which I want to colorize. While still having all of typescript.

This is what I have till now (taken form the playground examples), but with this the rest of typescript is gone:

monaco.languages.setMonarchTokensProvider('typescript', {
    tokenizer: {
        root: [
            [/\pvm.*/, "custom-error"]
        ]
    }
});


monaco.editor.defineTheme('myCoolTheme', {
    base: 'vs',
    inherit: true,
    rules: [
        { token: 'custom-error', foreground: 'ff0000', fontStyle: 'bold' }
    ]
});

(And then using theme myCoolTheme when creating the editor)

like image 968
jiron Avatar asked Jul 31 '17 15:07

jiron


1 Answers

I ended up finding the language .js file and adding the customization there. Not the way I'd like to do it, but it works.

like image 103
ctsears Avatar answered Oct 19 '22 01:10

ctsears