Skip to content

Commit a8f8a2d

Browse files
committed
Only re-request diagnostics if the file has actually been opened
Fixes microsoft#95027 Hovers cause VS Code to quickly open and the close the target file. We never actually sync the file with the TypeScript server when this happens. However on file close, we always re-request diagnostics for the project. This fix makes it so that we only re-request diagnostics if the file has actually been opened on the TSServer
1 parent 9cfd597 commit a8f8a2d

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

extensions/typescript-language-features/src/features/bufferSyncSupport.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,16 @@ class BufferSynchronizer {
8282
}
8383
}
8484

85-
public close(resource: vscode.Uri, filepath: string) {
85+
/**
86+
* @return Was the buffer open?
87+
*/
88+
public close(resource: vscode.Uri, filepath: string): boolean {
8689
if (this.supportsBatching) {
87-
this.updatePending(resource, new CloseOperation(filepath));
90+
return this.updatePending(resource, new CloseOperation(filepath));
8891
} else {
8992
const args: Proto.FileRequestArgs = { file: filepath };
9093
this.client.executeWithoutWaitingForResponse('close', args);
94+
return true;
9195
}
9296
}
9397

@@ -155,14 +159,14 @@ class BufferSynchronizer {
155159
return this.client.apiVersion.gte(API.v340);
156160
}
157161

158-
private updatePending(resource: vscode.Uri, op: BufferOperation): void {
162+
private updatePending(resource: vscode.Uri, op: BufferOperation): boolean {
159163
switch (op.type) {
160164
case BufferOperationType.Close:
161165
const existing = this._pending.get(resource);
162166
switch (existing?.type) {
163167
case BufferOperationType.Open:
164168
this._pending.delete(resource);
165-
return; // Open then close. No need to do anything
169+
return false; // Open then close. No need to do anything
166170
}
167171
break;
168172
}
@@ -172,6 +176,7 @@ class BufferSynchronizer {
172176
this.flush();
173177
}
174178
this._pending.set(resource, op);
179+
return true;
175180
}
176181
}
177182

@@ -232,9 +237,16 @@ class SyncedBuffer {
232237
}
233238
}
234239

235-
public close(): void {
236-
this.synchronizer.close(this.resource, this.filepath);
240+
/**
241+
* @return Was the buffer open?
242+
*/
243+
public close(): boolean {
244+
if (this.state !== BufferState.Open) {
245+
this.state = BufferState.Closed;
246+
return false;
247+
}
237248
this.state = BufferState.Closed;
249+
return this.synchronizer.close(this.resource, this.filepath);
238250
}
239251

240252
public onContentChanged(events: readonly vscode.TextDocumentContentChangeEvent[]): void {
@@ -454,9 +466,11 @@ export default class BufferSyncSupport extends Disposable {
454466
this.pendingDiagnostics.delete(resource);
455467
this.pendingGetErr?.files.delete(resource);
456468
this.syncedBuffers.delete(resource);
457-
syncedBuffer.close();
469+
const wasBufferOpen = syncedBuffer.close();
458470
this._onDelete.fire(resource);
459-
this.requestAllDiagnostics();
471+
if (wasBufferOpen) {
472+
this.requestAllDiagnostics();
473+
}
460474
}
461475

462476
public interuptGetErr<R>(f: () => R): R {

0 commit comments

Comments
 (0)