Skip to content

Commit 6a59e03

Browse files
committed
fix: completion type priority
1 parent 6b987f6 commit 6a59e03

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/renderer/utils/shell-integration.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,30 @@ function updateDecorationElement(decoration: IDecoration, callback: (el: HTMLEle
7979
}
8080
}
8181

82+
const completionTypePriority: Record<NonNullable<CommandCompletion['type']>, number> = {
83+
'third-party': 0,
84+
recommendation: 1,
85+
history: 2,
86+
directory: 3,
87+
file: 4,
88+
command: 5,
89+
default: Infinity,
90+
}
91+
92+
const completionTypeOrder = Object.entries(completionTypePriority)
93+
.sort((a, b) => a[1] - b[1])
94+
.map(([type, priority]) => type)
95+
96+
function determineCompletionType(
97+
a: CommandCompletion['type'],
98+
b: CommandCompletion['type'],
99+
): NonNullable<CommandCompletion['type']> {
100+
for (const type of completionTypeOrder) {
101+
if (a === type || b === type) return type
102+
}
103+
return 'default'
104+
}
105+
82106
function filterAndSortCompletions(completions: CommandCompletion[]) {
83107
const duplicatedTimes: (Pick<CommandCompletion, 'value' | 'query'> & { times: number })[] = []
84108
const deduplicatedCompletions: CommandCompletion[] = []
@@ -109,7 +133,7 @@ function filterAndSortCompletions(completions: CommandCompletion[]) {
109133
const existingItem = deduplicatedCompletions[existingIndex]
110134
const replacement = {
111135
...existingItem,
112-
type: 'default' as const,
136+
type: determineCompletionType(existingItem.type, completion.type),
113137
description: existingItem.description || completion.description,
114138
}
115139
deduplicatedCompletions.splice(existingIndex, 1, replacement)

0 commit comments

Comments
 (0)