I have implemented a LSP for a VSCode extension that provides a series of diagnostics for the opened document(s).
The execution of the function that evaluates the document occurs in the onDidChangeContent
event (server side):
documents.onDidChangeContent(async event => {
await validateTextDocument(event.document)
})
Now the issue comes when the document is quite long and you start typing or making changes rapidly. The validateTextDocument()
can take a few seconds for these long documents and since documents.onDidChangeContent()
will fire on each keystroke, the computer starts overloading with too many requests.
Is there any way to prevent the client from making any more requests until the server has responded? or even cancel the onDidChangeContent
altogether?
Thanks in advance
2
Answers
I'll take this approach as the final solution. I haven't found anything on the LSP client's side that will allow me to limit the number of events fired.
This is the best solution I've come up with on the server side. Just store all the received events and only execute last one every interval of 1 second discarding the rest. It works more or less OK
vscode.languages.registerDocumentLinkProvider
it will only call you when you haven’t typed for a while