From da6b136ea5b0e37d3dae9b78f3dbff2f18a9e5ea Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Tue, 21 Apr 2020 17:19:18 +0200 Subject: Improve autocompletion by looking on the type and name Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/rust-analyzer/src/conv.rs | 7 ++++--- crates/rust-analyzer/src/main_loop/handlers.rs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/conv.rs b/crates/rust-analyzer/src/conv.rs index d0218dcbf..7e30956cc 100644 --- a/crates/rust-analyzer/src/conv.rs +++ b/crates/rust-analyzer/src/conv.rs @@ -114,10 +114,10 @@ impl Conv for Severity { } } -impl ConvWith<(&LineIndex, LineEndings, usize)> for CompletionItem { +impl ConvWith<(&LineIndex, LineEndings, &mut usize)> for CompletionItem { type Output = ::lsp_types::CompletionItem; - fn conv_with(self, ctx: (&LineIndex, LineEndings, usize)) -> ::lsp_types::CompletionItem { + fn conv_with(self, ctx: (&LineIndex, LineEndings, &mut usize)) -> ::lsp_types::CompletionItem { let mut additional_text_edits = Vec::new(); let mut text_edit = None; // LSP does not allow arbitrary edits in completion, so we have to do a @@ -170,7 +170,8 @@ impl ConvWith<(&LineIndex, LineEndings, usize)> for CompletionItem { CompletionScore::TypeAndNameMatch => res.preselect = Some(true), CompletionScore::TypeMatch => {} } - res.sort_text = Some(format!("{:02}", ctx.2)); + res.sort_text = Some(format!("{:02}", *ctx.2)); + *ctx.2 += 1; } if self.deprecated() { diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index d18d2de34..08f5ad47c 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs @@ -423,10 +423,10 @@ pub fn handle_completion( }; let line_index = world.analysis().file_line_index(position.file_id)?; let line_endings = world.file_line_endings(position.file_id); + let mut count_sort_text_item = 0usize; let items: Vec = items .into_iter() - .enumerate() - .map(|(idx, item)| item.conv_with((&line_index, line_endings, idx))) + .map(|item| item.conv_with((&line_index, line_endings, &mut count_sort_text_item))) .collect(); Ok(Some(items.into())) -- cgit v1.2.3