I adding custom CodeLenseProvider to my React Monaco Editor, which works great in general:
{
provideCodeLenses(model: monaco.editor.ITextModel, token: monaco.CancellationToken): monaco.languages.ProviderResult<monaco.languages.CodeLensList> {
const lenses: monaco.languages.CodeLens[] = [];
lenses.push(...getLenses());
return {
lenses,
dispose: () => {},
};
},
}
The problem is that my method getLenses is time consuming and asynchronous. Ideally I'd like to e.g. fetch some data when provideCodeLenses is called, or even better, I'd like to be able to call provideCodeLenses manually refresh the lenses.
The steps would be:
- I have
onChangelistetener on
<MonacoEditor onChange={onChange} .../>
- this
onChangeis doing some async action - once the action is finished, I'd like to refresh code lenses
How can I achieve that? I know code lense provider has onDidChange property but it is not really clear to me how to use it or if it helps my case
By exploring
codelensController.jsto schedule code lens update manually, you have to useonDidChangefunction that will be called once during initialization of the provider with the argument being a function which can be called to signal for the update.