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
This commit is contained in:
Matt Bierner 2020-04-11 17:30:00 -07:00
parent 9cfd597153
commit a8f8a2dca0

View file

@ -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<R>(f: () => R): R {