aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorlazytanuki2022-10-27 14:16:55 +0000
committerGitHub2022-10-27 14:16:55 +0000
commitb4a3dd8f89d6b3c1c973be2dfb2121c4b6cb501f (patch)
treec26f454084b198724e88d67452cd9a00db1f6445 /helix-term/src
parentb1ffbbd49fd54525c55252162b5897d4ad4e990d (diff)
feat(lsp): LSP preselected items appear first in completion menu (#4480)
* feat(lsp): LSP preselected items appear first in completion menu * fix: shorter diff
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/ui/completion.rs6
-rw-r--r--helix-term/src/ui/menu.rs3
2 files changed, 7 insertions, 2 deletions
diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs
index a21767f9..de7c3232 100644
--- a/helix-term/src/ui/completion.rs
+++ b/helix-term/src/ui/completion.rs
@@ -92,11 +92,15 @@ impl Completion {
pub fn new(
editor: &Editor,
- items: Vec<CompletionItem>,
+ mut items: Vec<CompletionItem>,
offset_encoding: helix_lsp::OffsetEncoding,
start_offset: usize,
trigger_offset: usize,
) -> 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| {
fn item_to_transaction(
doc: &Document,
diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs
index 75769b90..99c2473d 100644
--- a/helix-term/src/ui/menu.rs
+++ b/helix-term/src/ui/menu.rs
@@ -108,7 +108,8 @@ impl<T: Item> Menu<T> {
.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
self.cursor = None;