Skip to content

Commit 56c83eb

Browse files
authored
Merge pull request #2195 from github/koesie10/move-database-commands
Move remaining local database commands to databases UI
2 parents 76558b8 + eb5659a commit 56c83eb

File tree

3 files changed

+65
-78
lines changed

3 files changed

+65
-78
lines changed

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,42 @@ export type QueryHistoryCommands = {
7878

7979
// Commands used for the local databases panel
8080
export type LocalDatabasesCommands = {
81-
"codeQL.setCurrentDatabase": (uri: Uri) => Promise<void>;
82-
"codeQL.setDefaultTourDatabase": () => Promise<void>;
81+
// Command palette commands
82+
"codeQL.chooseDatabaseFolder": () => Promise<void>;
83+
"codeQL.chooseDatabaseArchive": () => Promise<void>;
84+
"codeQL.chooseDatabaseInternet": () => Promise<void>;
85+
"codeQL.chooseDatabaseGithub": () => Promise<void>;
8386
"codeQL.upgradeCurrentDatabase": () => Promise<void>;
8487
"codeQL.clearCache": () => Promise<void>;
8588

89+
// Explorer context menu
90+
"codeQL.setCurrentDatabase": (uri: Uri) => Promise<void>;
91+
92+
// Database panel view title commands
8693
"codeQLDatabases.chooseDatabaseFolder": () => Promise<void>;
8794
"codeQLDatabases.chooseDatabaseArchive": () => Promise<void>;
8895
"codeQLDatabases.chooseDatabaseInternet": () => Promise<void>;
8996
"codeQLDatabases.chooseDatabaseGithub": () => Promise<void>;
97+
"codeQLDatabases.sortByName": () => Promise<void>;
98+
"codeQLDatabases.sortByDateAdded": () => Promise<void>;
99+
100+
// Database panel context menu
90101
"codeQLDatabases.setCurrentDatabase": (
91102
databaseItem: DatabaseItem,
92103
) => Promise<void>;
93-
"codeQLDatabases.sortByName": () => Promise<void>;
94-
"codeQLDatabases.sortByDateAdded": () => Promise<void>;
95-
"codeQLDatabases.removeOrphanedDatabases": () => Promise<void>;
96104

105+
// Database panel selection commands
97106
"codeQLDatabases.removeDatabase": SelectionCommandFunction<DatabaseItem>;
98107
"codeQLDatabases.upgradeDatabase": SelectionCommandFunction<DatabaseItem>;
99108
"codeQLDatabases.renameDatabase": SelectionCommandFunction<DatabaseItem>;
100109
"codeQLDatabases.openDatabaseFolder": SelectionCommandFunction<DatabaseItem>;
101110
"codeQLDatabases.addDatabaseSource": SelectionCommandFunction<DatabaseItem>;
111+
112+
// Codespace template commands
113+
"codeQL.setDefaultTourDatabase": () => Promise<void>;
114+
115+
// Internal commands
116+
"codeQLDatabases.removeOrphanedDatabases": () => Promise<void>;
102117
};
103118

104119
// Commands tied to variant analysis

extensions/ql-vscode/src/extension.ts

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -951,49 +951,6 @@ async function activateWithInstalledDistribution(
951951
),
952952
);
953953

