Skip to content

Commit e03d106

Browse files
committed
Update model editor queries
This updates the model editor queries to the version that will be merged into the CodeQL repository. There are some slight changes to the output format, so we slightly need to change the BQRS decoding of those queries. The queries themselves were copied from the two PRs with some minor additions at the end since these were changes in core CodeQL library files.
1 parent 6c1cd71 commit e03d106

File tree

8 files changed

+1038
-746
lines changed

8 files changed

+1038
-746
lines changed

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

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,72 @@ import { DecodedBqrsChunk } from "../common/bqrs-cli-types";
22
import { Call, CallClassification, Method } from "./method";
33
import { ModeledMethodType } from "./modeled-method";
44
import { parseLibraryFilename } from "./library";
5+
import { Mode } from "./shared/mode";
6+
import { ApplicationModeTuple, FrameworkModeTuple } from "./queries/query";
57

6-
export function decodeBqrsToMethods(chunk: DecodedBqrsChunk): Method[] {
8+
export function decodeBqrsToMethods(
9+
chunk: DecodedBqrsChunk,
10+
mode: Mode,
11+
): Method[] {
712
const methodsByApiName = new Map<string, Method>();
813

914
chunk?.tuples.forEach((tuple) => {
10-
const usage = tuple[0] as Call;
11-
const signature = tuple[1] as string;
12-
const supported = (tuple[2] as string) === "true";
13-
let library = tuple[4] as string;
14-
let libraryVersion: string | undefined = tuple[5] as string;
15-
const type = tuple[6] as ModeledMethodType;
16-
const classification = tuple[8] as CallClassification;
15+
let usage: Call;
16+
let packageName: string;
17+
let typeName: string;
18+
let methodName: string;
19+
let methodParameters: string;
20+
let supported: boolean;
21+
let library: string;
22+
let libraryVersion: string | undefined;
23+
let type: ModeledMethodType;
24+
let classification: CallClassification;
1725

18-
const [packageWithType, methodDeclaration] = signature.split("#");
26+
if (mode === Mode.Application) {
27+
[
28+
usage,
29+
packageName,
30+
typeName,
31+
methodName,
32+
methodParameters,
33+
supported,
34+
library,
35+
libraryVersion,
36+
type,
37+
classification,
38+
] = tuple as ApplicationModeTuple;
39+
} else {
40+
[
41+
usage,
42+
packageName,
43+
typeName,
44+
methodName,
45+
methodParameters,
46+
supported,
47+
library,
48+
type,
49+
] = tuple as FrameworkModeTuple;
50+
51+
classification = CallClassification.Unknown;
52+
}
1953

20-
const packageName = packageWithType.substring(
21-
0,
22-
packageWithType.lastIndexOf("."),
23-
);
24-
const typeName = packageWithType.substring(
25-
packageWithType.lastIndexOf(".") + 1,
26-
);
54+
if (!methodParameters.startsWith("(")) {
55+
// There's a difference in how the Java and C# queries return method parameters. In the C# query, the method
56+
// parameters are returned without parentheses. In the Java query, the method parameters are returned with
57+
// parentheses. Therefore, we'll just add them if we don't see them.
58+
methodParameters = `(${methodParameters})`;
59+
}
2760

28-
const methodName = methodDeclaration.substring(
29-
0,
30-
methodDeclaration.indexOf("("),
31-
);
32-
const methodParameters = methodDeclaration.substring(
33-
methodDeclaration.indexOf("("),
34-
);
61+
const signature = `${packageName}.${typeName}#${methodName}${methodParameters}`;
3562

3663
// For Java, we'll always get back a .jar file, and the library version may be bad because not all library authors
3764
// properly specify the version. Therefore, we'll always try to parse the name and version from the library filename
3865
// for Java.
39-
if (library.endsWith(".jar") || libraryVersion === "") {
66+
if (
67+
library.endsWith(".jar") ||
68+
libraryVersion === "" ||
69+
libraryVersion === undefined
70+
) {
4071
const { name, version } = parseLibraryFilename(library);
4172
library = name;
4273
if (version) {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export async function runExternalApiQueries(
132132
maxStep: externalApiQueriesProgressMaxStep,
133133
});
134134

135-
return decodeBqrsToMethods(bqrsChunk);
135+
return decodeBqrsToMethods(bqrsChunk, mode);
136136
}
137137

138138
type GetResultsOptions = {
@@ -160,7 +160,5 @@ export async function readQueryResults({
160160
}
161161

162162
function queryNameFromMode(mode: Mode): string {
163-
return `FetchExternalApis${
164-
mode.charAt(0).toUpperCase() + mode.slice(1)
165-
}Mode.ql`;
163+
return `${mode.charAt(0).toUpperCase() + mode.slice(1)}ModeEndpoints.ql`;
166164
}

0 commit comments

Comments
 (0)