Skip to content

Commit 3ca4c76

Browse files
Update sort order for supported methods and unsaved manual models
1 parent 7a68fcd commit 3ca4c76

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

extensions/ql-vscode/src/model-editor/shared/sorting.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { canMethodBeModeled } from "../method";
12
import type { Method } from "../method";
23
import type { ModeledMethod } from "../modeled-method";
34
import { 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
*/
8487
function 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
}

extensions/ql-vscode/test/unit-tests/model-editor/shared/sorting.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,31 @@ describe("sortMethods", () => {
1212
it("uses primary sort order", () => {
1313
const unsavedPositiveAutoModelPrediction = createMethod({
1414
signature: "org.sql2o.Sql2o#open1()",
15+
supported: false,
1516
});
1617
const negativeAutoModelPrediction = createMethod({
1718
signature: "org.sql2o.Sql2o#open2()",
19+
supported: false,
1820
});
1921
const unsavedManualModel = createMethod({
2022
signature: "org.sql2o.Sql2o#open3()",
23+
supported: false,
2124
});
2225
const unmodeledMethod = createMethod({
2326
signature: "org.sql2o.Sql2o#open4()",
27+
supported: false,
2428
});
2529
const savedAutoModelPrediction = createMethod({
2630
signature: "org.sql2o.Sql2o#open5()",
31+
supported: false,
2732
});
2833
const savedManualModel = createMethod({
2934
signature: "org.sql2o.Sql2o#open6()",
35+
supported: false,
36+
});
37+
const supportedMethod = createMethod({
38+
signature: "org.sql2o.Sql2o#open7()",
39+
supported: true,
3040
});
3141

3242
const methods: Method[] = shuffle([
@@ -36,6 +46,7 @@ describe("sortMethods", () => {
3646
unmodeledMethod,
3747
savedAutoModelPrediction,
3848
savedManualModel,
49+
supportedMethod,
3950
]);
4051

4152
const modeledMethodsMap: Record<string, readonly ModeledMethod[]> = {};
@@ -75,30 +86,36 @@ describe("sortMethods", () => {
7586
unmodeledMethod,
7687
savedAutoModelPrediction,
7788
savedManualModel,
89+
supportedMethod,
7890
]);
7991
});
8092

8193
it("uses secondary sort order based on usages and signature", () => {
8294
const negativeAutoModelPrediction = createMethod({
8395
signature: "org.sql2o.Sql2o#negative()",
96+
supported: false,
8497
usages: [],
8598
});
8699

87100
const unmodeledMethodWithTwoUsages = createMethod({
88101
signature: "org.sql2o.Sql2o#two()",
102+
supported: false,
89103
usages: [createUsage(), createUsage()],
90104
});
91105
const unmodeledMethodWithOneUsage = createMethod({
92106
signature: "org.sql2o.Sql2o#one()",
107+
supported: false,
93108
usages: [createUsage()],
94109
});
95110

96111
const unmodeledMethodWithEarlierSignature = createMethod({
97112
signature: "org.sql2o.Sql2o#aaa()",
113+
supported: false,
98114
usages: [],
99115
});
100116
const unmodeledMethodWithLaterSignature = createMethod({
101117
signature: "org.sql2o.Sql2o#bbb()",
118+
supported: false,
102119
usages: [],
103120
});
104121

0 commit comments

Comments
 (0)