From a8f8a2dca0847fd6a96a0bfaa2f47c10cead33a8 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Sat, 11 Apr 2020 17:30:00 -0700 Subject: [PATCH] Only re-request diagnostics if the file has actually been opened Fixes #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 --- .../src/features/bufferSyncSupport.ts | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/extensions/typescript-language-features/src/features/bufferSyncSupport.ts b/extensions/typescript-language-features/src/features/bufferSyncSupport.ts index 7110e69c696..647db7a1187 100644 --- a/extensions/typescript-language-features/src/features/bufferSyncSupport.ts +++ b/extensions/typescript-language-features/src/features/bufferSyncSupport.ts @@ -82,12 +82,16 @@ class BufferSynchronizer { } } - public close(resource: vscode.Uri, filepath: string) { + /** + * @return Was the buffer open? + */ + public close(resource: vscode.Uri, filepath: string): boolean { if (this.supportsBatching) { - this.updatePending(resource, new CloseOperation(filepath)); + return this.updatePending(resource, new CloseOperation(filepath)); } else { const args: Proto.FileRequestArgs = { file: filepath }; this.client.executeWithoutWaitingForResponse('close', args); + return true; } } @@ -155,14 +159,14 @@ class BufferSynchronizer { return this.client.apiVersion.gte(API.v340); } - private updatePending(resource: vscode.Uri, op: BufferOperation): void { + private updatePending(resource: vscode.Uri, op: BufferOperation): boolean { switch (op.type) { case BufferOperationType.Close: const existing = this._pending.get(resource); switch (existing?.type) { case BufferOperationType.Open: this._pending.delete(resource); - return; // Open then close. No need to do anything + return false; // Open then close. No need to do anything } break; } @@ -172,6 +176,7 @@ class BufferSynchronizer { this.flush(); } this._pending.set(resource, op); + return true; } } @@ -232,9 +237,16 @@ class SyncedBuffer { } } - public close(): void { - this.synchronizer.close(this.resource, this.filepath); + /** + * @return Was the buffer open? + */ + public close(): boolean { + if (this.state !== BufferState.Open) { + this.state = BufferState.Closed; + return false; + } this.state = BufferState.Closed; + return this.synchronizer.close(this.resource, this.filepath); } public onContentChanged(events: readonly vscode.TextDocumentContentChangeEvent[]): void { @@ -454,9 +466,11 @@ export default class BufferSyncSupport extends Disposable { this.pendingDiagnostics.delete(resource); this.pendingGetErr?.files.delete(resource); this.syncedBuffers.delete(resource); - syncedBuffer.close(); + const wasBufferOpen = syncedBuffer.close(); this._onDelete.fire(resource); - this.requestAllDiagnostics(); + if (wasBufferOpen) { + this.requestAllDiagnostics(); + } } public interuptGetErr(f: () => R): R {