From e146e7a314be312da2a2db7093e671b818dcb9ed Mon Sep 17 00:00:00 2001 From: Asger F Date: Tue, 12 Nov 2024 15:42:27 +0100 Subject: [PATCH 1/2] Refactor: Store EvaluatorLogPaths object on LocalQueryInfo Previously the fields from EvaluatorLogPaths were copied 1:1 into LocalQueryInfo but under different names. It seems easier to keep track of the different kinds of logs if they are called the same everywhere. --- .../src/log-insights/log-scanner-service.ts | 20 +++++++++---------- .../query-history/query-history-manager.ts | 17 +++++++++------- ...query-history-local-query-domain-mapper.ts | 8 ++++---- .../query-history-local-query-dto-mapper.ts | 11 ++++++---- extensions/ql-vscode/src/query-results.ts | 10 ++-------- .../ql-vscode/src/run-queries-shared.ts | 2 +- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/extensions/ql-vscode/src/log-insights/log-scanner-service.ts b/extensions/ql-vscode/src/log-insights/log-scanner-service.ts index d2fe1311907..76e996633dc 100644 --- a/extensions/ql-vscode/src/log-insights/log-scanner-service.ts +++ b/extensions/ql-vscode/src/log-insights/log-scanner-service.ts @@ -94,19 +94,19 @@ export class LogScannerService extends DisposableObject { public async scanEvalLog(query: QueryHistoryInfo | undefined): Promise { this.diagnosticCollection.clear(); - if ( - query?.t !== "local" || - query.evalLogSummaryLocation === undefined || - query.jsonEvalLogSummaryLocation === undefined - ) { + if (query?.t !== "local" || query.evalutorLogPaths === undefined) { return; } - const diagnostics = await this.scanLog( - query.jsonEvalLogSummaryLocation, - query.evalLogSummarySymbolsLocation, - ); - const uri = Uri.file(query.evalLogSummaryLocation); + const { summarySymbols, jsonSummary, humanReadableSummary } = + query.evalutorLogPaths; + + if (jsonSummary === undefined || humanReadableSummary === undefined) { + return; + } + + const diagnostics = await this.scanLog(jsonSummary, summarySymbols); + const uri = Uri.file(humanReadableSummary); this.diagnosticCollection.set(uri, diagnostics); } diff --git a/extensions/ql-vscode/src/query-history/query-history-manager.ts b/extensions/ql-vscode/src/query-history/query-history-manager.ts index d4b312ad563..c94db37f82a 100644 --- a/extensions/ql-vscode/src/query-history/query-history-manager.ts +++ b/extensions/ql-vscode/src/query-history/query-history-manager.ts @@ -781,7 +781,7 @@ export class QueryHistoryManager extends DisposableObject { private async warnNoEvalLogSummary(item: LocalQueryInfo) { const evalLogLocation = - item.evalLogLocation ?? item.initialInfo.outputDir?.evalLogPath; + item.evalutorLogPaths?.log ?? item.initialInfo.outputDir?.evalLogPath; // Summary log file doesn't exist. if (evalLogLocation && (await pathExists(evalLogLocation))) { @@ -801,7 +801,7 @@ export class QueryHistoryManager extends DisposableObject { } const evalLogLocation = - item.evalLogLocation ?? item.initialInfo.outputDir?.evalLogPath; + item.evalutorLogPaths?.log ?? item.initialInfo.outputDir?.evalLogPath; if (evalLogLocation && (await pathExists(evalLogLocation))) { await tryOpenExternalFile(this.app.commands, evalLogLocation); @@ -816,12 +816,15 @@ export class QueryHistoryManager extends DisposableObject { } // If the summary file location wasn't saved, display error - if (!item.evalLogSummaryLocation) { + if (!item.evalutorLogPaths?.humanReadableSummary) { await this.warnNoEvalLogSummary(item); return; } - await tryOpenExternalFile(this.app.commands, item.evalLogSummaryLocation); + await tryOpenExternalFile( + this.app.commands, + item.evalutorLogPaths.humanReadableSummary, + ); } async handleShowEvalLogViewer(item: QueryHistoryInfo) { @@ -830,7 +833,7 @@ export class QueryHistoryManager extends DisposableObject { } // If the JSON summary file location wasn't saved, display error - if (item.jsonEvalLogSummaryLocation === undefined) { + if (item.evalutorLogPaths?.jsonSummary === undefined) { await this.warnNoEvalLogSummary(item); return; } @@ -838,7 +841,7 @@ export class QueryHistoryManager extends DisposableObject { // TODO(angelapwen): Stream the file in. try { const evalLogData: EvalLogData[] = await parseViewerData( - item.jsonEvalLogSummaryLocation, + item.evalutorLogPaths.jsonSummary, ); const evalLogTreeBuilder = new EvalLogTreeBuilder( item.getQueryName(), @@ -847,7 +850,7 @@ export class QueryHistoryManager extends DisposableObject { this.evalLogViewer.updateRoots(await evalLogTreeBuilder.getRoots()); } catch { throw new Error( - `Could not read evaluator log summary JSON file to generate viewer data at ${item.jsonEvalLogSummaryLocation}.`, + `Could not read evaluator log summary JSON file to generate viewer data at ${item.evalutorLogPaths.jsonSummary}.`, ); } } diff --git a/extensions/ql-vscode/src/query-history/store/query-history-local-query-domain-mapper.ts b/extensions/ql-vscode/src/query-history/store/query-history-local-query-domain-mapper.ts index 45c7b184c11..9812dd5640f 100644 --- a/extensions/ql-vscode/src/query-history/store/query-history-local-query-domain-mapper.ts +++ b/extensions/ql-vscode/src/query-history/store/query-history-local-query-domain-mapper.ts @@ -25,10 +25,10 @@ export function mapLocalQueryInfoToDto( return { initialInfo: mapInitialQueryInfoToDto(query.initialInfo), t: "local", - evalLogLocation: query.evalLogLocation, - evalLogSummaryLocation: query.evalLogSummaryLocation, - jsonEvalLogSummaryLocation: query.jsonEvalLogSummaryLocation, - evalLogSummarySymbolsLocation: query.evalLogSummarySymbolsLocation, + evalLogLocation: query.evalutorLogPaths?.log, + evalLogSummaryLocation: query.evalutorLogPaths?.humanReadableSummary, + jsonEvalLogSummaryLocation: query.evalutorLogPaths?.jsonSummary, + evalLogSummarySymbolsLocation: query.evalutorLogPaths?.summarySymbols, failureReason: query.failureReason, completedQuery: query.completedQuery && mapCompletedQueryToDto(query.completedQuery), diff --git a/extensions/ql-vscode/src/query-history/store/query-history-local-query-dto-mapper.ts b/extensions/ql-vscode/src/query-history/store/query-history-local-query-dto-mapper.ts index ee6765c80d7..b9bd41e51e8 100644 --- a/extensions/ql-vscode/src/query-history/store/query-history-local-query-dto-mapper.ts +++ b/extensions/ql-vscode/src/query-history/store/query-history-local-query-dto-mapper.ts @@ -32,10 +32,13 @@ export function mapLocalQueryItemToDomainModel( localQuery.failureReason, localQuery.completedQuery && mapCompletedQueryInfoToDomainModel(localQuery.completedQuery), - localQuery.evalLogLocation, - localQuery.evalLogSummaryLocation, - localQuery.jsonEvalLogSummaryLocation, - localQuery.evalLogSummarySymbolsLocation, + { + log: localQuery.evalLogLocation, + humanReadableSummary: localQuery.evalLogSummaryLocation, + jsonSummary: localQuery.jsonEvalLogSummaryLocation, + summarySymbols: localQuery.evalLogSummarySymbolsLocation, + endSummary: undefined, + }, ); } diff --git a/extensions/ql-vscode/src/query-results.ts b/extensions/ql-vscode/src/query-results.ts index 95f5fcb2641..41a5cfd523c 100644 --- a/extensions/ql-vscode/src/query-results.ts +++ b/extensions/ql-vscode/src/query-results.ts @@ -200,10 +200,7 @@ export class LocalQueryInfo { private cancellationSource?: CancellationTokenSource, // used to cancel in progress queries public failureReason?: string, public completedQuery?: CompletedQueryInfo, - public evalLogLocation?: string, - public evalLogSummaryLocation?: string, - public jsonEvalLogSummaryLocation?: string, - public evalLogSummarySymbolsLocation?: string, + public evalutorLogPaths?: EvaluatorLogPaths, ) { /**/ } @@ -229,10 +226,7 @@ export class LocalQueryInfo { /** Sets the paths to the various structured evaluator logs. */ public setEvaluatorLogPaths(logPaths: EvaluatorLogPaths): void { - this.evalLogLocation = logPaths.log; - this.evalLogSummaryLocation = logPaths.humanReadableSummary; - this.jsonEvalLogSummaryLocation = logPaths.jsonSummary; - this.evalLogSummarySymbolsLocation = logPaths.summarySymbols; + this.evalutorLogPaths = logPaths; } /** diff --git a/extensions/ql-vscode/src/run-queries-shared.ts b/extensions/ql-vscode/src/run-queries-shared.ts index 6dbaa8e651b..674da31ee8f 100644 --- a/extensions/ql-vscode/src/run-queries-shared.ts +++ b/extensions/ql-vscode/src/run-queries-shared.ts @@ -45,7 +45,7 @@ import type { ProgressCallback } from "./common/vscode/progress"; * Holds the paths to the various structured log summary files generated for a query evaluation. */ export interface EvaluatorLogPaths { - log: string; + log: string | undefined; humanReadableSummary: string | undefined; endSummary: string | undefined; jsonSummary: string | undefined; From fa3e3ff669a7297e2669f360001b481c481b6bbb Mon Sep 17 00:00:00 2001 From: Asger F Date: Wed, 13 Nov 2024 13:30:38 +0100 Subject: [PATCH 2/2] Initialise object even if evaluator log paths were omitted --- extensions/ql-vscode/src/query-results.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/extensions/ql-vscode/src/query-results.ts b/extensions/ql-vscode/src/query-results.ts index 41a5cfd523c..ea4acd9097b 100644 --- a/extensions/ql-vscode/src/query-results.ts +++ b/extensions/ql-vscode/src/query-results.ts @@ -200,7 +200,13 @@ export class LocalQueryInfo { private cancellationSource?: CancellationTokenSource, // used to cancel in progress queries public failureReason?: string, public completedQuery?: CompletedQueryInfo, - public evalutorLogPaths?: EvaluatorLogPaths, + public evalutorLogPaths: EvaluatorLogPaths = { + log: undefined, + humanReadableSummary: undefined, + endSummary: undefined, + jsonSummary: undefined, + summarySymbols: undefined, + }, ) { /**/ }