Skip to content

Commit 8f3ab61

Browse files
Perform filtering before sorting when determining auto-model candidates
1 parent 3598b18 commit 8f3ab61

1 file changed

Lines changed: 14 additions & 20 deletions

File tree

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

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,33 @@ export function getCandidates(
2424
modeledMethodsBySignature: Record<string, readonly ModeledMethod[]>,
2525
processedByAutoModelMethods: Set<string>,
2626
): MethodSignature[] {
27-
// Filter out any methods already processed by auto-model
28-
methods = methods.filter(
29-
(m) => !processedByAutoModelMethods.has(m.signature),
30-
);
31-
32-
// Sort the same way as the UI so we send the first ones listed in the UI first
33-
const grouped = groupMethods(methods, mode);
34-
const sortedGroupNames = sortGroupNames(grouped);
35-
const sortedMethods = sortedGroupNames.flatMap((name) =>
36-
sortMethods(grouped[name]),
37-
);
38-
39-
const candidates: MethodSignature[] = [];
27+
const candidateMethods = methods.filter((method) => {
28+
// Filter out any methods already processed by auto-model
29+
if (processedByAutoModelMethods.has(method.signature)) {
30+
return false;
31+
}
4032

41-
for (const method of sortedMethods) {
4233
const modeledMethods: ModeledMethod[] = [
4334
...(modeledMethodsBySignature[method.signature] ?? []),
4435
];
4536

4637
// Anything that is modeled is not a candidate
4738
if (modeledMethods.some((m) => m.type !== "none")) {
48-
continue;
39+
return false;
4940
}
5041

5142
// A method that is supported is modeled outside of the model file, so it is not a candidate.
5243
if (method.supported) {
53-
continue;
44+
return false;
5445
}
5546

56-
// The rest are candidates
57-
candidates.push(method);
58-
}
59-
return candidates;
47+
return true;
48+
});
49+
50+
// Sort the same way as the UI so we send the first ones listed in the UI first
51+
const grouped = groupMethods(candidateMethods, mode);
52+
const sortedGroupNames = sortGroupNames(grouped);
53+
return sortedGroupNames.flatMap((name) => sortMethods(grouped[name]));
6054
}
6155

6256
/**

0 commit comments

Comments
 (0)