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 {