Description
If language client receives quick open - close - open requests for the same file, it is possible for diagnostics pull to stop working. Such events can happen if for example language id of the document is changed programmatically. Client will receive a close notification immediately followed by open notification with the same uri, but different language id.
Reproduction
Language id of the opened document is changed here:
https://github.com/itrapashko/diagnostics-not-pulled/blob/64cb62b0aa05f824750654390ed2e20c5285935a/client/src/extension.ts#L48-L52
Why this happens
|
if (this.options.workspaceDiagnostics && uri.scheme !== 'untitled') { |
|
// If we run workspace diagnostic pull a last time for the diagnostics |
|
// and then rely on getting them from the workspace result. |
|
if (request !== undefined) { |
|
this.openRequests.set(key, { state: RequestStateKind.reschedule, document: document }); |
|
} else { |
|
this.pull(document, () => { |
|
this.forget(PullState.document, document); |
|
}); |
|
} |
Here are steps that lead to this problem:
- User opens the file. Client receives open notification. It starts tracking the file.
- Language id is changed programmatically. Client receives close notification for document with old language id.
DiagnosticRequestor.forgetDocument is called, which calls DiagnosticRequestor.pull with this.forget in callback (line 457). This callback is asynchronous, so it is not called immediately. It will be called after diagnostic pull request will finish.
- Client receives open notification for document with the same uri and new language id. It starts tracking the file.
- Callback from step 2 is called. Client mistakenly stops tracking the file that is should track.
Description
If language client receives quick open - close - open requests for the same file, it is possible for diagnostics pull to stop working. Such events can happen if for example language id of the document is changed programmatically. Client will receive a close notification immediately followed by open notification with the same uri, but different language id.
Reproduction
npm installLaunch Clientclient\testFixturediagnostics.ex1is closed. Open it.textDocument/diagnosticrequest is not sent.Language id of the opened document is changed here:
https://github.com/itrapashko/diagnostics-not-pulled/blob/64cb62b0aa05f824750654390ed2e20c5285935a/client/src/extension.ts#L48-L52
Why this happens
vscode-languageserver-node/client/src/common/diagnostic.ts
Lines 451 to 460 in a760573
Here are steps that lead to this problem:
DiagnosticRequestor.forgetDocumentis called, which callsDiagnosticRequestor.pullwiththis.forgetin callback (line 457). This callback is asynchronous, so it is not called immediately. It will be called after diagnostic pull request will finish.