Convert extensions/ql-vscode/src/query-history/query-history-manager.ts to call typed commands

This commit is contained in:
Robert
2023-03-23 13:02:09 +00:00
parent 2e7952cb37
commit a9e495118c
6 changed files with 15 additions and 7 deletions

View File

@@ -38,6 +38,7 @@ export type BuiltInVsCodeCommands = {
// The codeQLDatabases.focus command is provided by VS Code because we've registered the custom view
"codeQLDatabases.focus": () => Promise<void>;
"markdown.showPreviewToSide": (uri: Uri) => Promise<void>;
revealFileInOS: (uri: Uri) => Promise<void>;
setContext: (
key: `${"codeql" | "codeQL"}${string}`,
value: unknown,

View File

@@ -777,6 +777,7 @@ async function activateWithInstalledDistribution(
};
const qhm = new QueryHistoryManager(
app,
qs,
dbm,
localQueryResultsView,

View File

@@ -1,6 +1,5 @@
import { join, dirname } from "path";
import {
commands,
Disposable,
env,
EventEmitter,
@@ -61,6 +60,7 @@ import { HistoryTreeDataProvider } from "./history-tree-data-provider";
import { redactableError } from "../pure/errors";
import { QueryHistoryDirs } from "./query-history-dirs";
import { QueryHistoryCommands } from "../common/commands";
import { App } from "../common/app";
import { tryOpenExternalFile } from "../vscode-utils/external-files";
/**
@@ -131,6 +131,7 @@ export class QueryHistoryManager extends DisposableObject {
readonly onDidCompleteQuery = this._onDidCompleteQuery.event;
constructor(
private readonly app: App,
private readonly qs: QueryRunner,
private readonly dbm: DatabaseManager,
private readonly localQueriesResultsView: ResultsView,
@@ -747,7 +748,7 @@ export class QueryHistoryManager extends DisposableObject {
}
}
try {
await commands.executeCommand(
await this.app.commands.execute(
"revealFileInOS",
Uri.file(externalFilePath),
);
@@ -1073,7 +1074,7 @@ export class QueryHistoryManager extends DisposableObject {
const actionsWorkflowRunUrl = getActionsWorkflowRunUrl(finalSingleItem);
await commands.executeCommand(
await this.app.commands.execute(
"vscode.open",
Uri.parse(actionsWorkflowRunUrl),
);
@@ -1097,7 +1098,7 @@ export class QueryHistoryManager extends DisposableObject {
return;
}
await commands.executeCommand(
await this.app.commands.execute(
"codeQL.copyVariantAnalysisRepoList",
finalSingleItem.variantAnalysis.id,
);

View File

@@ -27,6 +27,7 @@ import {
} from "../../../../src/query-history/history-tree-data-provider";
import { QueryHistoryManager } from "../../../../src/query-history/query-history-manager";
import { createMockQueryHistoryDirs } from "../../../factories/query-history/query-history-dirs";
import { createMockApp } from "../../../__mocks__/appMock";
describe("HistoryTreeDataProvider", () => {
const mockExtensionLocation = join(tmpDir.name, "mock-extension-location");
@@ -421,6 +422,7 @@ describe("HistoryTreeDataProvider", () => {
async function createMockQueryHistory(allHistory: QueryHistoryInfo[]) {
const qhm = new QueryHistoryManager(
createMockApp({}),
{} as QueryRunner,
{} as DatabaseManager,
localQueriesResultsViewStub,

View File

@@ -777,7 +777,7 @@ describe("QueryHistoryManager", () => {
const item = localQueryHistory[4];
await queryHistoryManager.handleCopyRepoList(item, [item]);
expect(executeCommandSpy).not.toBeCalled();
expect(executeCommand).not.toBeCalled();
});
it("should copy repo list for a single variant analysis", async () => {
@@ -785,7 +785,7 @@ describe("QueryHistoryManager", () => {
const item = variantAnalysisHistory[1];
await queryHistoryManager.handleCopyRepoList(item, [item]);
expect(executeCommandSpy).toBeCalledWith(
expect(executeCommand).toBeCalledWith(
"codeQL.copyVariantAnalysisRepoList",
item.variantAnalysis.id,
);
@@ -797,7 +797,7 @@ describe("QueryHistoryManager", () => {
const item1 = variantAnalysisHistory[1];
const item2 = variantAnalysisHistory[3];
await queryHistoryManager.handleCopyRepoList(item1, [item1, item2]);
expect(executeCommandSpy).not.toBeCalled();
expect(executeCommand).not.toBeCalled();
});
});
@@ -1094,6 +1094,7 @@ describe("QueryHistoryManager", () => {
async function createMockQueryHistory(allHistory: QueryHistoryInfo[]) {
const qhm = new QueryHistoryManager(
mockApp,
{} as QueryRunner,
{} as DatabaseManager,
localQueriesResultsViewStub,

View File

@@ -21,6 +21,7 @@ import { VariantAnalysisManager } from "../../../../src/variant-analysis/variant
import { QueryHistoryManager } from "../../../../src/query-history/query-history-manager";
import { mockedObject } from "../../utils/mocking.helpers";
import { createMockQueryHistoryDirs } from "../../../factories/query-history/query-history-dirs";
import { createMockApp } from "../../../__mocks__/appMock";
// set a higher timeout since recursive delete may take a while, expecially on Windows.
jest.setTimeout(120000);
@@ -73,6 +74,7 @@ describe("Variant Analyses and QueryHistoryManager", () => {
).queries;
qhm = new QueryHistoryManager(
createMockApp({}),
{} as QueryRunner,
{} as DatabaseManager,
localQueriesResultsViewStub,