Skip to content

Commit 3598b18

Browse files
Merge pull request github#3376 from github/robertbrignull/dont-model-twice
Don't send methods to AutoModel more than once
2 parents 4727e0e + e3d9efe commit 3598b18

File tree

5 files changed

+80
-4
lines changed

5 files changed

+80
-4
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ export function getCandidates(
2222
mode: Mode,
2323
methods: readonly Method[],
2424
modeledMethodsBySignature: Record<string, readonly ModeledMethod[]>,
25+
processedByAutoModelMethods: Set<string>,
2526
): MethodSignature[] {
27+
// Filter out any methods already processed by auto-model
28+
methods = methods.filter(
29+
(m) => !processedByAutoModelMethods.has(m.signature),
30+
);
31+
2632
// Sort the same way as the UI so we send the first ones listed in the UI first
2733
const grouped = groupMethods(methods, mode);
2834
const sortedGroupNames = sortGroupNames(grouped);

extensions/ql-vscode/src/model-editor/auto-modeler.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class AutoModeler {
5858
packageName: string,
5959
methods: readonly Method[],
6060
modeledMethods: Record<string, readonly ModeledMethod[]>,
61+
processedByAutoModelMethods: Set<string>,
6162
mode: Mode,
6263
): Promise<void> {
6364
if (this.jobs.has(packageName)) {
@@ -72,6 +73,7 @@ export class AutoModeler {
7273
packageName,
7374
methods,
7475
modeledMethods,
76+
processedByAutoModelMethods,
7577
mode,
7678
cancellationTokenSource,
7779
);
@@ -105,6 +107,7 @@ export class AutoModeler {
105107
packageName: string,
106108
methods: readonly Method[],
107109
modeledMethods: Record<string, readonly ModeledMethod[]>,
110+
processedByAutoModelMethods: Set<string>,
108111
mode: Mode,
109112
cancellationTokenSource: CancellationTokenSource,
110113
): Promise<void> {
@@ -114,7 +117,12 @@ export class AutoModeler {
114117

115118
await withProgress(async (progress) => {
116119
// Fetch the candidates to send to the model
117-
const allCandidateMethods = getCandidates(mode, methods, modeledMethods);
120+
const allCandidateMethods = getCandidates(
121+
mode,
122+
methods,
123+
modeledMethods,
124+
processedByAutoModelMethods,
125+
);
118126

119127
// If there are no candidates, there is nothing to model and we just return
120128
if (allCandidateMethods.length === 0) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,11 +655,17 @@ export class ModelEditorView extends AbstractWebview<
655655
this.databaseItem,
656656
methodSignatures,
657657
);
658+
const processedByAutoModelMethods =
659+
this.modelingStore.getProcessedByAutoModelMethods(
660+
this.databaseItem,
661+
methodSignatures,
662+
);
658663
const mode = this.modelingStore.getMode(this.databaseItem);
659664
await this.autoModeler.startModeling(
660665
packageName,
661666
methods,
662667
modeledMethods,
668+
processedByAutoModelMethods,
663669
mode,
664670
);
665671
}

extensions/ql-vscode/src/model-editor/modeling-store.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,22 @@ export class ModelingStore extends DisposableObject {
344344
});
345345
}
346346

347+
public getProcessedByAutoModelMethods(
348+
dbItem: DatabaseItem,
349+
methodSignatures?: string[],
350+
): Set<string> {
351+
const processedByAutoModelMethods =
352+
this.getState(dbItem).processedByAutoModelMethods;
353+
if (!methodSignatures) {
354+
return processedByAutoModelMethods;
355+
}
356+
return new Set(
357+
Array.from(processedByAutoModelMethods).filter((x) =>
358+
methodSignatures.includes(x),
359+
),
360+
);
361+
}
362+
347363
public addProcessedByAutoModelMethods(
348364
dbItem: DatabaseItem,
349365
processedByAutoModelMethods: string[],

extensions/ql-vscode/test/unit-tests/model-editor/auto-model.test.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ describe("getCandidates", () => {
116116
},
117117
],
118118
};
119-
const candidates = getCandidates(Mode.Application, methods, modeledMethods);
119+
const candidates = getCandidates(
120+
Mode.Application,
121+
methods,
122+
modeledMethods,
123+
new Set(),
124+
);
120125
expect(candidates.length).toEqual(0);
121126
});
122127

@@ -136,7 +141,37 @@ describe("getCandidates", () => {
136141
},
137142
];
138143
const modeledMethods = {};
139-
const candidates = getCandidates(Mode.Application, methods, modeledMethods);
144+
const candidates = getCandidates(
145+
Mode.Application,
146+
methods,
147+
modeledMethods,
148+
new Set(),
149+
);
150+
expect(candidates.length).toEqual(0);
151+
});
152+
153+
it("doesn't return methods that are already processed by auto model", () => {
154+
const methods: Method[] = [
155+
{
156+
library: "my.jar",
157+
signature: "org.my.A#x()",
158+
endpointType: EndpointType.Method,
159+
packageName: "org.my",
160+
typeName: "A",
161+
methodName: "x",
162+
methodParameters: "()",
163+
supported: false,
164+
supportedType: "none",
165+
usages: [],
166+
},
167+
];
168+
const modeledMethods = {};
169+
const candidates = getCandidates(
170+
Mode.Application,
171+
methods,
172+
modeledMethods,
173+
new Set(["org.my.A#x()"]),
174+
);
140175
expect(candidates.length).toEqual(0);
141176
});
142177

@@ -155,7 +190,12 @@ describe("getCandidates", () => {
155190
usages: [],
156191
});
157192
const modeledMethods = {};
158-
const candidates = getCandidates(Mode.Application, methods, modeledMethods);
193+
const candidates = getCandidates(
194+
Mode.Application,
195+
methods,
196+
modeledMethods,
197+
new Set(),
198+
);
159199
expect(candidates.length).toEqual(1);
160200
});
161201
});

0 commit comments

Comments
 (0)