How do I add a token to an existing language (like typescript)?

I can define tokens using setMonarchTokensProvider, but that doesn't really help, because I can only create a new language or rewrite typescript. Anyway, I don't have the rest of the typescript tokens that I still want to have.

I just want to add one token that will have a specific meaning in the context of this editor that I want to colorize. There is still typescript though.

This is what I have so far (taken from the playground examples), but with the rest of the typescript missing:

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 the theme myCoolTheme when creating the editor)

+3


source to share


1 answer


I ended up finding the .js file of the language and adding a setting there. Not the way I would like to do it, but it works.



+1


source







All Articles