Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions client/src/common/diagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,16 @@ class DocumentPullStateTracker {
return states.has(key);
}

public tracksVersion(kind: PullState, document: TextDocument): boolean {
const key = document.uri.toString();
const states = kind === PullState.document ? this.documentPullStates : this.workspacePullStates;
const existing = states.get(key);
if (existing === undefined) {
return false;
}
return existing.pulledVersion === document.version;
}

public getResultId(kind: PullState, document: TextDocument | Uri): string | undefined {
const key = DocumentOrUri.asKey(document);
const states = kind === PullState.document ? this.documentPullStates : this.workspacePullStates;
Expand Down Expand Up @@ -318,6 +328,17 @@ class DiagnosticRequestor implements Disposable {
return this.documentStates.tracks(kind, document) || this.openRequests.has(uri.toString());
}

public knowsDocument(document: TextDocument): boolean {
const key = document.uri.toString();
// If there is an in-flight request, we don't consider this as fully known
// since the request may have been issued before the server received the
// document content via didOpen.
if (this.openRequests.has(key)) {
return false;
}
return this.documentStates.tracksVersion(PullState.document, document);
}

private forget(kind: PullState, document: TextDocument | Uri): void {
this.documentStates.unTrack(kind, document);
}
Expand Down Expand Up @@ -864,8 +885,11 @@ class DiagnosticFeatureProviderImpl implements DiagnosticProviderShape {
const openFeature = client.getFeature(DidOpenTextDocumentNotification.method);
disposables.push(openFeature.onNotificationSent((event) => {
const textDocument = event.textDocument;
// We already know about this document. This can happen via a tab open.
if (this.diagnosticRequestor.knows(PullState.document, textDocument)) {
// If diagnostics have already been pulled for this exact version (e.g. via
// a tab event) and there is no in-flight request, we can skip. Otherwise we
// need to (re-)pull so the server computes diagnostics based on the content
// it received through the didOpen notification.
if (this.diagnosticRequestor.knowsDocument(textDocument)) {
return;
}
if (matches(textDocument)) {
Expand Down
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading