@@ -258,7 +258,7 @@ export interface DatabaseItem {
258258 * Returns the root uri of the virtual filesystem for this database's source archive,
259259 * as displayed in the filesystem explorer.
260260 */
261- getSourceArchiveExplorerUri ( ) : vscode . Uri | undefined ;
261+ getSourceArchiveExplorerUri ( ) : vscode . Uri ;
262262
263263 /**
264264 * Holds if `uri` belongs to this database's source archive.
@@ -274,6 +274,11 @@ export interface DatabaseItem {
274274 * Gets the state of this database, to be persisted in the workspace state.
275275 */
276276 getPersistedState ( ) : PersistedDatabaseItem ;
277+
278+ /**
279+ * Verifies that this database item has a zipped source folder. Returns an error message if it does not.
280+ */
281+ verifyZippedSources ( ) : string | undefined ;
277282}
278283
279284export enum DatabaseEventKind {
@@ -459,13 +464,26 @@ export class DatabaseItemImpl implements DatabaseItem {
459464 /**
460465 * Returns the root uri of the virtual filesystem for this database's source archive.
461466 */
462- public getSourceArchiveExplorerUri ( ) : vscode . Uri | undefined {
467+ public getSourceArchiveExplorerUri ( ) : vscode . Uri {
463468 const sourceArchive = this . sourceArchive ;
464- if ( sourceArchive === undefined || ! sourceArchive . fsPath . endsWith ( '.zip' ) )
465- return undefined ;
469+ if ( sourceArchive === undefined || ! sourceArchive . fsPath . endsWith ( '.zip' ) ) {
470+ throw new Error ( this . verifyZippedSources ( ) ) ;
471+ }
466472 return encodeArchiveBasePath ( sourceArchive . fsPath ) ;
467473 }
468474
475+ public verifyZippedSources ( ) : string | undefined {
476+ const sourceArchive = this . sourceArchive ;
477+ if ( sourceArchive === undefined ) {
478+ return `${ this . name } has no source archive.` ;
479+ }
480+
481+ if ( ! sourceArchive . fsPath . endsWith ( '.zip' ) ) {
482+ return `${ this . name } has a source folder that is unzipped.` ;
483+ }
484+ return ;
485+ }
486+
469487 /**
470488 * Holds if `uri` belongs to this database's source archive.
471489 */
@@ -603,26 +621,28 @@ export class DatabaseManager extends DisposableObject {
603621 // This is undesirable, as we might be adding and removing many
604622 // workspace folders as the user adds and removes databases.
605623 const end = ( vscode . workspace . workspaceFolders || [ ] ) . length ;
606- const uri = item . getSourceArchiveExplorerUri ( ) ;
607- if ( uri === undefined ) {
608- void logger . log ( `Couldn't obtain file explorer uri for ${ item . name } ` ) ;
624+
625+ const msg = item . verifyZippedSources ( ) ;
626+ if ( msg ) {
627+ void logger . log ( `Could not add source folder because ${ msg } ` ) ;
628+ return ;
609629 }
610- else {
611- void logger . log ( `Adding workspace folder for ${ item . name } source archive at index ${ end } ` ) ;
612- if ( ( vscode . workspace . workspaceFolders || [ ] ) . length < 2 ) {
613- // Adding this workspace folder makes the workspace
614- // multi-root, which may surprise the user. Let them know
615- // we're doing this.
616- void vscode . window . showInformationMessage ( `Adding workspace folder for source archive of database ${ item . name } .` ) ;
617- }
618- vscode . workspace . updateWorkspaceFolders ( end , 0 , {
619- name : `[${ item . name } source archive]` ,
620- uri,
621- } ) ;
622- // vscode api documentation says we must to wait for this event
623- // between multiple `updateWorkspaceFolders` calls.
624- await eventFired ( vscode . workspace . onDidChangeWorkspaceFolders ) ;
630+
631+ const uri = item . getSourceArchiveExplorerUri ( ) ;
632+ void logger . log ( `Adding workspace folder for ${ item . name } source archive at index ${ end } ` ) ;
633+ if ( ( vscode . workspace . workspaceFolders || [ ] ) . length < 2 ) {
634+ // Adding this workspace folder makes the workspace
635+ // multi-root, which may surprise the user. Let them know
636+ // we're doing this.
637+ void vscode . window . showInformationMessage ( `Adding workspace folder for source archive of database ${ item . name } .` ) ;
625638 }
639+ vscode . workspace . updateWorkspaceFolders ( end , 0 , {
640+ name : `[${ item . name } source archive]` ,
641+ uri,
642+ } ) ;
643+ // vscode api documentation says we must to wait for this event
644+ // between multiple `updateWorkspaceFolders` calls.
645+ await eventFired ( vscode . workspace . onDidChangeWorkspaceFolders ) ;
626646 }
627647 }
628648
@@ -732,7 +752,7 @@ export class DatabaseManager extends DisposableObject {
732752 this . updatePersistedCurrentDatabaseItem ( ) ;
733753
734754 await vscode . commands . executeCommand ( 'setContext' , 'codeQL.currentDatabaseItem' , item ?. name ) ;
735-
755+
736756 this . _onDidChangeCurrentDatabaseItem . fire ( {
737757 item,
738758 kind : DatabaseEventKind . Change
0 commit comments