954-
ctx.subscriptions.push(
955-
commandRunnerWithProgress(
956-
"codeQL.chooseDatabaseFolder",
957-
(progress: ProgressCallback, token: CancellationToken) =>
958-
databaseUI.chooseDatabaseFolder(progress, token),
959-
{
960-
title: "Choose a Database from a Folder",
961-
},
962-
),
963-
);
964-
ctx.subscriptions.push(
965-
commandRunnerWithProgress(
966-
"codeQL.chooseDatabaseArchive",
967-
(progress: ProgressCallback, token: CancellationToken) =>
968-
databaseUI.chooseDatabaseArchive(progress, token),
969-
{
970-
title: "Choose a Database from an Archive",
971-
},
972-
),
973-
);
974-
ctx.subscriptions.push(
975-
commandRunnerWithProgress(
976-
"codeQL.chooseDatabaseGithub",
977-
async (progress: ProgressCallback, token: CancellationToken) => {
978-
await databaseUI.chooseDatabaseGithub(progress, token);
979-
},
980-
{
981-
title: "Adding database from GitHub",
982-
},
983-
),
984-
);
985-
ctx.subscriptions.push(
986-
commandRunnerWithProgress(
987-
"codeQL.chooseDatabaseInternet",
988-
(progress: ProgressCallback, token: CancellationToken) =>
989-
databaseUI.chooseDatabaseInternet(progress, token),
990-
991-
{
992-
title: "Adding database from URL",
993-
},
994-
),
995-
);
996-
997954
ctx.subscriptions.push(
998955
commandRunner("codeQL.copyVersion", async () => {
999956
const text = `CodeQL extension version: ${

extensions/ql-vscode/src/local-databases-ui.ts

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,13 @@ export class DatabaseUI extends DisposableObject {
208208

209209
public getCommands(): LocalDatabasesCommands {
210210
return {
211+
"codeQL.chooseDatabaseFolder":
212+
this.handleChooseDatabaseFolderFromPalette.bind(this),
213+
"codeQL.chooseDatabaseArchive":
214+
this.handleChooseDatabaseArchiveFromPalette.bind(this),
215+
"codeQL.chooseDatabaseInternet":
216+
this.handleChooseDatabaseInternet.bind(this),
217+
"codeQL.chooseDatabaseGithub": this.handleChooseDatabaseGithub.bind(this),
211218
"codeQL.setCurrentDatabase": this.handleSetCurrentDatabase.bind(this),
212219
"codeQL.setDefaultTourDatabase":
213220
this.handleSetDefaultTourDatabase.bind(this),
@@ -242,7 +249,7 @@ export class DatabaseUI extends DisposableObject {
242249
await this.databaseManager.setCurrentDatabaseItem(databaseItem);
243250
}
244251

245-
public async chooseDatabaseFolder(
252+
private async chooseDatabaseFolder(
246253
progress: ProgressCallback,
247254
token: CancellationToken,
248255
): Promise<void> {
@@ -268,6 +275,17 @@ export class DatabaseUI extends DisposableObject {
268275
);
269276
}
270277

278+
private async handleChooseDatabaseFolderFromPalette(): Promise<void> {
279+
return withProgress(
280+
async (progress, token) => {
281+
await this.chooseDatabaseFolder(progress, token);
282+
},
283+
{
284+
title: "Choose a Database from a Folder",
285+
},
286+
);
287+
}
288+
271289
private async handleSetDefaultTourDatabase(): Promise<void> {
272290
return withProgress(
273291
async (progress, token) => {
@@ -392,7 +410,7 @@ export class DatabaseUI extends DisposableObject {
392410
}
393411
}
394412

395-
public async chooseDatabaseArchive(
413+
private async chooseDatabaseArchive(
396414
progress: ProgressCallback,
397415
token: CancellationToken,
398416
): Promise<void> {
@@ -418,50 +436,47 @@ export class DatabaseUI extends DisposableObject {
418436
);
419437
}
420438

421-
public async chooseDatabaseInternet(
422-
progress: ProgressCallback,
423-
token: CancellationToken,
424-
): Promise<DatabaseItem | undefined> {
425-
return await promptImportInternetDatabase(
426-
this.databaseManager,
427-
this.storagePath,
428-
progress,
429-
token,
430-
this.queryServer?.cliServer,
439+
private async handleChooseDatabaseArchiveFromPalette(): Promise<void> {
440+
return withProgress(
441+
async (progress, token) => {
442+
await this.chooseDatabaseArchive(progress, token);
443+
},
444+
{
445+
title: "Choose a Database from an Archive",
446+
},
431447
);
432448
}
433449

434450
private async handleChooseDatabaseInternet(): Promise<void> {
435451
return withProgress(
436452
async (progress, token) => {
437-
await this.chooseDatabaseInternet(progress, token);
453+
await promptImportInternetDatabase(
454+
this.databaseManager,
455+
this.storagePath,
456+
progress,
457+
token,
458+
this.queryServer?.cliServer,
459+
);
438460
},
439461
{
440462
title: "Adding database from URL",
441463
},
442464
);
443465
}
444466

445-
public async chooseDatabaseGithub(
446-
progress: ProgressCallback,
447-
token: CancellationToken,
448-
): Promise<DatabaseItem | undefined> {
449-
const credentials = isCanary() ? this.app.credentials : undefined;
450-
451-
return await promptImportGithubDatabase(
452-
this.databaseManager,
453-
this.storagePath,
454-
credentials,
455-
progress,
456-
token,
457-
this.queryServer?.cliServer,
458-
);
459-
}
460-
461467
private async handleChooseDatabaseGithub(): Promise<void> {
462468
return withProgress(
463469
async (progress, token) => {
464-
await this.chooseDatabaseGithub(progress, token);
470+
const credentials = isCanary() ? this.app.credentials : undefined;
471+
472+
await promptImportGithubDatabase(
473+
this.databaseManager,
474+
this.storagePath,
475+
credentials,
476+
progress,
477+
token,
478+
this.queryServer?.cliServer,
479+
);
465480
},
466481
{
467482
title: "Adding database from GitHub",

0 commit comments

Comments
 (0)