|
1 | | -import { join, dirname } from "path"; |
| 1 | +import { join } from "path"; |
2 | 2 | import { CancellationToken, Uri, workspace, window as Window } from "vscode"; |
3 | 3 | import { CodeQLCliServer } from "./cli"; |
4 | 4 | import { OutputChannelLogger } from "./common"; |
5 | 5 | import { Credentials } from "./common/authentication"; |
6 | 6 | import { QueryLanguage } from "./common/query-language"; |
7 | | -import { askForLanguage, isFolderAlreadyInWorkspace } from "./helpers"; |
| 7 | +import { |
| 8 | + askForLanguage, |
| 9 | + getFirstWorkspaceFolder, |
| 10 | + isFolderAlreadyInWorkspace, |
| 11 | +} from "./helpers"; |
8 | 12 | import { getErrorMessage } from "./pure/helpers-pure"; |
9 | 13 | import { QlPackGenerator } from "./qlpack-generator"; |
10 | 14 | import { DatabaseItem, DatabaseManager } from "./local-databases"; |
11 | 15 | import { ProgressCallback, UserCancellationException } from "./progress"; |
12 | 16 | import { askForGitHubRepo, downloadGitHubDatabase } from "./databaseFetcher"; |
| 17 | +import { existsSync } from "fs"; |
13 | 18 |
|
14 | 19 | type QueryLanguagesToDatabaseMap = Record<string, string>; |
15 | 20 |
|
@@ -50,11 +55,11 @@ export class SkeletonQueryWizard { |
50 | 55 | return; |
51 | 56 | } |
52 | 57 |
|
53 | | - this.qlPackStoragePath = this.getFirstStoragePath(); |
| 58 | + this.qlPackStoragePath = getFirstWorkspaceFolder(); |
54 | 59 |
|
55 | | - const skeletonPackAlreadyExists = isFolderAlreadyInWorkspace( |
56 | | - this.folderName, |
57 | | - ); |
| 60 | + const skeletonPackAlreadyExists = |
| 61 | + existsSync(join(this.qlPackStoragePath, this.folderName)) || |
| 62 | + isFolderAlreadyInWorkspace(this.folderName); |
58 | 63 |
|
59 | 64 | if (skeletonPackAlreadyExists) { |
60 | 65 | // just create a new example query file in skeleton QL pack |
@@ -93,27 +98,6 @@ export class SkeletonQueryWizard { |
93 | 98 | }); |
94 | 99 | } |
95 | 100 |
|
96 | | - public getFirstStoragePath() { |
97 | | - const workspaceFolders = workspace.workspaceFolders; |
98 | | - |
99 | | - if (!workspaceFolders || workspaceFolders.length === 0) { |
100 | | - throw new Error("No workspace folders found"); |
101 | | - } |
102 | | - |
103 | | - const firstFolder = workspaceFolders[0]; |
104 | | - const firstFolderFsPath = firstFolder.uri.fsPath; |
105 | | - |
106 | | - // For the vscode-codeql-starter repo, the first folder will be a ql pack |
107 | | - // so we need to get the parent folder |
108 | | - if (firstFolderFsPath.includes("codeql-custom-queries")) { |
109 | | - // return the parent folder |
110 | | - return dirname(firstFolderFsPath); |
111 | | - } else { |
112 | | - // if the first folder is not a ql pack, then we are in a normal workspace |
113 | | - return firstFolderFsPath; |
114 | | - } |
115 | | - } |
116 | | - |
117 | 101 | private async chooseLanguage() { |
118 | 102 | this.progress({ |
119 | 103 | message: "Choose language", |
|
0 commit comments