From 88d243c742ecd724372c4293b6b6ea293bae2d17 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 24 Apr 2020 01:52:26 +0200 Subject: [PATCH] Don't set sortText I might be reading this wrong, but it looks like we are setting it to essentially arbitrary string at the moment, as there are no defined order on the items in the *set* of completions. --- crates/rust-analyzer/src/conv.rs | 21 +++++++------------ .../rust-analyzer/src/main_loop/handlers.rs | 7 ++----- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/crates/rust-analyzer/src/conv.rs b/crates/rust-analyzer/src/conv.rs index 7e30956cc30..098ee369c2a 100644 --- a/crates/rust-analyzer/src/conv.rs +++ b/crates/rust-analyzer/src/conv.rs @@ -9,10 +9,10 @@ use lsp_types::{ TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, WorkspaceEdit, }; use ra_ide::{ - translate_offset_with_edit, CompletionItem, CompletionItemKind, CompletionScore, FileId, - FilePosition, FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HighlightModifier, - HighlightTag, InlayHint, InlayKind, InsertTextFormat, LineCol, LineIndex, NavigationTarget, - RangeInfo, ReferenceAccess, Severity, SourceChange, SourceFileEdit, + translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition, + FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HighlightModifier, HighlightTag, + InlayHint, InlayKind, InsertTextFormat, LineCol, LineIndex, NavigationTarget, RangeInfo, + ReferenceAccess, Severity, SourceChange, SourceFileEdit, }; use ra_syntax::{SyntaxKind, TextRange, TextUnit}; use ra_text_edit::{AtomTextEdit, TextEdit}; @@ -114,10 +114,10 @@ impl Conv for Severity { } } -impl ConvWith<(&LineIndex, LineEndings, &mut usize)> for CompletionItem { +impl ConvWith<(&LineIndex, LineEndings)> for CompletionItem { type Output = ::lsp_types::CompletionItem; - fn conv_with(self, ctx: (&LineIndex, LineEndings, &mut usize)) -> ::lsp_types::CompletionItem { + fn conv_with(self, ctx: (&LineIndex, LineEndings)) -> ::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 @@ -165,13 +165,8 @@ impl ConvWith<(&LineIndex, LineEndings, &mut usize)> for CompletionItem { ..Default::default() }; - if let Some(score) = self.score() { - match score { - CompletionScore::TypeAndNameMatch => res.preselect = Some(true), - CompletionScore::TypeMatch => {} - } - res.sort_text = Some(format!("{:02}", *ctx.2)); - *ctx.2 += 1; + if self.score().is_some() { + res.preselect = Some(true) } if self.deprecated() { diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index ee669f38321..41d9fe344d4 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs @@ -423,11 +423,8 @@ 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() - .map(|item| item.conv_with((&line_index, line_endings, &mut count_sort_text_item))) - .collect(); + let items: Vec = + items.into_iter().map(|item| item.conv_with((&line_index, line_endings))).collect(); Ok(Some(items.into())) }