Skip to content
Closed
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 @@ -28,7 +28,6 @@ type AutoModelQueryOptions = {
cliServer: CodeQLCliServer;
queryRunner: QueryRunner;
databaseItem: DatabaseItem;
qlpack: QlPacksForLanguage;
sourceInfo: SourceInfo | undefined;
additionalPacks: string[];
extensionPacks: string[];
Expand All @@ -55,7 +54,6 @@ async function runAutoModelQuery({
cliServer,
queryRunner,
databaseItem,
qlpack,
sourceInfo,
additionalPacks,
extensionPacks,
Expand All @@ -69,12 +67,14 @@ async function runAutoModelQuery({
// Example: internal extract automodel framework-mode candidates
const queries = await resolveQueries(
cliServer,
qlpack,
undefined,
`Extract automodel ${queryTag}`,
{
kind: "problem",
"tags contain all": ["automodel", modeTag(mode), ...queryTag.split(" ")],
},
additionalPacks,
[`codeql/${databaseItem.language}-queries`],
);
if (queries.length > 1) {
throw new Error(
Expand Down Expand Up @@ -157,6 +157,7 @@ type AutoModelQueriesOptions = {
cliServer: CodeQLCliServer;
queryRunner: QueryRunner;
databaseItem: DatabaseItem;
queryDir: string;
queryStorageDir: string;

progress: ProgressCallback;
Expand All @@ -173,12 +174,11 @@ export async function runAutoModelQueries({
cliServer,
queryRunner,
databaseItem,
queryDir,
queryStorageDir,
progress,
cancellationTokenSource,
}: AutoModelQueriesOptions): Promise<AutoModelQueriesResult | undefined> {
const qlpack = await qlpackOfDatabase(cliServer, databaseItem);

// CodeQL needs to have access to the database to be able to retrieve the
// snippets from it. The source location prefix is used to determine the
// base path of the database.
Expand All @@ -200,7 +200,11 @@ export async function runAutoModelQueries({
candidateMethods,
);

const additionalPacks = [...getOnDiskWorkspaceFolders(), filterPackDir];
const additionalPacks = [
...getOnDiskWorkspaceFolders(),
queryDir,
filterPackDir,
];
const extensionPacks = Object.keys(
await cliServer.resolveQlpacks(additionalPacks, true),
);
Expand All @@ -211,7 +215,6 @@ export async function runAutoModelQueries({
cliServer,
queryRunner,
databaseItem,
qlpack,
sourceInfo,
additionalPacks,
extensionPacks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class AutoModeler {
private readonly app: App,
private readonly cliServer: CodeQLCliServer,
private readonly queryRunner: QueryRunner,
private readonly queryDir: string,
private readonly queryStorageDir: string,
private readonly databaseItem: DatabaseItem,
private readonly setInProgressMethods: (
Expand Down Expand Up @@ -174,6 +175,7 @@ export class AutoModeler {
candidateMethods,
cliServer: this.cliServer,
queryRunner: this.queryRunner,
queryDir: this.queryDir,
queryStorageDir: this.queryStorageDir,
databaseItem: this.databaseItem,
progress: (update) => progress({ ...update }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class DataExtensionsEditorView extends AbstractWebview<
app,
cliServer,
queryRunner,
queryDir,
queryStorageDir,
databaseItem,
async (packageName, inProgressMethods) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function setUpPack(
name: "codeql/external-api-usage",
version: "0.0.0",
dependencies: {
[`codeql/${language}-all`]: "*",
[`codeql/${language}-all`]: "*", // TODO: update with autmodel pack
},
};

Expand Down
24 changes: 14 additions & 10 deletions extensions/ql-vscode/src/local-queries/query-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { redactableError } from "../common/errors";
import { showAndLogExceptionWithTelemetry } from "../common/logging";
import { extLogger } from "../common/logging/vscode";
import { telemetryListener } from "../common/vscode/telemetry";
import { get } from "http";

Check notice

Code scanning / CodeQL

Unused variable, import, function or class

Unused import get.

export async function qlpackOfDatabase(
cli: Pick<CodeQLCliServer, "resolveQlpacks">,
Expand Down Expand Up @@ -44,6 +45,7 @@ async function resolveQueriesFromPacks(
cli: CodeQLCliServer,
qlpacks: string[],
constraints: QueryConstraints,
extraPacks: string[] = [],
): Promise<string[]> {
const suiteFile = (
await file({
Expand All @@ -66,10 +68,9 @@ async function resolveQueriesFromPacks(
"utf8",
);

return await cli.resolveQueriesInSuite(
suiteFile,
getOnDiskWorkspaceFolders(),
);
const additionalPacks = [...getOnDiskWorkspaceFolders(), ...extraPacks];

return await cli.resolveQueriesInSuite(suiteFile, additionalPacks);
}

/**
Expand All @@ -83,22 +84,25 @@ async function resolveQueriesFromPacks(
*/
export async function resolveQueries(
cli: CodeQLCliServer,
qlpacks: QlPacksForLanguage,
qlpacks: QlPacksForLanguage | undefined,
name: string,
constraints: QueryConstraints,
extraPacks: string[] = [],
packsToSearch: string[] = [],
): Promise<string[]> {
const packsToSearch: string[] = [];

// The CLI can handle both library packs and query packs, so search both packs in order.
packsToSearch.push(qlpacks.dbschemePack);
if (qlpacks.queryPack !== undefined) {
packsToSearch.push(qlpacks.queryPack);
if (qlpacks !== undefined) {
packsToSearch.push(qlpacks.dbschemePack);
if (qlpacks.queryPack !== undefined) {
packsToSearch.push(qlpacks.queryPack);
}
}

const queries = await resolveQueriesFromPacks(
cli,
packsToSearch,
constraints,
extraPacks,
);
if (queries.length > 0) {
return queries;
Expand Down