Skip to content

Commit ae08a1b

Browse files
committed
Use data extensions for finding external API calls
The data extension editor was only using the default data extensions found in the `ql` submodule to find external API calls. This will add support for using data extensions found in the workspace. Rather than using the `codeQL.runningQueries.useExtensionPacks` setting, this will always include data extensions since the editor doesn't make sense to use without data extensions. We will also forbid the user from opening this view unless they are using a CLI which supports data extension packs.
1 parent deb2b83 commit ae08a1b

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

extensions/ql-vscode/src/data-extensions-editor/data-extensions-editor-module.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { ExtensionContext } from "vscode";
22
import { DataExtensionsEditorView } from "./data-extensions-editor-view";
33
import { DataExtensionsEditorCommands } from "../common/commands";
4-
import { CodeQLCliServer } from "../cli";
4+
import { CliVersionConstraint, CodeQLCliServer } from "../cli";
55
import { QueryRunner } from "../queryRunner";
66
import { DatabaseManager } from "../local-databases";
7-
import { extLogger } from "../common";
87
import { ensureDir } from "fs-extra";
98
import { join } from "path";
109
import { App } from "../common/app";
10+
import { showAndLogErrorMessage } from "../helpers";
1111

1212
export class DataExtensionsEditorModule {
1313
private readonly queryStorageDir: string;
@@ -52,7 +52,14 @@ export class DataExtensionsEditorModule {
5252
"codeQL.openDataExtensionsEditor": async () => {
5353
const db = this.databaseManager.currentDatabaseItem;
5454
if (!db) {
55-
void extLogger.log("No database selected");
55+
void showAndLogErrorMessage("No database selected");
56+
return;
57+
}
58+
59+
if (!(await this.cliServer.cliConstraints.supportsQlpacksKind())) {
60+
void showAndLogErrorMessage(
61+
`This feature requires CodeQL CLI version ${CliVersionConstraint.CLI_VERSION_WITH_QLPACKS_KIND.format()} or later.`,
62+
);
5663
return;
5764
}
5865

extensions/ql-vscode/src/data-extensions-editor/external-api-usage-query.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ export async function runQuery({
5454
}
5555
await writeFile(suiteFile, dumpYaml(suiteYaml), "utf8");
5656

57+
const additionalPacks = getOnDiskWorkspaceFolders();
58+
const extensionPacks = Object.keys(
59+
await cliServer.resolveQlpacks(additionalPacks, true),
60+
);
61+
5762
const queries = await cliServer.resolveQueriesInSuite(
5863
suiteFile,
5964
getOnDiskWorkspaceFolders(),
@@ -71,7 +76,7 @@ export async function runQuery({
7176
{ queryPath: query, quickEvalPosition: undefined },
7277
false,
7378
getOnDiskWorkspaceFolders(),
74-
undefined,
79+
extensionPacks,
7580
queryStorageDir,
7681
undefined,
7782
undefined,

extensions/ql-vscode/test/vscode-tests/no-workspace/data-extensions-editor/external-api-usage-query.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ describe("runQuery", () => {
3636

3737
const options = {
3838
cliServer: {
39-
resolveQlpacks: jest
40-
.fn()
41-
.mockRejectedValue(
42-
new Error("Did not expect mocked method to be called"),
43-
),
39+
resolveQlpacks: jest.fn().mockResolvedValue({
40+
"my/java-extensions": "/a/b/c/",
41+
}),
4442
resolveQueriesInSuite: jest
4543
.fn()
4644
.mockResolvedValue([
@@ -103,6 +101,8 @@ describe("runQuery", () => {
103101
},
104102
]);
105103

104+
expect(options.cliServer.resolveQlpacks).toHaveBeenCalledTimes(1);
105+
expect(options.cliServer.resolveQlpacks).toHaveBeenCalledWith([], true);
106106
expect(options.queryRunner.createQueryRun).toHaveBeenCalledWith(
107107
"/a/b/c/src.zip",
108108
{
@@ -112,15 +112,15 @@ describe("runQuery", () => {
112112
},
113113
false,
114114
[],
115-
undefined,
115+
["my/java-extensions"],
116116
"/tmp/queries",
117117
undefined,
118118
undefined,
119119
);
120120
});
121121
});
122122

123-
describe("getResults", () => {
123+
describe("readQueryResults", () => {
124124
const options = {
125125
cliServer: {
126126
bqrsInfo: jest.fn(),

0 commit comments

Comments
 (0)