Skip to content

Commit 2ebccd5

Browse files
Merge pull request #3014 from github/robertbrignull/hidden_methods
Use the same logic for hiding methods in model editor and usages panel
2 parents f0f13f3 + 231dcc0 commit 2ebccd5

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ export function getArgumentsList(methodParameters: string): string[] {
6666
return methodParameters.substring(1, methodParameters.length - 1).split(",");
6767
}
6868

69+
/**
70+
* Should we present the user with the ability to edit to modelings for this method.
71+
*
72+
* A method may be unmodelable if it is already modeled by CodeQL or by an extension
73+
* pack other than the one currently being edited.
74+
*/
6975
export function canMethodBeModeled(
7076
method: Method,
7177
modeledMethods: readonly ModeledMethod[],

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Uri,
1010
} from "vscode";
1111
import { DisposableObject } from "../../common/disposable-object";
12-
import { Method, Usage } from "../method";
12+
import { Method, Usage, canMethodBeModeled } from "../method";
1313
import { DatabaseItem } from "../../databases/local-databases";
1414
import { relative } from "path";
1515
import { CodeQLCliServer } from "../../codeql-cli/cli";
@@ -146,7 +146,13 @@ export class MethodsUsageDataProvider
146146
getChildren(item?: MethodsUsageTreeViewItem): MethodsUsageTreeViewItem[] {
147147
if (item === undefined) {
148148
if (this.hideModeledMethods) {
149-
return this.sortedTreeItems.filter((api) => !api.method.supported);
149+
return this.sortedTreeItems.filter((api) =>
150+
canMethodBeModeled(
151+
api.method,
152+
this.modeledMethods[api.method.signature] ?? [],
153+
this.modifiedMethodSignatures.has(api.method.signature),
154+
),
155+
);
150156
} else {
151157
return [...this.sortedTreeItems];
152158
}

extensions/ql-vscode/test/vscode-tests/no-workspace/model-editor/methods-usage/methods-usage-data-provider.test.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import { mockedObject } from "../../../utils/mocking.helpers";
1616
import { ModeledMethod } from "../../../../../src/model-editor/modeled-method";
1717
import { Mode } from "../../../../../src/model-editor/shared/mode";
18+
import { createModeledMethod } from "../../../../factories/model-editor/modeled-method-factories";
1819

1920
describe("MethodsUsageDataProvider", () => {
2021
const mockCliServer = mockedObject<CodeQLCliServer>({});
@@ -226,17 +227,35 @@ describe("MethodsUsageDataProvider", () => {
226227
});
227228

228229
describe("getChildren", () => {
229-
const supportedMethod = createMethod({
230+
const supportedUnmodeledMethod = createMethod({
231+
signature: "some.supported.unmodeled.method()",
230232
supported: true,
231233
});
232-
233-
const unsupportedMethod = createMethod({
234+
const supportedModeledMethod = createMethod({
235+
signature: "some.supported.modeled.method()",
236+
supported: true,
237+
});
238+
const unsupportedUnmodeledMethod = createMethod({
239+
signature: "some.unsupported.unmodeled.method()",
240+
supported: false,
241+
});
242+
const unsupportedModeledMethod = createMethod({
243+
signature: "some.unsupported.modeled.method()",
234244
supported: false,
235245
});
236246

237247
const mode = Mode.Application;
238-
const methods: Method[] = [supportedMethod, unsupportedMethod];
248+
const methods: Method[] = [
249+
supportedUnmodeledMethod,
250+
supportedModeledMethod,
251+
unsupportedUnmodeledMethod,
252+
unsupportedModeledMethod,
253+
];
239254
const modeledMethods: Record<string, ModeledMethod[]> = {};
255+
modeledMethods[supportedModeledMethod.signature] = [createModeledMethod()];
256+
modeledMethods[unsupportedModeledMethod.signature] = [
257+
createModeledMethod(),
258+
];
240259
const modifiedMethodSignatures: Set<string> = new Set();
241260

242261
const dbItem = mockedObject<DatabaseItem>({
@@ -246,12 +265,12 @@ describe("MethodsUsageDataProvider", () => {
246265
const usage = createUsage({});
247266

248267
const methodTreeItem: MethodsUsageTreeViewItem = {
249-
method: supportedMethod,
268+
method: unsupportedUnmodeledMethod,
250269
children: [],
251270
};
252271

253272
const usageTreeItem: MethodsUsageTreeViewItem = {
254-
method: supportedMethod,
273+
method: unsupportedUnmodeledMethod,
255274
usage,
256275
parent: methodTreeItem,
257276
};
@@ -275,7 +294,7 @@ describe("MethodsUsageDataProvider", () => {
275294
modeledMethods,
276295
modifiedMethodSignatures,
277296
);
278-
expect(dataProvider.getChildren().length).toEqual(2);
297+
expect(dataProvider.getChildren().length).toEqual(4);
279298
});
280299

281300
it("should filter methods if hideModeledMethods is true and looking at the root", async () => {
@@ -288,7 +307,7 @@ describe("MethodsUsageDataProvider", () => {
288307
modeledMethods,
289308
modifiedMethodSignatures,
290309
);
291-
expect(dataProvider.getChildren().length).toEqual(1);
310+
expect(dataProvider.getChildren().length).toEqual(3);
292311
});
293312

294313
describe("with multiple libraries", () => {

0 commit comments

Comments
 (0)