Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ export class DataExtensionsEditorView extends AbstractWebview<
externalApiUsages: ExternalApiUsage[],
modeledMethods: Record<string, ModeledMethod>,
): Promise<void> {
const yaml = createDataExtensionYaml(externalApiUsages, modeledMethods);
const yaml = createDataExtensionYaml(
this.databaseItem.language,
externalApiUsages,
modeledMethods,
);

await outputFile(this.modelFilename, yaml);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const packNameLength = 128;

export async function pickExtensionPackModelFile(
cliServer: Pick<CodeQLCliServer, "resolveQlpacks" | "resolveExtensions">,
databaseItem: Pick<DatabaseItem, "name">,
databaseItem: Pick<DatabaseItem, "name" | "language">,
progress: ProgressCallback,
token: CancellationToken,
): Promise<string | undefined> {
Expand Down Expand Up @@ -53,7 +53,7 @@ export async function pickExtensionPackModelFile(

async function pickExtensionPack(
cliServer: Pick<CodeQLCliServer, "resolveQlpacks">,
databaseItem: Pick<DatabaseItem, "name">,
databaseItem: Pick<DatabaseItem, "name" | "language">,
progress: ProgressCallback,
token: CancellationToken,
): Promise<string | undefined> {
Expand Down Expand Up @@ -184,7 +184,7 @@ async function pickModelFile(
}

async function pickNewExtensionPack(
databaseItem: Pick<DatabaseItem, "name">,
databaseItem: Pick<DatabaseItem, "name" | "language">,
token: CancellationToken,
): Promise<string | undefined> {
const workspaceFolders = getOnDiskWorkspaceFoldersObjects();
Expand Down Expand Up @@ -257,7 +257,7 @@ async function pickNewExtensionPack(
version: "0.0.0",
library: true,
extensionTargets: {
"codeql/java-all": "*",
[`codeql/${databaseItem.language}-all`]: "*",
},
dataExtensions: ["models/**/*.yml"],
}),
Expand Down
3 changes: 2 additions & 1 deletion extensions/ql-vscode/src/data-extensions-editor/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function createDataProperty(
}

export function createDataExtensionYaml(
language: string,
externalApiUsages: ExternalApiUsage[],
modeledMethods: Record<string, ModeledMethod>,
) {
Expand All @@ -69,7 +70,7 @@ export function createDataExtensionYaml(

const extensions = Object.entries(extensiblePredicateDefinitions).map(
([type, definition]) => ` - addsTo:
pack: codeql/java-all
pack: codeql/${language}-all
extensible: ${definition.extensiblePredicate}
data:${createDataProperty(
methodsByType[type as Exclude<ModeledMethodType, "none">],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
describe("createDataExtensionYaml", () => {
it("creates the correct YAML file", () => {
const yaml = createDataExtensionYaml(
"java",
[
{
signature: "org.sql2o.Connection#createQuery(String)",
Expand Down Expand Up @@ -99,6 +100,32 @@ describe("createDataExtensionYaml", () => {
pack: codeql/java-all
extensible: neutralModel
data: []
`);
});

it("includes the correct language", () => {
const yaml = createDataExtensionYaml("csharp", [], {});

expect(yaml).toEqual(`extensions:
- addsTo:
pack: codeql/csharp-all
extensible: sourceModel
data: []

- addsTo:
pack: codeql/csharp-all
extensible: sinkModel
data: []

- addsTo:
pack: codeql/csharp-all
extensible: summaryModel
data: []

- addsTo:
pack: codeql/csharp-all
extensible: neutralModel
data: []
`);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe("pickExtensionPackModelFile", () => {
};
const databaseItem = {
name: "github/vscode-codeql",
language: "java",
};

const cancellationTokenSource = new CancellationTokenSource();
Expand Down Expand Up @@ -304,6 +305,71 @@ describe("pickExtensionPackModelFile", () => {
});
});

it("allows user to create an extension pack when there are no extension packs with a different language", async () => {
const cliServer = mockCliServer({}, { models: [], data: {} });

const tmpDir = await dir({
unsafeCleanup: true,
});

showQuickPickSpy.mockResolvedValueOnce({
label: "codeql-custom-queries-java",
path: tmpDir.path,
} as QuickPickItem);
showInputBoxSpy.mockResolvedValueOnce("my-extension-pack");
showInputBoxSpy.mockResolvedValue("models/my-model.yml");

expect(
await pickExtensionPackModelFile(
cliServer,
{
...databaseItem,
language: "csharp",
},
progress,
token,
),
).toEqual(join(tmpDir.path, "my-extension-pack", "models", "my-model.yml"));
expect(showQuickPickSpy).toHaveBeenCalledTimes(1);
expect(showInputBoxSpy).toHaveBeenCalledTimes(2);
expect(showInputBoxSpy).toHaveBeenCalledWith(
{
title: expect.stringMatching(/extension pack/i),
prompt: expect.stringMatching(/extension pack/i),
placeHolder: expect.stringMatching(/github\/vscode-codeql-extensions/),
validateInput: expect.any(Function),
},
token,
);
expect(showInputBoxSpy).toHaveBeenCalledWith(
{
title: expect.stringMatching(/model file/),
value: "models/github.vscode-codeql.model.yml",
validateInput: expect.any(Function),
},
token,
);
expect(cliServer.resolveQlpacks).toHaveBeenCalled();
expect(cliServer.resolveExtensions).toHaveBeenCalled();

expect(
loadYaml(
await readFile(
join(tmpDir.path, "my-extension-pack", "codeql-pack.yml"),
"utf8",
),
),
).toEqual({
name: "my-extension-pack",
version: "0.0.0",
library: true,
extensionTargets: {
"codeql/csharp-all": "*",
},
dataExtensions: ["models/**/*.yml"],
});
});

it("allows cancelling the workspace folder selection", async () => {
const cliServer = mockCliServer({}, { models: [], data: {} });

Expand Down