Don't send methods to AutoModel more than once

This commit is contained in:
Robert
2024-02-20 11:50:52 +00:00
parent bca4910bf2
commit dbdb561598
5 changed files with 75 additions and 4 deletions

View File

@@ -22,7 +22,13 @@ export function getCandidates(
mode: Mode,
methods: readonly Method[],
modeledMethodsBySignature: Record<string, readonly ModeledMethod[]>,
processedByAutoModelMethods: Set<string>,
): MethodSignature[] {
// Filter out any methods already processed by auto-model
methods = methods.filter(
(m) => !processedByAutoModelMethods.has(m.signature),
);
// Sort the same way as the UI so we send the first ones listed in the UI first
const grouped = groupMethods(methods, mode);
const sortedGroupNames = sortGroupNames(grouped);

View File

@@ -58,6 +58,7 @@ export class AutoModeler {
packageName: string,
methods: readonly Method[],
modeledMethods: Record<string, readonly ModeledMethod[]>,
processedByAutoModelMethods: Set<string>,
mode: Mode,
): Promise<void> {
if (this.jobs.has(packageName)) {
@@ -72,6 +73,7 @@ export class AutoModeler {
packageName,
methods,
modeledMethods,
processedByAutoModelMethods,
mode,
cancellationTokenSource,
);
@@ -105,6 +107,7 @@ export class AutoModeler {
packageName: string,
methods: readonly Method[],
modeledMethods: Record<string, readonly ModeledMethod[]>,
processedByAutoModelMethods: Set<string>,
mode: Mode,
cancellationTokenSource: CancellationTokenSource,
): Promise<void> {
@@ -114,7 +117,12 @@ export class AutoModeler {
await withProgress(async (progress) => {
// Fetch the candidates to send to the model
const allCandidateMethods = getCandidates(mode, methods, modeledMethods);
const allCandidateMethods = getCandidates(
mode,
methods,
modeledMethods,
processedByAutoModelMethods,
);
// If there are no candidates, there is nothing to model and we just return
if (allCandidateMethods.length === 0) {

View File

@@ -655,11 +655,14 @@ export class ModelEditorView extends AbstractWebview<
this.databaseItem,
methodSignatures,
);
const processedByAutoModelMethods =
this.modelingStore.getProcessedByAutoModelMethods(this.databaseItem);
const mode = this.modelingStore.getMode(this.databaseItem);
await this.autoModeler.startModeling(
packageName,
methods,
modeledMethods,
processedByAutoModelMethods,
mode,
);
}

View File

@@ -344,6 +344,20 @@ export class ModelingStore extends DisposableObject {
});
}
public getProcessedByAutoModelMethods(
dbItem: DatabaseItem,
methodSignatures?: string[],
): Set<string> {
const processedByAutoModelMethods =
this.getState(dbItem).processedByAutoModelMethods;
if (!methodSignatures) {
return processedByAutoModelMethods;
}
return new Set(
Array.from(processedByAutoModelMethods).filter(methodSignatures.includes),
);
}
public addProcessedByAutoModelMethods(
dbItem: DatabaseItem,
processedByAutoModelMethods: string[],

View File

@@ -116,7 +116,12 @@ describe("getCandidates", () => {
},
],
};
const candidates = getCandidates(Mode.Application, methods, modeledMethods);
const candidates = getCandidates(
Mode.Application,
methods,
modeledMethods,
new Set(),
);
expect(candidates.length).toEqual(0);
});
@@ -136,7 +141,37 @@ describe("getCandidates", () => {
},
];
const modeledMethods = {};
const candidates = getCandidates(Mode.Application, methods, modeledMethods);
const candidates = getCandidates(
Mode.Application,
methods,
modeledMethods,
new Set(),
);
expect(candidates.length).toEqual(0);
});
it("doesn't return methods that are already processed by auto model", () => {
const methods: Method[] = [
{
library: "my.jar",
signature: "org.my.A#x()",
endpointType: EndpointType.Method,
packageName: "org.my",
typeName: "A",
methodName: "x",
methodParameters: "()",
supported: false,
supportedType: "none",
usages: [],
},
];
const modeledMethods = {};
const candidates = getCandidates(
Mode.Application,
methods,
modeledMethods,
new Set(["org.my.A#x()"]),
);
expect(candidates.length).toEqual(0);
});
@@ -155,7 +190,12 @@ describe("getCandidates", () => {
usages: [],
});
const modeledMethods = {};
const candidates = getCandidates(Mode.Application, methods, modeledMethods);
const candidates = getCandidates(
Mode.Application,
methods,
modeledMethods,
new Set(),
);
expect(candidates.length).toEqual(1);
});
});