1- import { join } from "path" ;
1+ import { join , dirname } from "path" ;
22import { CancellationToken , Uri , workspace , window as Window } from "vscode" ;
33import { CodeQLCliServer } from "./cli" ;
44import { OutputChannelLogger } from "./common" ;
@@ -27,7 +27,7 @@ export const QUERY_LANGUAGE_TO_DATABASE_REPO: QueryLanguagesToDatabaseMap = {
2727export class SkeletonQueryWizard {
2828 private language : string | undefined ;
2929 private fileName = "example.ql" ;
30- private storagePath : string | undefined ;
30+ private qlPackStoragePath : string | undefined ;
3131
3232 constructor (
3333 private readonly cliServer : CodeQLCliServer ,
@@ -36,6 +36,7 @@ export class SkeletonQueryWizard {
3636 private readonly extLogger : OutputChannelLogger ,
3737 private readonly databaseManager : DatabaseManager ,
3838 private readonly token : CancellationToken ,
39+ private readonly databaseStoragePath : string | undefined ,
3940 ) { }
4041
4142 private get folderName ( ) {
@@ -49,7 +50,7 @@ export class SkeletonQueryWizard {
4950 return ;
5051 }
5152
52- this . storagePath = this . getFirstStoragePath ( ) ;
53+ this . qlPackStoragePath = this . getFirstStoragePath ( ) ;
5354
5455 const skeletonPackAlreadyExists = isFolderAlreadyInWorkspace (
5556 this . folderName ,
@@ -72,12 +73,12 @@ export class SkeletonQueryWizard {
7273 }
7374
7475 private async openExampleFile ( ) {
75- if ( this . folderName === undefined || this . storagePath === undefined ) {
76+ if ( this . folderName === undefined || this . qlPackStoragePath === undefined ) {
7677 throw new Error ( "Path to folder is undefined" ) ;
7778 }
7879
7980 const queryFileUri = Uri . file (
80- join ( this . storagePath , this . folderName , this . fileName ) ,
81+ join ( this . qlPackStoragePath , this . folderName , this . fileName ) ,
8182 ) ;
8283
8384 try {
@@ -99,15 +100,16 @@ export class SkeletonQueryWizard {
99100 }
100101
101102 const firstFolder = workspaceFolders [ 0 ] ;
103+ const firstFolderFsPath = firstFolder . uri . fsPath ;
102104
103105 // For the vscode-codeql-starter repo, the first folder will be a ql pack
104106 // so we need to get the parent folder
105- if ( firstFolder . uri . path . includes ( "codeql-custom-queries" ) ) {
106- // slice off the last part of the path and return the parent folder
107- return firstFolder . uri . path . split ( "/" ) . slice ( 0 , - 1 ) . join ( "/" ) ;
107+ if ( firstFolderFsPath . includes ( "codeql-custom-queries" ) ) {
108+ // return the parent folder
109+ return dirname ( firstFolderFsPath ) ;
108110 } else {
109111 // if the first folder is not a ql pack, then we are in a normal workspace
110- return firstFolder . uri . path ;
112+ return firstFolderFsPath ;
111113 }
112114 }
113115
@@ -137,7 +139,7 @@ export class SkeletonQueryWizard {
137139 this . folderName ,
138140 this . language as QueryLanguage ,
139141 this . cliServer ,
140- this . storagePath ,
142+ this . qlPackStoragePath ,
141143 ) ;
142144
143145 await qlPackGenerator . generate ( ) ;
@@ -165,7 +167,7 @@ export class SkeletonQueryWizard {
165167 this . folderName ,
166168 this . language as QueryLanguage ,
167169 this . cliServer ,
168- this . storagePath ,
170+ this . qlPackStoragePath ,
169171 ) ;
170172
171173 this . fileName = await this . determineNextFileName ( this . folderName ) ;
@@ -178,11 +180,11 @@ export class SkeletonQueryWizard {
178180 }
179181
180182 private async determineNextFileName ( folderName : string ) : Promise < string > {
181- if ( this . storagePath === undefined ) {
183+ if ( this . qlPackStoragePath === undefined ) {
182184 throw new Error ( "Workspace storage path is undefined" ) ;
183185 }
184186
185- const folderUri = Uri . file ( join ( this . storagePath , folderName ) ) ;
187+ const folderUri = Uri . file ( join ( this . qlPackStoragePath , folderName ) ) ;
186188 const files = await workspace . fs . readDirectory ( folderUri ) ;
187189 const qlFiles = files . filter ( ( [ filename , _fileType ] ) =>
188190 filename . match ( / e x a m p l e [ 0 - 9 ] * .q l / ) ,
@@ -192,10 +194,14 @@ export class SkeletonQueryWizard {
192194 }
193195
194196 private async downloadDatabase ( ) {
195- if ( this . storagePath === undefined ) {
197+ if ( this . qlPackStoragePath === undefined ) {
196198 throw new Error ( "Workspace storage path is undefined" ) ;
197199 }
198200
201+ if ( this . databaseStoragePath === undefined ) {
202+ throw new Error ( "Database storage path is undefined" ) ;
203+ }
204+
199205 if ( this . language === undefined ) {
200206 throw new Error ( "Language is undefined" ) ;
201207 }
@@ -219,7 +225,7 @@ export class SkeletonQueryWizard {
219225 await databaseFetcher . downloadGitHubDatabase (
220226 chosenRepo ,
221227 this . databaseManager ,
222- this . storagePath ,
228+ this . databaseStoragePath ,
223229 this . credentials ,
224230 this . progress ,
225231 this . token ,
@@ -233,7 +239,7 @@ export class SkeletonQueryWizard {
233239 throw new Error ( "Language is undefined" ) ;
234240 }
235241
236- if ( this . storagePath === undefined ) {
242+ if ( this . qlPackStoragePath === undefined ) {
237243 throw new Error ( "Workspace storage path is undefined" ) ;
238244 }
239245
0 commit comments