Convert handleOpenQuery to use createSingleSelectionCommand
This commit is contained in:
@@ -59,6 +59,7 @@ import { QueryHistoryDirs } from "./query-history-dirs";
|
|||||||
import { QueryHistoryCommands } from "../common/commands";
|
import { QueryHistoryCommands } from "../common/commands";
|
||||||
import { App } from "../common/app";
|
import { App } from "../common/app";
|
||||||
import { tryOpenExternalFile } from "../vscode-utils/external-files";
|
import { tryOpenExternalFile } from "../vscode-utils/external-files";
|
||||||
|
import { createSingleSelectionCommand } from "../common/selection-commands";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* query-history-manager.ts
|
* query-history-manager.ts
|
||||||
@@ -235,8 +236,10 @@ export class QueryHistoryManager extends DisposableObject {
|
|||||||
"codeQLQueryHistory.sortByDate": this.handleSortByDate.bind(this),
|
"codeQLQueryHistory.sortByDate": this.handleSortByDate.bind(this),
|
||||||
"codeQLQueryHistory.sortByCount": this.handleSortByCount.bind(this),
|
"codeQLQueryHistory.sortByCount": this.handleSortByCount.bind(this),
|
||||||
|
|
||||||
"codeQLQueryHistory.openQueryContextMenu":
|
"codeQLQueryHistory.openQueryContextMenu": createSingleSelectionCommand(
|
||||||
this.handleOpenQuery.bind(this),
|
this.handleOpenQuery.bind(this),
|
||||||
|
"query",
|
||||||
|
),
|
||||||
"codeQLQueryHistory.removeHistoryItemContextMenu":
|
"codeQLQueryHistory.removeHistoryItemContextMenu":
|
||||||
this.handleRemoveHistoryItem.bind(this),
|
this.handleRemoveHistoryItem.bind(this),
|
||||||
"codeQLQueryHistory.removeHistoryItemContextInline":
|
"codeQLQueryHistory.removeHistoryItemContextInline":
|
||||||
@@ -395,35 +398,26 @@ export class QueryHistoryManager extends DisposableObject {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleOpenQuery(
|
async handleOpenQuery(item: QueryHistoryInfo): Promise<void> {
|
||||||
singleItem: QueryHistoryInfo,
|
if (item.t === "variant-analysis") {
|
||||||
multiSelect: QueryHistoryInfo[] | undefined,
|
await this.variantAnalysisManager.openQueryFile(item.variantAnalysis.id);
|
||||||
): Promise<void> {
|
|
||||||
if (!this.assertSingleQuery(multiSelect)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (singleItem.t === "variant-analysis") {
|
|
||||||
await this.variantAnalysisManager.openQueryFile(
|
|
||||||
singleItem.variantAnalysis.id,
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let queryPath: string;
|
let queryPath: string;
|
||||||
switch (singleItem.t) {
|
switch (item.t) {
|
||||||
case "local":
|
case "local":
|
||||||
queryPath = singleItem.initialInfo.queryPath;
|
queryPath = item.initialInfo.queryPath;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assertNever(singleItem);
|
assertNever(item);
|
||||||
}
|
}
|
||||||
const textDocument = await workspace.openTextDocument(Uri.file(queryPath));
|
const textDocument = await workspace.openTextDocument(Uri.file(queryPath));
|
||||||
const editor = await window.showTextDocument(textDocument, ViewColumn.One);
|
const editor = await window.showTextDocument(textDocument, ViewColumn.One);
|
||||||
|
|
||||||
if (singleItem.t === "local") {
|
if (item.t === "local") {
|
||||||
const queryText = singleItem.initialInfo.queryText;
|
const queryText = item.initialInfo.queryText;
|
||||||
if (queryText !== undefined && singleItem.initialInfo.isQuickQuery) {
|
if (queryText !== undefined && item.initialInfo.isQuickQuery) {
|
||||||
await editor.edit((edit) =>
|
await editor.edit((edit) =>
|
||||||
edit.replace(
|
edit.replace(
|
||||||
textDocument.validateRange(
|
textDocument.validateRange(
|
||||||
@@ -629,7 +623,7 @@ export class QueryHistoryManager extends DisposableObject {
|
|||||||
singleItem === prevItemClick.item
|
singleItem === prevItemClick.item
|
||||||
) {
|
) {
|
||||||
// show original query file on double click
|
// show original query file on double click
|
||||||
await this.handleOpenQuery(singleItem, [singleItem]);
|
await this.handleOpenQuery(singleItem);
|
||||||
} else if (
|
} else if (
|
||||||
singleItem.t === "variant-analysis" ||
|
singleItem.t === "variant-analysis" ||
|
||||||
singleItem.status === QueryStatus.Completed
|
singleItem.status === QueryStatus.Completed
|
||||||
|
|||||||
Reference in New Issue
Block a user