From 8f3ab61422f09d141429431981bcdced1416ff7a Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 20 Feb 2024 14:24:13 +0000 Subject: [PATCH] Perform filtering before sorting when determining auto-model candidates --- .../ql-vscode/src/model-editor/auto-model.ts | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/extensions/ql-vscode/src/model-editor/auto-model.ts b/extensions/ql-vscode/src/model-editor/auto-model.ts index 42020db13..13a67954b 100644 --- a/extensions/ql-vscode/src/model-editor/auto-model.ts +++ b/extensions/ql-vscode/src/model-editor/auto-model.ts @@ -24,39 +24,33 @@ export function getCandidates( modeledMethodsBySignature: Record, processedByAutoModelMethods: Set, ): 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])); } /**