@@ -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
@@ -220,6 +221,15 @@ export class DatabaseUI extends DisposableObject {
220221 } ,
221222 ) ,
222223 ) ;
224+ this . push (
225+ commandRunnerWithProgress (
226+ "codeQL.setDefaultTourDatabase" ,
227+ this . handleSetDefaultTourDatabase ,
228+ {
229+ title : "Set Default Database for Codespace CodeQL Tour" ,
230+ } ,
231+ ) ,
232+ ) ;
223233 this . push (
224234 commandRunnerWithProgress (
225235 "codeQL.upgradeCurrentDatabase" ,
@@ -354,6 +364,40 @@ export class DatabaseUI extends DisposableObject {
354364 }
355365 } ;
356366
367+ private handleSetDefaultTourDatabase = async (
368+ progress : ProgressCallback ,
369+ token : CancellationToken ,
370+ ) : Promise < void > => {
371+ try {
372+ if ( ! workspace . workspaceFolders ?. length ) {
373+ throw new Error ( "No workspace folder is open." ) ;
374+ } else {
375+ // This specifically refers to the database folder in
376+ // https://github.com/github/codespaces-codeql
377+ const uri = Uri . parse (
378+ `${ workspace . workspaceFolders [ 0 ] . uri } /codeql-tutorial-database` ,
379+ ) ;
380+
381+ let databaseItem = this . databaseManager . findDatabaseItem ( uri ) ;
382+ if ( databaseItem === undefined ) {
383+ databaseItem = await this . databaseManager . openDatabase (
384+ progress ,
385+ token ,
386+ uri ,
387+ ) ;
388+ }
389+ await this . databaseManager . setCurrentDatabaseItem ( databaseItem ) ;
390+ }
391+ } catch ( e ) {
392+ // rethrow and let this be handled by default error handling.
393+ throw new Error (
394+ `Could not set the database for the Code Tour. Please make sure you are using the default workspace in your codespace: ${ getErrorMessage (
395+ e ,
396+ ) } `,
397+ ) ;
398+ }
399+ } ;
400+
357401 handleRemoveOrphanedDatabases = async ( ) : Promise < void > => {
358402 void extLogger . log ( "Removing orphaned databases from workspace storage." ) ;
359403 let dbDirs = undefined ;
0 commit comments