Skip to content

Commit 00211cb

Browse files
committed
Revert "Move git branch boost after score comparison to avoid global prioritization"
This reverts commit b3275ed.
1 parent b3275ed commit 00211cb

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalCompletionModel.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,6 @@ const compareCompletionsFn = (leadingLineContent: string, a: TerminalCompletionI
4444
return score;
4545
}
4646

47-
// Boost main and master branches for git commands (only when scores are equal)
48-
// HACK: Currently this just matches leading line content, it should eventually check the
49-
// completion type is a branch
50-
if (a.completion.kind === TerminalCompletionItemKind.Method && b.completion.kind === TerminalCompletionItemKind.Method && /^\s*git\b/.test(leadingLineContent)) {
51-
const aLabel = typeof a.completion.label === 'string' ? a.completion.label : a.completion.label.label;
52-
const bLabel = typeof b.completion.label === 'string' ? b.completion.label : b.completion.label.label;
53-
const aIsMainOrMaster = aLabel === 'main' || aLabel === 'master';
54-
const bIsMainOrMaster = bLabel === 'main' || bLabel === 'master';
55-
56-
if (aIsMainOrMaster && !bIsMainOrMaster) {
57-
return -1;
58-
}
59-
if (bIsMainOrMaster && !aIsMainOrMaster) {
60-
return 1;
61-
}
62-
}
63-
6447
// Boost inline completions
6548
if (a.completion.kind === TerminalCompletionItemKind.InlineSuggestion && a.completion.kind !== b.completion.kind) {
6649
return -1;
@@ -98,6 +81,23 @@ const compareCompletionsFn = (leadingLineContent: string, a: TerminalCompletionI
9881
}
9982
}
10083

84+
// Boost main and master branches for git commands
85+
// HACK: Currently this just matches leading line content, it should eventually check the
86+
// completion type is a branch
87+
if (a.completion.kind === TerminalCompletionItemKind.Method && b.completion.kind === TerminalCompletionItemKind.Method && /^\s*git\b/.test(leadingLineContent)) {
88+
const aLabel = typeof a.completion.label === 'string' ? a.completion.label : a.completion.label.label;
89+
const bLabel = typeof b.completion.label === 'string' ? b.completion.label : b.completion.label.label;
90+
const aIsMainOrMaster = aLabel === 'main' || aLabel === 'master';
91+
const bIsMainOrMaster = bLabel === 'main' || bLabel === 'master';
92+
93+
if (aIsMainOrMaster && !bIsMainOrMaster) {
94+
return -1;
95+
}
96+
if (bIsMainOrMaster && !aIsMainOrMaster) {
97+
return 1;
98+
}
99+
}
100+
101101
// Sort by more detailed completions
102102
if (a.completion.kind === TerminalCompletionItemKind.Method && b.completion.kind === TerminalCompletionItemKind.Method) {
103103
if (typeof a.completion.label !== 'string' && a.completion.label.description && typeof b.completion.label !== 'string' && b.completion.label.description) {

src/vs/workbench/contrib/terminalContrib/suggest/test/browser/terminalCompletionModel.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,11 @@ suite('TerminalCompletionModel', function () {
348348
createItem({ label: { label: 'main', description: 'Main branch' } })
349349
];
350350
const model = new TerminalCompletionModel(items, new LineContext('git checkout ', 0));
351-
assertItems(model, ['main', 'master', 'feature-branch']);
351+
assertItems(model, [
352+
{ label: "main", description: "Main branch" },
353+
{ label: "master", description: "Master branch" },
354+
{ label: "feature-branch", description: "Feature branch" },
355+
]);
352356
});
353357
});
354358
});

0 commit comments

Comments
 (0)