Convert handleShowQueryText to use createSingleSelectionCommand

This commit is contained in:
Robert
2023-04-20 17:25:21 +01:00
parent b2f0e2efd9
commit 288a2bf62a
2 changed files with 11 additions and 19 deletions

View File

@@ -268,7 +268,10 @@ export class QueryHistoryManager extends DisposableObject {
this.handleShowQueryLog.bind(this), this.handleShowQueryLog.bind(this),
"query", "query",
), ),
"codeQLQueryHistory.showQueryText": this.handleShowQueryText.bind(this), "codeQLQueryHistory.showQueryText": createSingleSelectionCommand(
this.handleShowQueryText.bind(this),
"query",
),
"codeQLQueryHistory.openQueryDirectory": createSingleSelectionCommand( "codeQLQueryHistory.openQueryDirectory": createSingleSelectionCommand(
this.handleOpenQueryDirectory.bind(this), this.handleOpenQueryDirectory.bind(this),
"query", "query",
@@ -811,31 +814,20 @@ export class QueryHistoryManager extends DisposableObject {
await Promise.all(results); await Promise.all(results);
} }
async handleShowQueryText( async handleShowQueryText(item: QueryHistoryInfo) {
singleItem: QueryHistoryInfo, if (item.t === "variant-analysis") {
multiSelect: QueryHistoryInfo[] = [], await this.variantAnalysisManager.openQueryText(item.variantAnalysis.id);
) {
if (!this.assertSingleQuery(multiSelect)) {
return;
}
if (singleItem.t === "variant-analysis") {
await this.variantAnalysisManager.openQueryText(
singleItem.variantAnalysis.id,
);
return; return;
} }
const params = new URLSearchParams({ const params = new URLSearchParams({
isQuickEval: String( isQuickEval: String(
!!( !!(item.t === "local" && item.initialInfo.quickEvalPosition),
singleItem.t === "local" && singleItem.initialInfo.quickEvalPosition
),
), ),
queryText: encodeURIComponent(getQueryText(singleItem)), queryText: encodeURIComponent(getQueryText(item)),
}); });
const queryId = getQueryId(singleItem); const queryId = getQueryId(item);
const uri = Uri.parse(`codeql:${queryId}.ql?${params.toString()}`, true); const uri = Uri.parse(`codeql:${queryId}.ql?${params.toString()}`, true);
const doc = await workspace.openTextDocument(uri); const doc = await workspace.openTextDocument(uri);

View File

@@ -183,7 +183,7 @@ describe("Variant Analyses and QueryHistoryManager", () => {
it("should get the query text", async () => { it("should get the query text", async () => {
await qhm.readQueryHistory(); await qhm.readQueryHistory();
await qhm.handleShowQueryText(qhm.treeDataProvider.allHistory[0], []); await qhm.handleShowQueryText(qhm.treeDataProvider.allHistory[0]);
expect(openQueryTextSpy).toHaveBeenCalledWith( expect(openQueryTextSpy).toHaveBeenCalledWith(
rawQueryHistory[0].variantAnalysis.id, rawQueryHistory[0].variantAnalysis.id,