Convert local database commands to typed commands
This commit is contained in:
Родитель
dbd832f1a0
Коммит
e603de41c1
|
@ -1,5 +1,6 @@
|
|||
import type { CommandManager } from "../packages/commands";
|
||||
import type { Uri } from "vscode";
|
||||
import type { DatabaseItem } from "../local-databases";
|
||||
import type { QueryHistoryInfo } from "../query-history/query-history-info";
|
||||
|
||||
// A command function matching the signature that VS Code calls when
|
||||
|
@ -53,6 +54,31 @@ export type QueryHistoryCommands = {
|
|||
"codeQLQueryHistory.copyRepoList": SelectionCommandFunction<QueryHistoryInfo>;
|
||||
};
|
||||
|
||||
// Commands used for the local databases panel
|
||||
export type LocalDatabasesCommands = {
|
||||
"codeQL.setCurrentDatabase": (uri: Uri) => Promise<void>;
|
||||
"codeQL.setDefaultTourDatabase": () => Promise<void>;
|
||||
"codeQL.upgradeCurrentDatabase": () => Promise<void>;
|
||||
"codeQL.clearCache": () => Promise<void>;
|
||||
|
||||
"codeQLDatabases.chooseDatabaseFolder": () => Promise<void>;
|
||||
"codeQLDatabases.chooseDatabaseArchive": () => Promise<void>;
|
||||
"codeQLDatabases.chooseDatabaseInternet": () => Promise<void>;
|
||||
"codeQLDatabases.chooseDatabaseGithub": () => Promise<void>;
|
||||
"codeQLDatabases.setCurrentDatabase": (
|
||||
databaseItem: DatabaseItem,
|
||||
) => Promise<void>;
|
||||
"codeQLDatabases.sortByName": () => Promise<void>;
|
||||
"codeQLDatabases.sortByDateAdded": () => Promise<void>;
|
||||
"codeQLDatabases.removeOrphanedDatabases": () => Promise<void>;
|
||||
|
||||
"codeQLDatabases.removeDatabase": SelectionCommandFunction<DatabaseItem>;
|
||||
"codeQLDatabases.upgradeDatabase": SelectionCommandFunction<DatabaseItem>;
|
||||
"codeQLDatabases.renameDatabase": SelectionCommandFunction<DatabaseItem>;
|
||||
"codeQLDatabases.openDatabaseFolder": SelectionCommandFunction<DatabaseItem>;
|
||||
"codeQLDatabases.addDatabaseSource": SelectionCommandFunction<DatabaseItem>;
|
||||
};
|
||||
|
||||
// Commands tied to variant analysis
|
||||
export type VariantAnalysisCommands = {
|
||||
"codeQL.openVariantAnalysisLogs": (
|
||||
|
@ -64,6 +90,7 @@ export type VariantAnalysisCommands = {
|
|||
|
||||
export type AllCommands = BaseCommands &
|
||||
QueryHistoryCommands &
|
||||
LocalDatabasesCommands &
|
||||
VariantAnalysisCommands;
|
||||
|
||||
export type AppCommandManager = CommandManager<AllCommands>;
|
||||
|
|
|
@ -35,7 +35,6 @@ import { CodeQLCliServer } from "./cli";
|
|||
import {
|
||||
CliConfigListener,
|
||||
DistributionConfigListener,
|
||||
isCanary,
|
||||
joinOrderWarningThreshold,
|
||||
MAX_QUERIES,
|
||||
QueryHistoryConfigListener,
|
||||
|
@ -642,7 +641,6 @@ async function activateWithInstalledDistribution(
|
|||
getContextStoragePath(ctx),
|
||||
ctx.extensionPath,
|
||||
);
|
||||
databaseUI.init();
|
||||
ctx.subscriptions.push(databaseUI);
|
||||
|
||||
void extLogger.log("Initializing evaluator log viewer.");
|
||||
|
@ -1096,6 +1094,7 @@ async function activateWithInstalledDistribution(
|
|||
...getCommands(),
|
||||
...qhm.getCommands(),
|
||||
...variantAnalysisManager.getCommands(),
|
||||
...databaseUI.getCommands(),
|
||||
};
|
||||
|
||||
for (const [commandName, command] of Object.entries(allCommands)) {
|
||||
|
@ -1290,8 +1289,7 @@ async function activateWithInstalledDistribution(
|
|||
commandRunnerWithProgress(
|
||||
"codeQL.chooseDatabaseGithub",
|
||||
async (progress: ProgressCallback, token: CancellationToken) => {
|
||||
const credentials = isCanary() ? app.credentials : undefined;
|
||||
await databaseUI.chooseDatabaseGithub(credentials, progress, token);
|
||||
await databaseUI.chooseDatabaseGithub(progress, token);
|
||||
},
|
||||
{
|
||||
title: "Adding database from GitHub",
|
||||
|
|
|
@ -21,7 +21,7 @@ import {
|
|||
DatabaseItem,
|
||||
DatabaseManager,
|
||||
} from "./local-databases";
|
||||
import { commandRunner, ProgressCallback, withProgress } from "./commandRunner";
|
||||
import { ProgressCallback, withProgress } from "./commandRunner";
|
||||
import {
|
||||
isLikelyDatabaseRoot,
|
||||
isLikelyDbLanguageFolder,
|
||||
|
@ -38,8 +38,8 @@ import { asError, asyncFilter, getErrorMessage } from "./pure/helpers-pure";
|
|||
import { QueryRunner } from "./queryRunner";
|
||||
import { isCanary } from "./config";
|
||||
import { App } from "./common/app";
|
||||
import { Credentials } from "./common/authentication";
|
||||
import { redactableError } from "./pure/errors";
|
||||
import { LocalDatabasesCommands } from "./common/commands";
|
||||
|
||||
enum SortOrder {
|
||||
NameAsc = "NameAsc",
|
||||
|
@ -206,108 +206,34 @@ export class DatabaseUI extends DisposableObject {
|
|||
);
|
||||
}
|
||||
|
||||
init() {
|
||||
void extLogger.log("Registering database panel commands.");
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQL.setCurrentDatabase",
|
||||
this.handleSetCurrentDatabase.bind(this),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQL.setDefaultTourDatabase",
|
||||
public getCommands(): LocalDatabasesCommands {
|
||||
return {
|
||||
"codeQL.setCurrentDatabase": this.handleSetCurrentDatabase.bind(this),
|
||||
"codeQL.setDefaultTourDatabase":
|
||||
this.handleSetDefaultTourDatabase.bind(this),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQL.upgradeCurrentDatabase",
|
||||
"codeQL.upgradeCurrentDatabase":
|
||||
this.handleUpgradeCurrentDatabase.bind(this),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner("codeQL.clearCache", this.handleClearCache.bind(this)),
|
||||
);
|
||||
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLDatabases.chooseDatabaseFolder",
|
||||
"codeQL.clearCache": this.handleClearCache.bind(this),
|
||||
"codeQLDatabases.chooseDatabaseFolder":
|
||||
this.handleChooseDatabaseFolder.bind(this),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLDatabases.chooseDatabaseArchive",
|
||||
"codeQLDatabases.chooseDatabaseArchive":
|
||||
this.handleChooseDatabaseArchive.bind(this),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLDatabases.chooseDatabaseInternet",
|
||||
"codeQLDatabases.chooseDatabaseInternet":
|
||||
this.handleChooseDatabaseInternet.bind(this),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner("codeQLDatabases.chooseDatabaseGithub", async () => {
|
||||
const credentials = isCanary() ? this.app.credentials : undefined;
|
||||
await this.handleChooseDatabaseGithub(credentials);
|
||||
}),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLDatabases.setCurrentDatabase",
|
||||
"codeQLDatabases.chooseDatabaseGithub":
|
||||
this.handleChooseDatabaseGithub.bind(this),
|
||||
"codeQLDatabases.setCurrentDatabase":
|
||||
this.handleMakeCurrentDatabase.bind(this),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLDatabases.sortByName",
|
||||
this.handleSortByName.bind(this),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLDatabases.sortByDateAdded",
|
||||
this.handleSortByDateAdded.bind(this),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLDatabases.removeDatabase",
|
||||
this.handleRemoveDatabase.bind(this),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLDatabases.upgradeDatabase",
|
||||
this.handleUpgradeDatabase.bind(this),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLDatabases.renameDatabase",
|
||||
this.handleRenameDatabase.bind(this),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLDatabases.openDatabaseFolder",
|
||||
this.handleOpenFolder.bind(this),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLDatabases.addDatabaseSource",
|
||||
this.handleAddSource.bind(this),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLDatabases.removeOrphanedDatabases",
|
||||
"codeQLDatabases.sortByName": this.handleSortByName.bind(this),
|
||||
"codeQLDatabases.sortByDateAdded": this.handleSortByDateAdded.bind(this),
|
||||
"codeQLDatabases.removeDatabase": this.handleRemoveDatabase.bind(this),
|
||||
"codeQLDatabases.upgradeDatabase": this.handleUpgradeDatabase.bind(this),
|
||||
"codeQLDatabases.renameDatabase": this.handleRenameDatabase.bind(this),
|
||||
"codeQLDatabases.openDatabaseFolder": this.handleOpenFolder.bind(this),
|
||||
"codeQLDatabases.addDatabaseSource": this.handleAddSource.bind(this),
|
||||
"codeQLDatabases.removeOrphanedDatabases":
|
||||
this.handleRemoveOrphanedDatabases.bind(this),
|
||||
),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
private async handleMakeCurrentDatabase(
|
||||
|
@ -505,12 +431,10 @@ export class DatabaseUI extends DisposableObject {
|
|||
);
|
||||
}
|
||||
|
||||
private async handleChooseDatabaseInternet(): Promise<
|
||||
DatabaseItem | undefined
|
||||
> {
|
||||
private async handleChooseDatabaseInternet(): Promise<void> {
|
||||
return withProgress(
|
||||
async (progress, token) => {
|
||||
return await this.chooseDatabaseInternet(progress, token);
|
||||
await this.chooseDatabaseInternet(progress, token);
|
||||
},
|
||||
{
|
||||
title: "Adding database from URL",
|
||||
|
@ -519,10 +443,11 @@ export class DatabaseUI extends DisposableObject {
|
|||
}
|
||||
|
||||
public async chooseDatabaseGithub(
|
||||
credentials: Credentials | undefined,
|
||||
progress: ProgressCallback,
|
||||
token: CancellationToken,
|
||||
): Promise<DatabaseItem | undefined> {
|
||||
const credentials = isCanary() ? this.app.credentials : undefined;
|
||||
|
||||
return await promptImportGithubDatabase(
|
||||
this.databaseManager,
|
||||
this.storagePath,
|
||||
|
@ -533,12 +458,10 @@ export class DatabaseUI extends DisposableObject {
|
|||
);
|
||||
}
|
||||
|
||||
private async handleChooseDatabaseGithub(
|
||||
credentials: Credentials | undefined,
|
||||
): Promise<DatabaseItem | undefined> {
|
||||
private async handleChooseDatabaseGithub(): Promise<void> {
|
||||
return withProgress(
|
||||
async (progress, token) => {
|
||||
return await this.chooseDatabaseGithub(credentials, progress, token);
|
||||
await this.chooseDatabaseGithub(progress, token);
|
||||
},
|
||||
{
|
||||
title: "Adding database from GitHub",
|
||||
|
|
Загрузка…
Ссылка в новой задаче