Skip to content

Commit 8c0d0d8

Browse files
Merge pull request #2305 from github/elena/yer-a-progress-query
Small fixes to skeleton query wizard
2 parents 03adb70 + 3627139 commit 8c0d0d8

File tree

4 files changed

+28
-26
lines changed

4 files changed

+28
-26
lines changed

extensions/ql-vscode/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362
"title": "CodeQL: Quick Query"
363363
},
364364
{
365-
"command": "codeQL.createSkeletonQuery",
365+
"command": "codeQL.createQuery",
366366
"title": "CodeQL: Create Query"
367367
},
368368
{
@@ -1321,6 +1321,10 @@
13211321
{
13221322
"command": "codeQL.mockGitHubApiServer.unloadScenario",
13231323
"when": "config.codeQL.mockGitHubApiServer.enabled && codeQL.mockGitHubApiServer.scenarioLoaded"
1324+
},
1325+
{
1326+
"command": "codeQL.createQuery",
1327+
"when": "config.codeQL.canary"
13241328
}
13251329
],
13261330
"editor/context": [

extensions/ql-vscode/src/common/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export type LocalQueryCommands = {
9999
"codeQL.quickEvalContextEditor": (uri: Uri) => Promise<void>;
100100
"codeQL.codeLensQuickEval": (uri: Uri, range: Range) => Promise<void>;
101101
"codeQL.quickQuery": () => Promise<void>;
102-
"codeQL.createSkeletonQuery": () => Promise<void>;
102+
"codeQL.createQuery": () => Promise<void>;
103103
};
104104

105105
export type ResultsViewCommands = {

extensions/ql-vscode/src/local-queries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export class LocalQueries extends DisposableObject {
238238
"codeQL.quickEvalContextEditor": this.quickEval.bind(this),
239239
"codeQL.codeLensQuickEval": this.codeLensQuickEval.bind(this),
240240
"codeQL.quickQuery": this.quickQuery.bind(this),
241-
"codeQL.createSkeletonQuery": this.createSkeletonQuery.bind(this),
241+
"codeQL.createQuery": this.createSkeletonQuery.bind(this),
242242
};
243243
}
244244

extensions/ql-vscode/src/skeleton-query-wizard.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { askForLanguage, isFolderAlreadyInWorkspace } from "./helpers";
88
import { getErrorMessage } from "./pure/helpers-pure";
99
import { QlPackGenerator } from "./qlpack-generator";
1010
import { DatabaseItem, DatabaseManager } from "./local-databases";
11-
import * as databaseFetcher from "./databaseFetcher";
1211
import { ProgressCallback, UserCancellationException } from "./progress";
12+
import { askForGitHubRepo, downloadGitHubDatabase } from "./databaseFetcher";
1313

1414
type QueryLanguagesToDatabaseMap = Record<string, string>;
1515

@@ -69,7 +69,14 @@ export class SkeletonQueryWizard {
6969
}
7070

7171
// open a query file
72-
await this.openExampleFile();
72+
73+
try {
74+
await this.openExampleFile();
75+
} catch (e: unknown) {
76+
void this.extLogger.log(
77+
`Could not open example query file: ${getErrorMessage(e)}`,
78+
);
79+
}
7380
}
7481

7582
private async openExampleFile() {
@@ -81,15 +88,9 @@ export class SkeletonQueryWizard {
8188
join(this.qlPackStoragePath, this.folderName, this.fileName),
8289
);
8390

84-
try {
85-
void workspace.openTextDocument(queryFileUri).then((doc) => {
86-
void Window.showTextDocument(doc);
87-
});
88-
} catch (e: unknown) {
89-
void this.extLogger.log(
90-
`Could not open example query file: ${getErrorMessage(e)}`,
91-
);
92-
}
91+
void workspace.openTextDocument(queryFileUri).then((doc) => {
92+
void Window.showTextDocument(doc);
93+
});
9394
}
9495

9596
public getFirstStoragePath() {
@@ -117,7 +118,7 @@ export class SkeletonQueryWizard {
117118
this.progress({
118119
message: "Choose language",
119120
step: 1,
120-
maxStep: 1,
121+
maxStep: 3,
121122
});
122123

123124
return await askForLanguage(this.cliServer, false);
@@ -131,7 +132,7 @@ export class SkeletonQueryWizard {
131132
this.progress({
132133
message: "Creating skeleton QL pack around query",
133134
step: 2,
134-
maxStep: 2,
135+
maxStep: 3,
135136
});
136137

137138
try {
@@ -159,7 +160,7 @@ export class SkeletonQueryWizard {
159160
message:
160161
"Skeleton query pack already exists. Creating additional query example file.",
161162
step: 2,
162-
maxStep: 2,
163+
maxStep: 3,
163164
});
164165

165166
try {
@@ -181,21 +182,21 @@ export class SkeletonQueryWizard {
181182

182183
private async determineNextFileName(folderName: string): Promise<string> {
183184
if (this.qlPackStoragePath === undefined) {
184-
throw new Error("Workspace storage path is undefined");
185+
throw new Error("QL Pack storage path is undefined");
185186
}
186187

187188
const folderUri = Uri.file(join(this.qlPackStoragePath, folderName));
188189
const files = await workspace.fs.readDirectory(folderUri);
189190
const qlFiles = files.filter(([filename, _fileType]) =>
190-
filename.match(/example[0-9]*.ql/),
191+
filename.match(/^example[0-9]*\.ql$/),
191192
);
192193

193194
return `example${qlFiles.length + 1}.ql`;
194195
}
195196

196197
private async downloadDatabase() {
197198
if (this.qlPackStoragePath === undefined) {
198-
throw new Error("Workspace storage path is undefined");
199+
throw new Error("QL Pack storage path is undefined");
199200
}
200201

201202
if (this.databaseStoragePath === undefined) {
@@ -213,16 +214,13 @@ export class SkeletonQueryWizard {
213214
});
214215

215216
const githubRepoNwo = QUERY_LANGUAGE_TO_DATABASE_REPO[this.language];
216-
const chosenRepo = await databaseFetcher.askForGitHubRepo(
217-
undefined,
218-
githubRepoNwo,
219-
);
217+
const chosenRepo = await askForGitHubRepo(undefined, githubRepoNwo);
220218

221219
if (!chosenRepo) {
222220
throw new UserCancellationException("No GitHub repository provided");
223221
}
224222

225-
await databaseFetcher.downloadGitHubDatabase(
223+
await downloadGitHubDatabase(
226224
chosenRepo,
227225
this.databaseManager,
228226
this.databaseStoragePath,
@@ -240,7 +238,7 @@ export class SkeletonQueryWizard {
240238
}
241239

242240
if (this.qlPackStoragePath === undefined) {
243-
throw new Error("Workspace storage path is undefined");
241+
throw new Error("QL Pack storage path is undefined");
244242
}
245243

246244
const databaseNwo = QUERY_LANGUAGE_TO_DATABASE_REPO[this.language];

0 commit comments

Comments
 (0)