Skip to content

Commit 46c284d

Browse files
authored
Merge pull request #3803 from asgerf/asgerf/factor-out-evaluator-log-paths
Refactor: Store EvaluatorLogPaths object on LocalQueryInfo
2 parents 1ac725b + eee5939 commit 46c284d

File tree

5 files changed

+35
-33
lines changed

5 files changed

+35
-33
lines changed

extensions/ql-vscode/src/log-insights/log-scanner-service.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@ export class LogScannerService extends DisposableObject {
9494
public async scanEvalLog(query: QueryHistoryInfo | undefined): Promise<void> {
9595
this.diagnosticCollection.clear();
9696

97-
if (
98-
query?.t !== "local" ||
99-
query.evalLogSummaryLocation === undefined ||
100-
query.jsonEvalLogSummaryLocation === undefined
101-
) {
97+
if (query?.t !== "local" || query.evaluatorLogPaths === undefined) {
10298
return;
10399
}
104100

105-
const diagnostics = await this.scanLog(
106-
query.jsonEvalLogSummaryLocation,
107-
query.evalLogSummarySymbolsLocation,
108-
);
109-
const uri = Uri.file(query.evalLogSummaryLocation);
101+
const { summarySymbols, jsonSummary, humanReadableSummary } =
102+
query.evaluatorLogPaths;
103+
104+
if (jsonSummary === undefined || humanReadableSummary === undefined) {
105+
return;
106+
}
107+
108+
const diagnostics = await this.scanLog(jsonSummary, summarySymbols);
109+
const uri = Uri.file(humanReadableSummary);
110110
this.diagnosticCollection.set(uri, diagnostics);
111111
}
112112

extensions/ql-vscode/src/query-history/query-history-manager.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ export class QueryHistoryManager extends DisposableObject {
781781

782782
private async warnNoEvalLogSummary(item: LocalQueryInfo) {
783783
const evalLogLocation =
784-
item.evalLogLocation ?? item.initialInfo.outputDir?.evalLogPath;
784+
item.evaluatorLogPaths?.log ?? item.initialInfo.outputDir?.evalLogPath;
785785

786786
// Summary log file doesn't exist.
787787
if (evalLogLocation && (await pathExists(evalLogLocation))) {
@@ -801,7 +801,7 @@ export class QueryHistoryManager extends DisposableObject {
801801
}
802802

803803
const evalLogLocation =
804-
item.evalLogLocation ?? item.initialInfo.outputDir?.evalLogPath;
804+
item.evaluatorLogPaths?.log ?? item.initialInfo.outputDir?.evalLogPath;
805805

806806
if (evalLogLocation && (await pathExists(evalLogLocation))) {
807807
await tryOpenExternalFile(this.app.commands, evalLogLocation);
@@ -816,12 +816,15 @@ export class QueryHistoryManager extends DisposableObject {
816816
}
817817

818818
// If the summary file location wasn't saved, display error
819-
if (!item.evalLogSummaryLocation) {
819+
if (!item.evaluatorLogPaths?.humanReadableSummary) {
820820
await this.warnNoEvalLogSummary(item);
821821
return;
822822
}
823823

824-
await tryOpenExternalFile(this.app.commands, item.evalLogSummaryLocation);
824+
await tryOpenExternalFile(
825+
this.app.commands,
826+
item.evaluatorLogPaths.humanReadableSummary,
827+
);
825828
}
826829

827830
async handleShowEvalLogViewer(item: QueryHistoryInfo) {
@@ -830,15 +833,15 @@ export class QueryHistoryManager extends DisposableObject {
830833
}
831834

832835
// If the JSON summary file location wasn't saved, display error
833-
if (item.jsonEvalLogSummaryLocation === undefined) {
836+
if (item.evaluatorLogPaths?.jsonSummary === undefined) {
834837
await this.warnNoEvalLogSummary(item);
835838
return;
836839
}
837840

838841
// TODO(angelapwen): Stream the file in.
839842
try {
840843
const evalLogData: EvalLogData[] = await parseViewerData(
841-
item.jsonEvalLogSummaryLocation,
844+
item.evaluatorLogPaths.jsonSummary,
842845
);
843846
const evalLogTreeBuilder = new EvalLogTreeBuilder(
844847
item.getQueryName(),
@@ -847,7 +850,7 @@ export class QueryHistoryManager extends DisposableObject {
847850
this.evalLogViewer.updateRoots(await evalLogTreeBuilder.getRoots());
848851
} catch {
849852
throw new Error(
850-
`Could not read evaluator log summary JSON file to generate viewer data at ${item.jsonEvalLogSummaryLocation}.`,
853+
`Could not read evaluator log summary JSON file to generate viewer data at ${item.evaluatorLogPaths.jsonSummary}.`,
851854
);
852855
}
853856
}

extensions/ql-vscode/src/query-history/store/query-history-local-query-domain-mapper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ export function mapLocalQueryInfoToDto(
2525
return {
2626
initialInfo: mapInitialQueryInfoToDto(query.initialInfo),
2727
t: "local",
28-
evalLogLocation: query.evalLogLocation,
29-
evalLogSummaryLocation: query.evalLogSummaryLocation,
30-
jsonEvalLogSummaryLocation: query.jsonEvalLogSummaryLocation,
31-
evalLogSummarySymbolsLocation: query.evalLogSummarySymbolsLocation,
28+
evalLogLocation: query.evaluatorLogPaths?.log,
29+
evalLogSummaryLocation: query.evaluatorLogPaths?.humanReadableSummary,
30+
jsonEvalLogSummaryLocation: query.evaluatorLogPaths?.jsonSummary,
31+
evalLogSummarySymbolsLocation: query.evaluatorLogPaths?.summarySymbols,
3232
failureReason: query.failureReason,
3333
completedQuery:
3434
query.completedQuery && mapCompletedQueryToDto(query.completedQuery),

extensions/ql-vscode/src/query-history/store/query-history-local-query-dto-mapper.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ export function mapLocalQueryItemToDomainModel(
3232
localQuery.failureReason,
3333
localQuery.completedQuery &&
3434
mapCompletedQueryInfoToDomainModel(localQuery.completedQuery),
35-
localQuery.evalLogLocation,
36-
localQuery.evalLogSummaryLocation,
37-
localQuery.jsonEvalLogSummaryLocation,
38-
localQuery.evalLogSummarySymbolsLocation,
35+
localQuery.evalLogLocation
36+
? {
37+
log: localQuery.evalLogLocation,
38+
humanReadableSummary: localQuery.evalLogSummaryLocation,
39+
jsonSummary: localQuery.jsonEvalLogSummaryLocation,
40+
summarySymbols: localQuery.evalLogSummarySymbolsLocation,
41+
endSummary: undefined,
42+
}
43+
: undefined,
3944
);
4045
}
4146

extensions/ql-vscode/src/query-results.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,7 @@ export class LocalQueryInfo {
200200
private cancellationSource?: CancellationTokenSource, // used to cancel in progress queries
201201
public failureReason?: string,
202202
public completedQuery?: CompletedQueryInfo,
203-
public evalLogLocation?: string,
204-
public evalLogSummaryLocation?: string,
205-
public jsonEvalLogSummaryLocation?: string,
206-
public evalLogSummarySymbolsLocation?: string,
203+
public evaluatorLogPaths?: EvaluatorLogPaths,
207204
) {
208205
/**/
209206
}
@@ -229,10 +226,7 @@ export class LocalQueryInfo {
229226

230227
/** Sets the paths to the various structured evaluator logs. */
231228
public setEvaluatorLogPaths(logPaths: EvaluatorLogPaths): void {
232-
this.evalLogLocation = logPaths.log;
233-
this.evalLogSummaryLocation = logPaths.humanReadableSummary;
234-
this.jsonEvalLogSummaryLocation = logPaths.jsonSummary;
235-
this.evalLogSummarySymbolsLocation = logPaths.summarySymbols;
229+
this.evaluatorLogPaths = logPaths;
236230
}
237231

238232
/**

0 commit comments

Comments
 (0)