Skip to content

Commit b3275ed

Browse files
CopilotTyriar
andcommitted
Move git branch boost after score comparison to avoid global prioritization
Co-authored-by: Tyriar <[email protected]>
1 parent eb0eb3c commit b3275ed

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
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,6 +44,23 @@ 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+
4764
// Boost inline completions
4865
if (a.completion.kind === TerminalCompletionItemKind.InlineSuggestion && a.completion.kind !== b.completion.kind) {
4966
return -1;
@@ -81,23 +98,6 @@ const compareCompletionsFn = (leadingLineContent: string, a: TerminalCompletionI
8198
}
8299
}
83100

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: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,7 @@ 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, [
352-
{ label: "main", description: "Main branch" },
353-
{ label: "master", description: "Master branch" },
354-
{ label: "feature-branch", description: "Feature branch" },
355-
]);
351+
assertItems(model, ['main', 'master', 'feature-branch']);
356352
});
357353
});
358354
});

0 commit comments

Comments
 (0)