File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed
Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 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"
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" ,
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"
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments