Skip to content

Commit f7b6d4c

Browse files
authored
Merge pull request #2189 from github/koesie10/typed-local-database-ui-commands
Convert local database commands to typed commands
2 parents 3c229d2 + 58bffe1 commit f7b6d4c

File tree

3 files changed

+297
-302
lines changed

3 files changed

+297
-302
lines changed

extensions/ql-vscode/src/common/commands.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { CommandManager } from "../packages/commands";
22
import type { Uri } from "vscode";
33
import type { DbTreeViewItem } from "../databases/ui/db-tree-view-item";
4+
import type { DatabaseItem } from "../local-databases";
45
import type { QueryHistoryInfo } from "../query-history/query-history-info";
56

67
// A command function matching the signature that VS Code calls when
@@ -60,6 +61,31 @@ export type QueryHistoryCommands = {
6061
"codeQLQueryHistory.copyRepoList": SelectionCommandFunction<QueryHistoryInfo>;
6162
};
6263

64+
// Commands used for the local databases panel
65+
export type LocalDatabasesCommands = {
66+
"codeQL.setCurrentDatabase": (uri: Uri) => Promise<void>;
67+
"codeQL.setDefaultTourDatabase": () => Promise<void>;
68+
"codeQL.upgradeCurrentDatabase": () => Promise<void>;
69+
"codeQL.clearCache": () => Promise<void>;
70+
71+
"codeQLDatabases.chooseDatabaseFolder": () => Promise<void>;
72+
"codeQLDatabases.chooseDatabaseArchive": () => Promise<void>;
73+
"codeQLDatabases.chooseDatabaseInternet": () => Promise<void>;
74+
"codeQLDatabases.chooseDatabaseGithub": () => Promise<void>;
75+
"codeQLDatabases.setCurrentDatabase": (
76+
databaseItem: DatabaseItem,
77+
) => Promise<void>;
78+
"codeQLDatabases.sortByName": () => Promise<void>;
79+
"codeQLDatabases.sortByDateAdded": () => Promise<void>;
80+
"codeQLDatabases.removeOrphanedDatabases": () => Promise<void>;
81+
82+
"codeQLDatabases.removeDatabase": SelectionCommandFunction<DatabaseItem>;
83+
"codeQLDatabases.upgradeDatabase": SelectionCommandFunction<DatabaseItem>;
84+
"codeQLDatabases.renameDatabase": SelectionCommandFunction<DatabaseItem>;
85+
"codeQLDatabases.openDatabaseFolder": SelectionCommandFunction<DatabaseItem>;
86+
"codeQLDatabases.addDatabaseSource": SelectionCommandFunction<DatabaseItem>;
87+
};
88+
6389
// Commands tied to variant analysis
6490
export type VariantAnalysisCommands = {
6591
"codeQL.openVariantAnalysisLogs": (
@@ -84,6 +110,7 @@ export type DatabasePanelCommands = {
84110

85111
export type AllCommands = BaseCommands &
86112
QueryHistoryCommands &
113+
LocalDatabasesCommands &
87114
VariantAnalysisCommands &
88115
DatabasePanelCommands;
89116

extensions/ql-vscode/src/extension.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import { CodeQLCliServer } from "./cli";
3535
import {
3636
CliConfigListener,
3737
DistributionConfigListener,
38-
isCanary,
3938
joinOrderWarningThreshold,
4039
MAX_QUERIES,
4140
QueryHistoryConfigListener,
@@ -639,7 +638,6 @@ async function activateWithInstalledDistribution(
639638
getContextStoragePath(ctx),
640639
ctx.extensionPath,
641640
);
642-
databaseUI.init();
643641
ctx.subscriptions.push(databaseUI);
644642

645643
void extLogger.log("Initializing evaluator log viewer.");
@@ -1093,6 +1091,7 @@ async function activateWithInstalledDistribution(
10931091
...getCommands(),
10941092
...qhm.getCommands(),
10951093
...variantAnalysisManager.getCommands(),
1094+
...databaseUI.getCommands(),
10961095
...dbModule.getCommands(),
10971096
};
10981097

@@ -1225,7 +1224,7 @@ async function activateWithInstalledDistribution(
12251224
commandRunnerWithProgress(
12261225
"codeQL.chooseDatabaseFolder",
12271226
(progress: ProgressCallback, token: CancellationToken) =>
1228-
databaseUI.handleChooseDatabaseFolder(progress, token),
1227+
databaseUI.chooseDatabaseFolder(progress, token),
12291228
{
12301229
title: "Choose a Database from a Folder",
12311230
},
@@ -1235,7 +1234,7 @@ async function activateWithInstalledDistribution(
12351234
commandRunnerWithProgress(
12361235
"codeQL.chooseDatabaseArchive",
12371236
(progress: ProgressCallback, token: CancellationToken) =>
1238-
databaseUI.handleChooseDatabaseArchive(progress, token),
1237+
databaseUI.chooseDatabaseArchive(progress, token),
12391238
{
12401239
title: "Choose a Database from an Archive",
12411240
},
@@ -1245,12 +1244,7 @@ async function activateWithInstalledDistribution(
12451244
commandRunnerWithProgress(
12461245
"codeQL.chooseDatabaseGithub",
12471246
async (progress: ProgressCallback, token: CancellationToken) => {
1248-
const credentials = isCanary() ? app.credentials : undefined;
1249-
await databaseUI.handleChooseDatabaseGithub(
1250-
credentials,
1251-
progress,
1252-
token,
1253-
);
1247+
await databaseUI.chooseDatabaseGithub(progress, token);
12541248
},
12551249
{
12561250
title: "Adding database from GitHub",
@@ -1261,7 +1255,7 @@ async function activateWithInstalledDistribution(
12611255
commandRunnerWithProgress(
12621256
"codeQL.chooseDatabaseInternet",
12631257
(progress: ProgressCallback, token: CancellationToken) =>
1264-
databaseUI.handleChooseDatabaseInternet(progress, token),
1258+
databaseUI.chooseDatabaseInternet(progress, token),
12651259

12661260
{
12671261
title: "Adding database from URL",

0 commit comments

Comments
 (0)