Skip to content

Commit b1debee

Browse files
authored
Merge pull request #2868 from github/koesie10/new-model-editor-queries
Update model editor queries
2 parents 3b00d74 + 95c512e commit b1debee

File tree

8 files changed

+1038
-747
lines changed

8 files changed

+1038
-747
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)