diff --git a/crates/rust-analyzer/src/conv.rs b/crates/rust-analyzer/src/conv.rs index d0218dcbf7..7e30956cc3 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 d18d2de348..08f5ad47c2 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()))