Skip to content

Commit 63d6793

Browse files
committed
Remove some unused BQRS methods/argument type unions
1 parent fc2e6d0 commit 63d6793

20 files changed

Lines changed: 195 additions & 362 deletions

File tree

extensions/ql-vscode/src/common/bqrs-cli-types.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,6 @@ export interface RawResultSet {
9090
readonly rows: readonly ResultRow[];
9191
}
9292

93-
// TODO: This function is not necessary. It generates a tuple that is slightly easier
94-
// to handle than the ResultSetSchema and DecodedBqrsChunk. But perhaps it is unnecessary
95-
// boilerplate.
96-
export function transformBqrsResultSet(
97-
schema: ResultSetSchema,
98-
page: DecodedBqrsChunk,
99-
): RawResultSet {
100-
return {
101-
schema,
102-
rows: Array.from(page.tuples),
103-
};
104-
}
105-
10693
export type BqrsKind =
10794
| "String"
10895
| "Float"

extensions/ql-vscode/src/common/bqrs-result.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function mapEntityValue(cellValue: BqrsEntityValue): EntityValue {
102102
};
103103
}
104104

105-
function mapUrlValue(urlValue: BqrsUrlValue): UrlValue | undefined {
105+
export function mapUrlValue(urlValue: BqrsUrlValue): UrlValue | undefined {
106106
if (typeof urlValue === "string") {
107107
const location = tryGetLocationFromString(urlValue);
108108
if (location !== undefined) {

extensions/ql-vscode/src/common/bqrs-utils.ts

Lines changed: 1 addition & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { createRemoteFileRef } from "../common/location-link-utils";
2-
import {
3-
isUrlValueResolvable,
4-
UrlValue,
5-
UrlValueResolvable,
6-
} from "./raw-result-types";
2+
import { isUrlValueResolvable, UrlValue } from "./raw-result-types";
73
import {
84
LineColumnLocation,
95
UrlValue as BqrsUrlValue,
@@ -18,82 +14,6 @@ export function isEmptyPath(uriStr: string) {
1814
return !uriStr || uriStr === "file:/";
1915
}
2016

21-
/**
22-
* The CodeQL filesystem libraries use this pattern in `getURL()` predicates
23-
* to describe the location of an entire filesystem resource.
24-
* Such locations appear as `StringLocation`s instead of `FivePartLocation`s.
25-
*
26-
* Folder resources also get similar URLs, but with the `folder` scheme.
27-
* They are deliberately ignored here, since there is no suitable location to show the user.
28-
*/
29-
const FILE_LOCATION_REGEX = /file:\/\/(.+):([0-9]+):([0-9]+):([0-9]+):([0-9]+)/;
30-
/**
31-
* Gets a resolvable source file location for the specified `LocationValue`, if possible.
32-
* @param loc The location to test.
33-
*/
34-
export function tryGetResolvableLocation(
35-
loc: BqrsUrlValue | undefined,
36-
): UrlValueResolvable | undefined {
37-
let resolvedLoc: UrlValueResolvable | undefined;
38-
if (loc === undefined) {
39-
resolvedLoc = undefined;
40-
} else if (isWholeFileLoc(loc)) {
41-
resolvedLoc = {
42-
type: "wholeFileLocation",
43-
uri: loc.uri,
44-
};
45-
} else if (isLineColumnLoc(loc)) {
46-
resolvedLoc = {
47-
type: "lineColumnLocation",
48-
uri: loc.uri,
49-
startLine: loc.startLine,
50-
startColumn: loc.startColumn,
51-
endLine: loc.endLine,
52-
endColumn: loc.endColumn,
53-
};
54-
} else if (isStringLoc(loc)) {
55-
resolvedLoc = tryGetLocationFromString(loc);
56-
} else {
57-
resolvedLoc = undefined;
58-
}
59-
60-
return resolvedLoc;
61-
}
62-
63-
export function tryGetLocationFromString(
64-
loc: string,
65-
): UrlValueResolvable | undefined {
66-
const matches = FILE_LOCATION_REGEX.exec(loc);
67-
if (matches && matches.length > 1 && matches[1]) {
68-
if (isWholeFileMatch(matches)) {
69-
return {
70-
type: "wholeFileLocation",
71-
uri: matches[1],
72-
};
73-
} else {
74-
return {
75-
type: "lineColumnLocation",
76-
uri: matches[1],
77-
startLine: Number(matches[2]),
78-
startColumn: Number(matches[3]),
79-
endLine: Number(matches[4]),
80-
endColumn: Number(matches[5]),
81-
};
82-
}
83-
} else {
84-
return undefined;
85-
}
86-
}
87-
88-
function isWholeFileMatch(matches: RegExpExecArray): boolean {
89-
return (
90-
matches[2] === "0" &&
91-
matches[3] === "0" &&
92-
matches[4] === "0" &&
93-
matches[5] === "0"
94-
);
95-
}
96-
9717
export function isLineColumnLoc(loc: BqrsUrlValue): loc is LineColumnLocation {
9818
return (
9919
typeof loc !== "string" &&
@@ -115,20 +35,6 @@ export function isStringLoc(loc: BqrsUrlValue): loc is string {
11535
return typeof loc === "string";
11636
}
11737

118-
export function tryGetBqrsRemoteLocation(
119-
loc: BqrsUrlValue | undefined,
120-
fileLinkPrefix: string,
121-
sourceLocationPrefix: string | undefined,
122-
): string | undefined {
123-
const resolvedLoc = tryGetResolvableLocation(loc);
124-
125-
return tryGetRemoteLocation(
126-
resolvedLoc,
127-
fileLinkPrefix,
128-
sourceLocationPrefix,
129-
);
130-
}
131-
13238
export function tryGetRemoteLocation(
13339
loc: UrlValue | undefined,
13440
fileLinkPrefix: string,

extensions/ql-vscode/src/common/interface-types.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import * as sarif from "sarif";
2-
import {
3-
ResultSetSchema,
4-
ResolvableLocationValue,
5-
} from "../common/bqrs-cli-types";
2+
import { ResultSetSchema } from "../common/bqrs-cli-types";
63
import {
74
VariantAnalysis,
85
VariantAnalysisScannedRepositoryResult,
@@ -215,7 +212,7 @@ export type FromResultsViewMsg =
215212
*/
216213
interface ViewSourceFileMsg {
217214
t: "viewSourceFile";
218-
loc: ResolvableLocationValue | UrlValueResolvable;
215+
loc: UrlValueResolvable;
219216
databaseUri: string;
220217
}
221218

extensions/ql-vscode/src/databases/local-databases/locations.ts

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@ import {
99
window as Window,
1010
workspace,
1111
} from "vscode";
12-
import {
13-
ResolvableLocationValue,
14-
UrlValue as BqrsUrlValue,
15-
} from "../../common/bqrs-cli-types";
1612
import { assertNever, getErrorMessage } from "../../common/helpers-pure";
1713
import { Logger } from "../../common/logging";
1814
import { DatabaseItem } from "./database-item";
1915
import { DatabaseManager } from "./database-manager";
20-
import { tryGetResolvableLocation } from "../../common/bqrs-utils";
2116
import {
2217
UrlValueLineColumnLocation,
2318
UrlValueResolvable,
@@ -74,49 +69,32 @@ function resolveWholeFileLocation(
7469
return new Location(databaseItem.resolveSourceFile(loc.uri), range);
7570
}
7671

77-
function isUrlValueResolvable(
78-
loc: BqrsUrlValue | UrlValueResolvable | undefined,
79-
): loc is UrlValueResolvable {
80-
if (!loc) {
81-
return false;
82-
}
83-
84-
if (typeof loc !== "object") {
85-
return false;
86-
}
87-
88-
return "type" in loc;
89-
}
90-
9172
/**
9273
* Try to resolve the specified CodeQL location to a URI into the source archive. If no exact location
9374
* can be resolved, returns `undefined`.
9475
* @param loc CodeQL location to resolve
9576
* @param databaseItem Database in which to resolve the file location.
9677
*/
9778
export function tryResolveLocation(
98-
loc: BqrsUrlValue | UrlValueResolvable | undefined,
79+
loc: UrlValueResolvable | undefined,
9980
databaseItem: DatabaseItem,
10081
): Location | undefined {
101-
const resolvableLoc = isUrlValueResolvable(loc)
102-
? loc
103-
: tryGetResolvableLocation(loc);
104-
if (!resolvableLoc) {
82+
if (!loc) {
10583
return;
10684
}
10785

108-
switch (resolvableLoc.type) {
86+
switch (loc.type) {
10987
case "wholeFileLocation":
110-
return resolveWholeFileLocation(resolvableLoc, databaseItem);
88+
return resolveWholeFileLocation(loc, databaseItem);
11189
case "lineColumnLocation":
112-
return resolveFivePartLocation(resolvableLoc, databaseItem);
90+
return resolveFivePartLocation(loc, databaseItem);
11391
default:
114-
assertNever(resolvableLoc);
92+
assertNever(loc);
11593
}
11694
}
11795

11896
export async function showResolvableLocation(
119-
loc: ResolvableLocationValue | UrlValueResolvable,
97+
loc: UrlValueResolvable,
12098
databaseItem: DatabaseItem,
12199
logger: Logger,
122100
): Promise<void> {
@@ -174,7 +152,7 @@ export async function showLocation(location?: Location) {
174152

175153
export async function jumpToLocation(
176154
databaseUri: string,
177-
loc: ResolvableLocationValue | UrlValueResolvable,
155+
loc: UrlValueResolvable,
178156
databaseManager: DatabaseManager,
179157
logger: Logger,
180158
) {

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { DecodedBqrsChunk } from "../common/bqrs-cli-types";
2-
import { Call, CallClassification, Method } from "./method";
1+
import { DecodedBqrsChunk, EntityValue } from "../common/bqrs-cli-types";
2+
import { CallClassification, Method, Usage } from "./method";
33
import { ModeledMethodType } from "./modeled-method";
44
import { parseLibraryFilename } from "./library";
55
import { Mode } from "./shared/mode";
66
import { ApplicationModeTuple, FrameworkModeTuple } from "./queries/query";
77
import { QueryLanguage } from "../common/query-language";
88
import { getModelsAsDataLanguage } from "./languages";
9+
import { mapUrlValue } from "../common/bqrs-result";
10+
import { isUrlValueResolvable } from "../common/raw-result-types";
911

1012
export function decodeBqrsToMethods(
1113
chunk: DecodedBqrsChunk,
@@ -17,7 +19,7 @@ export function decodeBqrsToMethods(
1719
const definition = getModelsAsDataLanguage(language);
1820

1921
chunk?.tuples.forEach((tuple) => {
20-
let usage: Call;
22+
let usageEntityValue: EntityValue;
2123
let packageName: string;
2224
let typeName: string;
2325
let methodName: string;
@@ -30,7 +32,7 @@ export function decodeBqrsToMethods(
3032

3133
if (mode === Mode.Application) {
3234
[
33-
usage,
35+
usageEntityValue,
3436
packageName,
3537
typeName,
3638
methodName,
@@ -43,7 +45,7 @@ export function decodeBqrsToMethods(
4345
] = tuple as ApplicationModeTuple;
4446
} else {
4547
[
46-
usage,
48+
usageEntityValue,
4749
packageName,
4850
typeName,
4951
methodName,
@@ -97,11 +99,25 @@ export function decodeBqrsToMethods(
9799
});
98100
}
99101

102+
if (usageEntityValue.url === undefined) {
103+
return;
104+
}
105+
106+
const usageUrl = mapUrlValue(usageEntityValue.url);
107+
if (!usageUrl || !isUrlValueResolvable(usageUrl)) {
108+
return;
109+
}
110+
111+
if (!usageEntityValue.label) {
112+
return;
113+
}
114+
100115
const method = methodsByApiName.get(signature)!;
101-
const usages = [
116+
const usages: Usage[] = [
102117
...method.usages,
103118
{
104-
...usage,
119+
label: usageEntityValue.label,
120+
url: usageUrl,
105121
classification,
106122
},
107123
];

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { ResolvableLocationValue } from "../common/bqrs-cli-types";
21
import { ModeledMethod, ModeledMethodType } from "./modeled-method";
2+
import { UrlValueResolvable } from "../common/raw-result-types";
33

44
export type Call = {
55
readonly label: string;
6-
readonly url: Readonly<ResolvableLocationValue>;
6+
readonly url: Readonly<UrlValueResolvable>;
77
};
88

99
export enum CallClassification {

extensions/ql-vscode/src/model-editor/methods-usage/methods-usage-data-provider.ts

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { assertNever } from "../../common/helpers-pure";
1919
import { ModeledMethod } from "../modeled-method";
2020
import { groupMethods, sortGroupNames, sortMethods } from "../shared/sorting";
2121
import { INITIAL_MODE, Mode } from "../shared/mode";
22+
import { UrlValueResolvable } from "../../common/raw-result-types";
2223

2324
export class MethodsUsageDataProvider
2425
extends DisposableObject
@@ -99,11 +100,16 @@ export class MethodsUsageDataProvider
99100
} else {
100101
const { method, usage } = item;
101102

103+
const description =
104+
usage.url.type === "wholeFileLocation"
105+
? this.relativePathWithinDatabase(usage.url.uri)
106+
: `${this.relativePathWithinDatabase(usage.url.uri)} [${
107+
usage.url.startLine
108+
}, ${usage.url.endLine}]`;
109+
102110
return {
103111
label: usage.label,
104-
description: `${this.relativePathWithinDatabase(usage.url.uri)} [${
105-
usage.url.startLine
106-
}, ${usage.url.endLine}]`,
112+
description,
107113
collapsibleState: TreeItemCollapsibleState.None,
108114
command: {
109115
title: "Show usage",
@@ -211,14 +217,35 @@ function usagesAreEqual(u1: Usage, u2: Usage): boolean {
211217
return (
212218
u1.label === u2.label &&
213219
u1.classification === u2.classification &&
214-
u1.url.uri === u2.url.uri &&
215-
u1.url.startLine === u2.url.startLine &&
216-
u1.url.startColumn === u2.url.startColumn &&
217-
u1.url.endLine === u2.url.endLine &&
218-
u1.url.endColumn === u2.url.endColumn
220+
urlValueResolvablesAreEqual(u1.url, u2.url)
219221
);
220222
}
221223

224+
function urlValueResolvablesAreEqual(
225+
u1: UrlValueResolvable,
226+
u2: UrlValueResolvable,
227+
): boolean {
228+
if (u1.type !== u2.type) {
229+
return false;
230+
}
231+
232+
if (u1.type === "wholeFileLocation" && u2.type === "wholeFileLocation") {
233+
return u1.uri === u2.uri;
234+
}
235+
236+
if (u1.type === "lineColumnLocation" && u2.type === "lineColumnLocation") {
237+
return (
238+
u1.uri === u2.uri &&
239+
u1.startLine === u2.startLine &&
240+
u1.startColumn === u2.startColumn &&
241+
u1.endLine === u2.endLine &&
242+
u1.endColumn === u2.endColumn
243+
);
244+
}
245+
246+
return false;
247+
}
248+
222249
function sortMethodsInGroups(methods: readonly Method[], mode: Mode): Method[] {
223250
const grouped = groupMethods(methods, mode);
224251

0 commit comments

Comments
 (0)