@@ -12,6 +12,7 @@ import {
1212 CancellationToken ,
1313 ThemeIcon ,
1414 ThemeColor ,
15+ workspace ,
1516} from "vscode" ;
1617import { pathExists , stat , readdir , remove } from "fs-extra" ;
1718
@@ -218,6 +219,15 @@ export class DatabaseUI extends DisposableObject {
218219 } ,
219220 ) ,
220221 ) ;
222+ this . push (
223+ commandRunnerWithProgress (
224+ "codeQL.setDefaultTourDatabase" ,
225+ this . handleSetDefaultTourDatabase ,
226+ {
227+ title : "Set Default Database for Codespace CodeQL Tour" ,
228+ } ,
229+ ) ,
230+ ) ;
221231 this . push (
222232 commandRunnerWithProgress (
223233 "codeQL.upgradeCurrentDatabase" ,
@@ -348,6 +358,40 @@ export class DatabaseUI extends DisposableObject {
348358 }
349359 } ;
350360
361+ private handleSetDefaultTourDatabase = async (
362+ progress : ProgressCallback ,
363+ token : CancellationToken ,
364+ ) : Promise < void > => {
365+ try {
366+ if ( ! workspace . workspaceFolders ?. length ) {
367+ throw new Error ( "No workspace folder is open." ) ;
368+ } else {
369+ // This specifically refers to the database folder in
370+ // https://github.com/github/codespaces-codeql
371+ const uri = Uri . parse (
372+ `${ workspace . workspaceFolders [ 0 ] . uri } /codeql-tutorial-database` ,
373+ ) ;
374+
375+ let databaseItem = this . databaseManager . findDatabaseItem ( uri ) ;
376+ if ( databaseItem === undefined ) {
377+ databaseItem = await this . databaseManager . openDatabase (
378+ progress ,
379+ token ,
380+ uri ,
381+ ) ;
382+ }
383+ await this . databaseManager . setCurrentDatabaseItem ( databaseItem ) ;
384+ }
385+ } catch ( e ) {
386+ // rethrow and let this be handled by default error handling.
387+ throw new Error (
388+ `Could not set the database for the Code Tour. Please make sure you are using the default workspace in your codespace: ${ getErrorMessage (
389+ e ,
390+ ) } `,
391+ ) ;
392+ }
393+ } ;
394+
351395 handleRemoveOrphanedDatabases = async ( ) : Promise < void > => {
352396 void extLogger . log ( "Removing orphaned databases from workspace storage." ) ;
353397 let dbDirs = undefined ;
0 commit comments