Improve autocompletion by looking on the type and name

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
This commit is contained in:
Benjamin Coenen 2020-04-21 17:19:18 +02:00
parent b6a7be19d9
commit da6b136ea5
2 changed files with 6 additions and 5 deletions

View file

@ -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() {

View file

@ -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<CompletionItem> = 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()))