mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 04:23:25 +00:00
Selecting &mut foo
completion now actually inserts &mut
This commit is contained in:
parent
12fe301a0c
commit
73b9937e4e
1 changed files with 16 additions and 15 deletions
|
@ -175,12 +175,6 @@ pub(crate) fn completion_item(
|
|||
line_index: &LineIndex,
|
||||
item: CompletionItem,
|
||||
) -> Vec<lsp_types::CompletionItem> {
|
||||
fn set_score(lsp_item: &mut lsp_types::CompletionItem, label: &str) {
|
||||
lsp_item.preselect = Some(true);
|
||||
// HACK: sort preselect items first
|
||||
lsp_item.sort_text = Some(format!(" {}", label));
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -220,7 +214,9 @@ pub(crate) fn completion_item(
|
|||
};
|
||||
|
||||
if item.score().is_some() {
|
||||
set_score(&mut lsp_item, item.label());
|
||||
lsp_item.preselect = Some(true);
|
||||
// HACK: sort preselect items first
|
||||
lsp_item.sort_text = Some(format!(" {}", item.label()));
|
||||
}
|
||||
|
||||
if item.deprecated() {
|
||||
|
@ -233,11 +229,16 @@ pub(crate) fn completion_item(
|
|||
|
||||
let mut res = match item.ref_match() {
|
||||
Some(mutability) => {
|
||||
let mut refed = lsp_item.clone();
|
||||
let label = format!("&{}{}", mutability.as_keyword_for_ref(), refed.label);
|
||||
set_score(&mut refed, &label);
|
||||
refed.label = label;
|
||||
vec![lsp_item, refed]
|
||||
let mut lsp_item_with_ref = lsp_item.clone();
|
||||
lsp_item.preselect = Some(true);
|
||||
lsp_item.sort_text = Some(format!(" {}", item.label()));
|
||||
lsp_item_with_ref.label =
|
||||
format!("&{}{}", mutability.as_keyword_for_ref(), lsp_item_with_ref.label);
|
||||
if let Some(lsp_types::CompletionTextEdit::Edit(it)) = &mut lsp_item_with_ref.text_edit
|
||||
{
|
||||
it.new_text = format!("&{}{}", mutability.as_keyword_for_ref(), it.new_text);
|
||||
}
|
||||
vec![lsp_item_with_ref, lsp_item]
|
||||
}
|
||||
None => vec![lsp_item],
|
||||
};
|
||||
|
@ -1104,13 +1105,13 @@ mod tests {
|
|||
expect_test::expect![[r#"
|
||||
[
|
||||
(
|
||||
"arg",
|
||||
"&arg",
|
||||
None,
|
||||
),
|
||||
(
|
||||
"&arg",
|
||||
"arg",
|
||||
Some(
|
||||
" &arg",
|
||||
" arg",
|
||||
),
|
||||
),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue