Search code examples
monaco-editor

Programmatically reset tokenization state in Monaco editor


I created a TokensProvider to provide syntax highlighting to my custom language. This works, but it only redraws when text is edited.

Problem is - My custom language depends on outside context that can change even if text does not. Thus I need to trigger syntax highlighting redraw even when text does not change.

How can i achieve this?


Solution

  • Digging through vscode repo, looks like the following line works:

    monaco.editor.getModel(url)._resetTokenizationState()
    

    Unfortunately, this looks like an undocumented API that might break with future versions, so a public API will be nice.