From 2421b521421b84d3628519b2c932ceb565e0f7b3 Mon Sep 17 00:00:00 2001 From: Discookie Date: Wed, 26 Jan 2022 22:14:25 +0100 Subject: [PATCH] Reduce number of `parse` calls Does not call parse: * When open files did not change * When there's no files open * When an opened window is an 'output://' window --- src/backend/processor/diagnostics.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/backend/processor/diagnostics.ts b/src/backend/processor/diagnostics.ts index 9c512ac..4f0eff6 100644 --- a/src/backend/processor/diagnostics.ts +++ b/src/backend/processor/diagnostics.ts @@ -76,6 +76,14 @@ export class DiagnosticsApi { filesToLoad.push(this._selectedEntry.file); } + // Unload reports without calling parse + if (filesToLoad.length === 0) { + this._diagnosticEntries = new Map(); + this._diagnosticsUpdated.fire(); + + return; + } + ExtensionApi.executorBridge.parseMetadata(...filesToLoad.map(file => Uri.file(file))) .catch((err: any) => console.log(`Internal error in reloadDiagnostics: ${err}`)); } @@ -143,9 +151,20 @@ export class DiagnosticsApi { } private onDocumentsChanged(event: TextEditor[]): void { - this._openedFiles = event.map(editor => editor.document.uri.fsPath); - - this.reloadDiagnostics(); + const newFiles = event + // Filters out the Output tab's extra events + .filter(editor => editor.document.uri.scheme !== 'output') + .map(editor => editor.document.uri.fsPath) + .sort(); + + // Only reload diagnostics when files are changed + if ( + this._openedFiles.length !== newFiles.length || + this._openedFiles.some((filePath, idx) => filePath !== newFiles[idx]) + ) { + this._openedFiles = newFiles; + this.reloadDiagnostics(); + } } private onMetadataUpdated(_metadata: CheckerMetadata | undefined) {