-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3377 from github/robertbrignull/disable-automodel…
…-button Disable the automodel button if there are no methods that can be modeled
- Loading branch information
Showing
6 changed files
with
194 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
extensions/ql-vscode/src/model-editor/shared/auto-model-candidates.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type { Method, MethodSignature } from "../method"; | ||
import type { ModeledMethod } from "../modeled-method"; | ||
import type { Mode } from "./mode"; | ||
import { groupMethods, sortGroupNames, sortMethods } from "./sorting"; | ||
|
||
/** | ||
* Return the candidates that the model should be run on. This includes limiting the number of | ||
* candidates to the candidate limit and filtering out anything that is already modeled and respecting | ||
* the order in the UI. | ||
* @param mode Whether it is application or framework mode. | ||
* @param methods all methods. | ||
* @param modeledMethodsBySignature the currently modeled methods. | ||
* @returns list of modeled methods that are candidates for modeling. | ||
*/ | ||
|
||
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); | ||
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; | ||
} | ||
|
||
// A method that is supported is modeled outside of the model file, so it is not a candidate. | ||
if (method.supported) { | ||
continue; | ||
} | ||
|
||
// The rest are candidates | ||
candidates.push(method); | ||
} | ||
return candidates; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.