Skip to content

Commit 993f9ac

Browse files
lazytanukiFrederik Vestre
authored and
Frederik Vestre
committed
feat(lsp): LSP preselected items appear first in completion menu (helix-editor#4480)
* feat(lsp): LSP preselected items appear first in completion menu * fix: shorter diff
1 parent 4da31f5 commit 993f9ac

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

helix-term/src/ui/completion.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,15 @@ impl Completion {
9292

9393
pub fn new(
9494
editor: &Editor,
95-
items: Vec<CompletionItem>,
95+
mut items: Vec<CompletionItem>,
9696
offset_encoding: helix_lsp::OffsetEncoding,
9797
start_offset: usize,
9898
trigger_offset: usize,
9999
) -> Self {
100+
// Sort completion items according to their preselect status (given by the LSP server)
101+
items.sort_by_key(|item| !item.preselect.unwrap_or(false));
102+
103+
// Then create the menu
100104
let menu = Menu::new(items, (), move |editor: &mut Editor, item, event| {
101105
fn item_to_transaction(
102106
doc: &Document,

helix-term/src/ui/menu.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ impl<T: Item> Menu<T> {
108108
.map(|score| (index, score))
109109
}),
110110
);
111-
self.matches.sort_unstable_by_key(|(_, score)| -score);
111+
// Order of equal elements needs to be preserved as LSP preselected items come in order of high to low priority
112+
self.matches.sort_by_key(|(_, score)| -score);
112113

113114
// reset cursor position
114115
self.cursor = None;

0 commit comments

Comments
 (0)