Skip to content

Commit b47c561

Browse files
authored
Merge pull request #3044 from github/koesie10/fix-query-storage-path
Fix queries always being created in qlpack root
2 parents 2f39364 + 0bec013 commit b47c561

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

extensions/ql-vscode/src/databases/local-databases/database-manager.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,10 @@ export class DatabaseManager extends DisposableObject {
248248
const firstWorkspaceFolder = getFirstWorkspaceFolder();
249249
const folderName = `codeql-custom-queries-${databaseItem.language}`;
250250

251+
const qlpackStoragePath = join(firstWorkspaceFolder, folderName);
252+
251253
if (
252-
existsSync(join(firstWorkspaceFolder, folderName)) ||
254+
existsSync(qlpackStoragePath) ||
253255
isFolderAlreadyInWorkspace(folderName)
254256
) {
255257
return;
@@ -276,7 +278,8 @@ export class DatabaseManager extends DisposableObject {
276278
const qlPackGenerator = new QlPackGenerator(
277279
databaseItem.language,
278280
this.cli,
279-
join(firstWorkspaceFolder, folderName),
281+
qlpackStoragePath,
282+
qlpackStoragePath,
280283
);
281284
await qlPackGenerator.generate();
282285
} catch (e: unknown) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class QlPackGenerator {
1818
private readonly queryLanguage: QueryLanguage,
1919
private readonly cliServer: CodeQLCliServer,
2020
private readonly storagePath: string,
21+
private readonly queryStoragePath: string,
2122
private readonly includeFolderNameInQlpackName: boolean = false,
2223
) {
2324
this.qlpackVersion = "1.0.0";
@@ -91,7 +92,7 @@ export class QlPackGenerator {
9192
}
9293

9394
public async createExampleQlFile(fileName = "example.ql") {
94-
const exampleQlFilePath = join(this.folderUri.fsPath, fileName);
95+
const exampleQlFilePath = join(this.queryStoragePath, fileName);
9596

9697
const exampleQl = `
9798
/**

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,10 @@ export class SkeletonQueryWizard {
455455

456456
private createQlPackGenerator() {
457457
if (this.qlPackStoragePath === undefined) {
458-
throw new Error("Query pack storage path is undefined");
458+
throw new Error("QL pack storage path is undefined");
459+
}
460+
if (this.queryStoragePath === undefined) {
461+
throw new Error("Query storage path is undefined");
459462
}
460463
if (this.language === undefined) {
461464
throw new Error("Language is undefined");
@@ -472,6 +475,7 @@ export class SkeletonQueryWizard {
472475
this.language,
473476
this.cliServer,
474477
this.qlPackStoragePath,
478+
this.queryStoragePath,
475479
includeFolderNameInQlpackName,
476480
);
477481
}

extensions/ql-vscode/test/vscode-tests/minimal-workspace/qlpack-generator.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe("QlPackGenerator", () => {
4646
language as QueryLanguage,
4747
mockCli,
4848
packFolderPath,
49+
packFolderPath,
4950
);
5051
});
5152

@@ -128,6 +129,7 @@ describe("QlPackGenerator", () => {
128129
language as QueryLanguage,
129130
mockCli,
130131
packFolderPath,
132+
packFolderPath,
131133
true,
132134
);
133135
});
@@ -161,6 +163,7 @@ describe("QlPackGenerator", () => {
161163
language as QueryLanguage,
162164
mockCli,
163165
packFolderPath,
166+
packFolderPath,
164167
true,
165168
);
166169
});
@@ -195,6 +198,7 @@ describe("QlPackGenerator", () => {
195198
language as QueryLanguage,
196199
mockCli,
197200
packFolderPath,
201+
packFolderPath,
198202
true,
199203
);
200204
});

0 commit comments

Comments
 (0)