For my extension I'm implementing the SemanticTokenProvider. This works great when edits are being parsed by my server, and everything looks good.
However, I've created functionality regarding TextEdits so they are bundled together if typed within a short period of each other. Every new edit will cancel the message to the server, and bundle the old and new edits and add it to the queue once more.
Due to how the SemanticTokenProvider works, it will fire itself after every edit, but sometimes the actual edit is removed from the queue, and the provider will act on data which hasn't changed.
To fix this, I created an event which is fired when TextEdits are actually sent to the server. When it is fired, I get the vscode.EventEmitter that is connected to the onDidChangeSemanticTokens Event, and fire it. Unfortunately, this doesn't actually seem to trigger the Provider.
I created a dummy command, which also asks the Provider for new tokens, and when this command is executed, it does ask for new tokens. If I execute the command from my event, it does not work.
My guess is that I'm doing something wrong with my events, but I'm unable to figure out why. See the basics of my implementation here:
Here the vscode.Event and vscode.EventEmitter
private mOnSentTextEditsEventEmitter: vscode.EventEmitter<void> = new vscode.EventEmitter<void>();
private mOnSentTextEditsEvent: vscode.Event<void> = this.mOnSentTextEditsEventEmitter.event;
My callback implementation. The then() is called once the queued message has been sent.
vscode.workspace.onDidChangeTextDocument( (event: vscode.TextDocumentChangeEvent) => {
// Executing code to queue a textedit message
// If succesfully sent, clear the text edit array.
this.mQueuedNotification.then( () => {
this.mTextEdits = [];
this.mQueuedNotification = null;
this.mOnSentTextEditsEventEmitter.fire();
});
)})
The function to register a callback
RegisterOnSentTextEdits(inThis: unknown, inCallback: () => void)
{
this.mOnSentTextEditsEvent.call(inThis, inCallback);
}
Here I register the callback by calling the above function
file_watcher.RegisterOnSentTextEdits(semantic_highlighter_provider_instance, () => {
semantic_highlighter_provider_instance.mOnDidchangeSemanticTokens.fire();
})
I do reach this last part, so I know my callback fires correctly. However, after this fire(), I never hit the breakpoint in provideDocumentSemanticTokens()
I also created a command for this, which does trigger correctly, which looks like follows:
let update_semantic_tokens = vscode.commands.registerCommand('update_semantic_tokens', () => {
semantic_highlighter_provider_instance.mOnDidchangeSemanticTokens.fire();
})
What am I doing wrong here? How can I consistently get the provider to retrigger, if I fire the event?
Thanks for reading, and if I need to provide more information, please let me know.