Skip to content

Diagnostics pull does not work if file is closed and reopened quickly #1821

Description

@itrapashko

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

  • Clone repository https://github.com/itrapashko/diagnostics-not-pulled
  • npm install
  • Run Launch Client
  • Open client\testFixture
  • Ensure diagnostics.ex1 is closed. Open it.
  • Edit the file. Diagnostics does not update, and textDocument/diagnostic request 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

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:

  1. User opens the file. Client receives open notification. It starts tracking the file.
  2. 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.
  3. Client receives open notification for document with the same uri and new language id. It starts tracking the file.
  4. Callback from step 2 is called. Client mistakenly stops tracking the file that is should track.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions