Perform filtering before sorting when determining auto-model candidates

This commit is contained in:
Robert
2024-02-20 14:24:13 +00:00
parent 3598b1871f
commit 8f3ab61422

View File

@@ -24,39 +24,33 @@ export function getCandidates(
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),
);
const candidateMethods = methods.filter((method) => {
// Filter out any methods already processed by auto-model
if (processedByAutoModelMethods.has(method.signature)) {
return false;
}
// 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);
const sortedMethods = sortedGroupNames.flatMap((name) =>
sortMethods(grouped[name]),
);
const candidates: MethodSignature[] = [];
for (const method of sortedMethods) {
const modeledMethods: ModeledMethod[] = [
...(modeledMethodsBySignature[method.signature] ?? []),
];
// Anything that is modeled is not a candidate
if (modeledMethods.some((m) => m.type !== "none")) {
continue;
return false;
}
// A method that is supported is modeled outside of the model file, so it is not a candidate.
if (method.supported) {
continue;
return false;
}
// The rest are candidates
candidates.push(method);
}
return candidates;
return true;
});
// Sort the same way as the UI so we send the first ones listed in the UI first
const grouped = groupMethods(candidateMethods, mode);
const sortedGroupNames = sortGroupNames(grouped);
return sortedGroupNames.flatMap((name) => sortMethods(grouped[name]));
}
/**