Alessio Stalla
Alessio Stalla

Reputation: 1062

Monaco editor: how to recompute and redraw semantic highlighting data?

I have implemented semantic highlighting on Monaco (using registerDocumentSemanticTokensProvider). My semantic highlighting depends on some out-of-editor information (say, a data model with valid property names, against which I check how to highlight tokens). Such information can change over time, e.g., because the user adds a new property to the data model, maybe even as the result of a code action in the editor. So, whenever the data model changes, I'd like to update the editor to show the new information. However, Monaco only updates the semantic highlighting when the document is changed. Is there a way to force it to reapply highlighting even when no editing operation occurred?

Upvotes: 2

Views: 1997

Answers (1)

Alessio Stalla
Alessio Stalla

Reputation: 1062

It turns out that by simply re-setting the model's value, semantic highlighting gets refreshed:

model.setValue(model.getValue());

As far as I know, this is not documented anywhere. Tested on Monaco 0.24.0.

Upvotes: 3

Related Questions