Skip to content

Commit 905eaf6

Browse files
committed
Implement PR feedback
1 parent e9b67dd commit 905eaf6

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface QueryConstraints {
4242
* @param additionalPacks Additional pack paths to search.
4343
* @returns The found queries from the first pack in which any matching queries were found.
4444
*/
45-
async function resolveQueriesFromPacks(
45+
export async function resolveQueriesFromPacks(
4646
cli: CodeQLCliServer,
4747
qlpacks: string[],
4848
constraints: QueryConstraints,
@@ -99,7 +99,6 @@ export async function resolveQueriesByLanguagePack(
9999
* @param packsToSearch The list of packs to search.
100100
* @param name The name of the query to use in error messages.
101101
* @param constraints Constraints on the queries to search for.
102-
* @param allowNoQueriesFound If true, will not throw an error if no queries are found.
103102
* @param additionalPacks Additional pack paths to search.
104103
* @returns The found queries from the first pack in which any matching queries were found.
105104
*/
@@ -108,7 +107,6 @@ export async function resolveQueries(
108107
packsToSearch: string[],
109108
name: string,
110109
constraints: QueryConstraints,
111-
allowNoQueriesFound = false,
112110
additionalPacks: string[] = [],
113111
): Promise<string[]> {
114112
const queries = await resolveQueriesFromPacks(
@@ -135,10 +133,6 @@ export async function resolveQueries(
135133
);
136134
}
137135

138-
if (allowNoQueriesFound) {
139-
return [];
140-
}
141-
142136
const joinedPacksToSearch = packsToSearch.join(", ");
143137
const error = redactableError`No ${name} queries (${humanConstraints.join(
144138
", ",

extensions/ql-vscode/src/model-editor/external-api-usage-queries.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,13 @@ export async function runExternalApiQueries(
105105
mode,
106106
[syntheticQueryPackName],
107107
[queryDir],
108-
false,
109108
);
110109
if (!queryPath) {
110+
void showAndLogExceptionWithTelemetry(
111+
extLogger,
112+
telemetryListener,
113+
redactableError`The ${mode} model editor query could not be found. Try re-opening the model editor. If that doesn't work, try upgrading the CodeQL libraries.`,
114+
);
111115
return;
112116
}
113117

extensions/ql-vscode/src/model-editor/model-editor-queries.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { prepareExternalApiQuery } from "./external-api-usage-queries";
66
import { CodeQLCliServer } from "../codeql-cli/cli";
77
import { showLlmGeneration } from "../config";
88
import { Mode } from "./shared/mode";
9-
import { resolveQueries } from "../local-queries";
9+
import { resolveQueriesFromPacks } from "../local-queries";
1010
import { modeTag } from "./mode-tag";
11-
import { extLogger } from "../common/logging/vscode";
1211

1312
export const syntheticQueryPackName = "codeql/external-api-usage";
1413

@@ -39,18 +38,17 @@ export async function setUpPack(
3938
// Download the required query packs
4039
await cliServer.packDownload([`codeql/${language}-queries`]);
4140

41+
// We'll only check if the application mode query exists in the pack and assume that if it does,
42+
// the framework mode query will also exist.
4243
const applicationModeQuery = await resolveEndpointsQuery(
4344
cliServer,
4445
language,
4546
Mode.Application,
4647
[],
4748
[],
48-
true,
4949
);
5050

5151
if (applicationModeQuery) {
52-
void extLogger.log("Using application mode queries");
53-
5452
// Set up a synthetic pack so CodeQL doesn't crash later when we try
5553
// to resolve a query within this directory
5654
const syntheticQueryPack = {
@@ -62,8 +60,6 @@ export async function setUpPack(
6260
const qlpackFile = join(queryDir, "codeql-pack.yml");
6361
await writeFile(qlpackFile, dump(syntheticQueryPack), "utf8");
6462
} else {
65-
void extLogger.log("Writing external API usage queries to disk");
66-
6763
// If we can't resolve the query, we need to write them to desk ourselves.
6864
const externalApiQuerySuccess = await prepareExternalApiQuery(
6965
queryDir,
@@ -105,31 +101,27 @@ export async function setUpPack(
105101
* @param mode The mode to resolve the query for.
106102
* @param additionalPackNames Additional pack names to search.
107103
* @param additionalPackPaths Additional pack paths to search.
108-
* @param allowNoQueriesFound If true, will not throw an error if no queries are found.
109104
*/
110105
export async function resolveEndpointsQuery(
111106
cliServer: CodeQLCliServer,
112107
language: string,
113108
mode: Mode,
114109
additionalPackNames: string[] = [],
115110
additionalPackPaths: string[] = [],
116-
allowNoQueriesFound = false,
117111
): Promise<string | undefined> {
118112
const packsToSearch = [`codeql/${language}-queries`, ...additionalPackNames];
119113

120114
// First, resolve the query that we want to run.
121115
// All queries are tagged like this:
122116
// internal extract automodel <mode> <queryTag>
123117
// Example: internal extract automodel framework-mode candidates
124-
const queries = await resolveQueries(
118+
const queries = await resolveQueriesFromPacks(
125119
cliServer,
126120
packsToSearch,
127-
`Fetch endpoints query for ${mode}`,
128121
{
129122
kind: "table",
130123
"tags contain all": ["modeleditor", "endpoints", modeTag(mode)],
131124
},
132-
allowNoQueriesFound,
133125
additionalPackPaths,
134126
);
135127
if (queries.length > 1) {

0 commit comments

Comments
 (0)