mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
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:
parent
b6a7be19d9
commit
da6b136ea5
2 changed files with 6 additions and 5 deletions
|
@ -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;
|
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 additional_text_edits = Vec::new();
|
||||||
let mut text_edit = None;
|
let mut text_edit = None;
|
||||||
// LSP does not allow arbitrary edits in completion, so we have to do a
|
// 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::TypeAndNameMatch => res.preselect = Some(true),
|
||||||
CompletionScore::TypeMatch => {}
|
CompletionScore::TypeMatch => {}
|
||||||
}
|
}
|
||||||
res.sort_text = Some(format!("{:02}", ctx.2));
|
res.sort_text = Some(format!("{:02}", *ctx.2));
|
||||||
|
*ctx.2 += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.deprecated() {
|
if self.deprecated() {
|
||||||
|
|
|
@ -423,10 +423,10 @@ pub fn handle_completion(
|
||||||
};
|
};
|
||||||
let line_index = world.analysis().file_line_index(position.file_id)?;
|
let line_index = world.analysis().file_line_index(position.file_id)?;
|
||||||
let line_endings = world.file_line_endings(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
|
let items: Vec<CompletionItem> = items
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate()
|
.map(|item| item.conv_with((&line_index, line_endings, &mut count_sort_text_item)))
|
||||||
.map(|(idx, item)| item.conv_with((&line_index, line_endings, idx)))
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Ok(Some(items.into()))
|
Ok(Some(items.into()))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue