Skip to content

Commit 6ff8aad

Browse files
committed
Simplify query history type checks
1 parent 4d1e61a commit 6ff8aad

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function getRawQueryName(item: QueryHistoryInfo): string {
2222

2323
/**
2424
* Gets an identifier for the query history item which could be
25-
* a local/remote query or a variant analysis. This id isn't guaranteed
25+
* a local query or a variant analysis. This id isn't guaranteed
2626
* to be unique for each item in the query history.
2727
* @param item the history item.
2828
* @returns the id of the query or variant analysis.

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

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -755,14 +755,12 @@ export class QueryHistoryManager extends DisposableObject {
755755
) {
756756
// show original query file on double click
757757
await this.handleOpenQuery(finalSingleItem, [finalSingleItem]);
758-
} else {
758+
} else if (
759+
finalSingleItem.t === "variant-analysis" ||
760+
finalSingleItem.status === QueryStatus.Completed
761+
) {
759762
// show results on single click (if results view is available)
760-
if (
761-
finalSingleItem.t === "variant-analysis" ||
762-
finalSingleItem.status === QueryStatus.Completed
763-
) {
764-
await this.openQueryResults(finalSingleItem);
765-
}
763+
await this.openQueryResults(finalSingleItem);
766764
}
767765
}
768766

@@ -797,6 +795,8 @@ export class QueryHistoryManager extends DisposableObject {
797795
return this.variantAnalysisManager.getVariantAnalysisStorageLocation(
798796
queryHistoryItem.variantAnalysis.id,
799797
);
798+
} else {
799+
assertNever(queryHistoryItem);
800800
}
801801

802802
throw new Error("Unable to get query directory");
@@ -830,6 +830,8 @@ export class QueryHistoryManager extends DisposableObject {
830830
),
831831
"timestamp",
832832
);
833+
} else {
834+
assertNever(finalSingleItem);
833835
}
834836

835837
if (externalFilePath) {
@@ -994,6 +996,8 @@ export class QueryHistoryManager extends DisposableObject {
994996
"codeQL.cancelVariantAnalysis",
995997
item.variantAnalysis.id,
996998
);
999+
} else {
1000+
assertNever(item);
9971001
}
9981002
}
9991003
});
@@ -1185,17 +1189,19 @@ export class QueryHistoryManager extends DisposableObject {
11851189
multiSelect,
11861190
);
11871191

1188-
// Remote queries only
1189-
if (!this.assertSingleQuery(finalMultiSelect) || !finalSingleItem) {
1192+
// Variant analyses only
1193+
if (
1194+
!this.assertSingleQuery(finalMultiSelect) ||
1195+
!finalSingleItem ||
1196+
finalSingleItem.t !== "variant-analysis"
1197+
) {
11901198
return;
11911199
}
11921200

1193-
if (finalSingleItem.t === "variant-analysis") {
1194-
await commands.executeCommand(
1195-
"codeQL.copyVariantAnalysisRepoList",
1196-
finalSingleItem.variantAnalysis.id,
1197-
);
1198-
}
1201+
await commands.executeCommand(
1202+
"codeQL.copyVariantAnalysisRepoList",
1203+
finalSingleItem.variantAnalysis.id,
1204+
);
11991205
}
12001206

12011207
async handleExportResults(
@@ -1207,17 +1213,19 @@ export class QueryHistoryManager extends DisposableObject {
12071213
multiSelect,
12081214
);
12091215

1210-
if (!this.assertSingleQuery(finalMultiSelect) || !finalSingleItem) {
1216+
// Variant analysis only
1217+
if (
1218+
!this.assertSingleQuery(finalMultiSelect) ||
1219+
!finalSingleItem ||
1220+
finalSingleItem.t !== "variant-analysis"
1221+
) {
12111222
return;
12121223
}
12131224

1214-
// Variant analysis only
1215-
if (finalSingleItem.t === "variant-analysis") {
1216-
await commands.executeCommand(
1217-
"codeQL.exportVariantAnalysisResults",
1218-
finalSingleItem.variantAnalysis.id,
1219-
);
1220-
}
1225+
await commands.executeCommand(
1226+
"codeQL.exportVariantAnalysisResults",
1227+
finalSingleItem.variantAnalysis.id,
1228+
);
12211229
}
12221230

12231231
addQuery(item: QueryHistoryInfo) {
@@ -1290,7 +1298,7 @@ the file in the file explorer and dragging it into the workspace.`,
12901298
singleItem: QueryHistoryInfo,
12911299
multiSelect: QueryHistoryInfo[],
12921300
): Promise<CompletedLocalQueryInfo | undefined> {
1293-
// Remote queries cannot be compared
1301+
// Variant analyses cannot be compared
12941302
if (
12951303
singleItem.t !== "local" ||
12961304
multiSelect.some((s) => s.t !== "local") ||

0 commit comments

Comments
 (0)