feat(lsp): LSP preselected items appear first in completion menu (#4480)

* feat(lsp): LSP preselected items appear first in completion menu

* fix: shorter diff
pull/4495/head
lazytanuki 2 years ago committed by GitHub
parent b1ffbbd49f
commit b4a3dd8f89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -92,11 +92,15 @@ impl Completion {
pub fn new( pub fn new(
editor: &Editor, editor: &Editor,
items: Vec<CompletionItem>, mut items: Vec<CompletionItem>,
offset_encoding: helix_lsp::OffsetEncoding, offset_encoding: helix_lsp::OffsetEncoding,
start_offset: usize, start_offset: usize,
trigger_offset: usize, trigger_offset: usize,
) -> Self { ) -> Self {
// Sort completion items according to their preselect status (given by the LSP server)
items.sort_by_key(|item| !item.preselect.unwrap_or(false));
// Then create the menu
let menu = Menu::new(items, (), move |editor: &mut Editor, item, event| { let menu = Menu::new(items, (), move |editor: &mut Editor, item, event| {
fn item_to_transaction( fn item_to_transaction(
doc: &Document, doc: &Document,

@ -108,7 +108,8 @@ impl<T: Item> Menu<T> {
.map(|score| (index, score)) .map(|score| (index, score))
}), }),
); );
self.matches.sort_unstable_by_key(|(_, score)| -score); // Order of equal elements needs to be preserved as LSP preselected items come in order of high to low priority
self.matches.sort_by_key(|(_, score)| -score);
// reset cursor position // reset cursor position
self.cursor = None; self.cursor = None;

Loading…
Cancel
Save