1+ import { canMethodBeModeled } from "../method" ;
12import type { Method } from "../method" ;
23import type { ModeledMethod } from "../modeled-method" ;
34import { Mode } from "./mode" ;
@@ -32,9 +33,9 @@ export function sortGroupNames(
3233 * Primarily sorts methods into the following order:
3334 * - Unsaved positive AutoModel predictions
3435 * - Negative AutoModel predictions
35- * - Unsaved manual models
36- * - Umodeled
37- * - Modeled and saved (AutoModel and manual)
36+ * - Unsaved manual models + unmodeled methods
37+ * - Saved models from this model pack (AutoModel and manual)
38+ * - Methods not modelable in this model pack
3839 *
3940 * Secondary sort order is by number of usages descending, then by method signature ascending.
4041 */
@@ -48,12 +49,14 @@ export function sortMethods(
4849 sortedMethods . sort ( ( a , b ) => {
4950 // First sort by the type of method
5051 const methodAPrimarySortOrdinal = getMethodPrimarySortOrdinal (
51- ! ! modeledMethodsMap [ a . signature ] ?. length ,
52+ a ,
53+ modeledMethodsMap [ a . signature ] ?? [ ] ,
5254 modifiedSignatures . has ( a . signature ) ,
5355 processedByAutoModelMethods . has ( a . signature ) ,
5456 ) ;
5557 const methodBPrimarySortOrdinal = getMethodPrimarySortOrdinal (
56- ! ! modeledMethodsMap [ b . signature ] ?. length ,
58+ b ,
59+ modeledMethodsMap [ b . signature ] ?? [ ] ,
5760 modifiedSignatures . has ( b . signature ) ,
5861 processedByAutoModelMethods . has ( b . signature ) ,
5962 ) ;
@@ -77,23 +80,28 @@ export function sortMethods(
7780 * Assigns numbers to the following classes of methods:
7881 * - Unsaved positive AutoModel predictions => 0
7982 * - Negative AutoModel predictions => 1
80- * - Unsaved manual models => 2
81- * - Umodeled => 3
82- * - Modeled and saved (AutoModel and manual) => 4
83+ * - Unsaved manual models + unmodeled methods => 2
84+ * - Saved models from this model pack (AutoModel and manual) => 3
85+ * - Methods not modelable in this model pack => 4
8386 */
8487function getMethodPrimarySortOrdinal (
85- isModeled : boolean ,
86- isModified : boolean ,
88+ method : Method ,
89+ modeledMethods : readonly ModeledMethod [ ] ,
90+ isUnsaved : boolean ,
8791 isProcessedByAutoModel : boolean ,
8892) : number {
89- if ( isModeled && isModified && isProcessedByAutoModel ) {
90- return 0 ;
91- } else if ( ! isModeled && isProcessedByAutoModel ) {
92- return 1 ;
93- } else if ( isModeled && isModified ) {
94- return 2 ;
95- } else if ( ! isModeled ) {
96- return 3 ;
93+ const canBeModeled = canMethodBeModeled ( method , modeledMethods , isUnsaved ) ;
94+ const isModeled = modeledMethods . length > 0 ;
95+ if ( canBeModeled ) {
96+ if ( isModeled && isUnsaved && isProcessedByAutoModel ) {
97+ return 0 ;
98+ } else if ( ! isModeled && isProcessedByAutoModel ) {
99+ return 1 ;
100+ } else if ( ( isModeled && isUnsaved ) || ! isModeled ) {
101+ return 2 ;
102+ } else {
103+ return 3 ;
104+ }
97105 } else {
98106 return 4 ;
99107 }
0 commit comments