Skip to content

Commit d3192b7

Browse files
shati-patelaeisenberg
authored andcommitted
New command to add database source folder to workspace
1 parent e7ab296 commit d3192b7

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

extensions/ql-vscode/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@
345345
"command": "codeQLDatabases.openDatabaseFolder",
346346
"title": "Show Database Directory"
347347
},
348+
{
349+
"command": "codeQLDatabases.addDatabaseSource",
350+
"title": "Add Database Source to Workspace"
351+
},
348352
{
349353
"command": "codeQL.chooseDatabaseFolder",
350354
"title": "CodeQL: Choose Database from Folder"
@@ -584,6 +588,11 @@
584588
"group": "9_qlCommands",
585589
"when": "view == codeQLDatabases"
586590
},
591+
{
592+
"command": "codeQLDatabases.addDatabaseSource",
593+
"group": "9_qlCommands",
594+
"when": "view == codeQLDatabases"
595+
},
587596
{
588597
"command": "codeQLQueryHistory.openQuery",
589598
"group": "9_qlCommands",
@@ -707,6 +716,10 @@
707716
"command": "codeQLDatabases.openDatabaseFolder",
708717
"when": "false"
709718
},
719+
{
720+
"command": "codeQLDatabases.addDatabaseSource",
721+
"when": "false"
722+
},
710723
{
711724
"command": "codeQLDatabases.sortByName",
712725
"when": "false"

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ export class DatabaseUI extends DisposableObject {
348348
this.handleOpenFolder
349349
)
350350
);
351+
this.push(
352+
commandRunner(
353+
'codeQLDatabases.addDatabaseSource',
354+
this.handleAddSource
355+
)
356+
);
351357
this.push(
352358
commandRunner(
353359
'codeQLDatabases.removeOrphanedDatabases',
@@ -632,6 +638,25 @@ export class DatabaseUI extends DisposableObject {
632638
}
633639
};
634640

641+
/**
642+
* Adds the source folder of a CodeQL database to the workspace.
643+
* When a database is first added in the "Databases" view, its source folder is added to the workspace.
644+
* If the source folder is removed from the workspace for some reason, we want to be able to re-add it if need be.
645+
*/
646+
private handleAddSource = async (
647+
databaseItem: DatabaseItem,
648+
multiSelect: DatabaseItem[] | undefined
649+
): Promise<void> => {
650+
if (multiSelect?.length) {
651+
// TODO: This multiselect part doesn't work yet. Only the first databases is re-added.
652+
await Promise.all(
653+
multiSelect.map((dbItem) => this.databaseManager.addDatabaseSourceArchiveFolder(dbItem))
654+
);
655+
} else {
656+
await this.databaseManager.addDatabaseSourceArchiveFolder(databaseItem);
657+
}
658+
};
659+
635660
/**
636661
* Return the current database directory. If we don't already have a
637662
* current database, ask the user for one, and return that, or

extensions/ql-vscode/src/databases.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ export class DatabaseManager extends DisposableObject {
587587
}));
588588
}
589589

590-
private async addDatabaseSourceArchiveFolder(item: DatabaseItem) {
590+
public async addDatabaseSourceArchiveFolder(item: DatabaseItem) {
591591
// The folder may already be in workspace state from a previous
592592
// session. If not, add it.
593593
const index = this.getDatabaseWorkspaceFolderIndex(item);

0 commit comments

Comments
 (0)