I would like to run a function each time a token is recognized. I have seen the documentation and the following function seems to be the entry point to what I would like to do: setMonarchTokensProvider.
Here we have a provided example:
monaco.languages.setMonarchTokensProvider('mySpecialLanguage', {
tokenizer: {
root: [
[/\[error.*/, "custom-error"],
[/\[notice.*/, "custom-notice"],
[/\[info.*/, "custom-info"],
[/\[[a-zA-Z 0-9:]+\]/, "custom-date"],
]
}});
monaco.editor.defineTheme('myCoolTheme', {
base: 'vs',
inherit: false,
rules: [
{ token: 'custom-info', foreground: '808080' },
{ token: 'custom-error', foreground: 'ff0000', fontStyle: 'bold' },
{ token: 'custom-notice', foreground: 'FFA500' },
{ token: 'custom-date', foreground: '008800' },
]});
I tried to set an alert("something") instead of the "custom-error" but it runs only once and not for each occurrence of the token. The provided code sample works well: it colours each token satisfy the regex.
I have seen the documentation and seems I should use IMonarchLanguageRule and so the IMonarchLanguageAction but still isn't clear to me how to use it.
I am sure an example could solve this problem. Thanks a lot.