mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 05:38:46 +00:00
Merge #4534
4534: Add call postfix completion r=matklad a=vain0x To make it easier to wrap an expression with Ok/Some/Rc::new etc. Note I agree with conclusion of the discussion in #1431 that adding many completions is not the way to go. However, this PR still could be justified due to versatility of use. Co-authored-by: vain0x <vainzerox@gmail.com>
This commit is contained in:
commit
e3280eb4ae
1 changed files with 59 additions and 0 deletions
|
@ -184,6 +184,16 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
|
|||
&format!("dbg!({})", receiver_text),
|
||||
)
|
||||
.add_to(acc);
|
||||
|
||||
postfix_snippet(
|
||||
ctx,
|
||||
cap,
|
||||
&dot_receiver,
|
||||
"call",
|
||||
"function(expr)",
|
||||
&format!("${{1}}({})", receiver_text),
|
||||
)
|
||||
.add_to(acc);
|
||||
}
|
||||
|
||||
fn get_receiver_text(receiver: &ast::Expr, receiver_is_ambiguous_float_literal: bool) -> String {
|
||||
|
@ -255,6 +265,13 @@ mod tests {
|
|||
insert: "Box::new(bar)",
|
||||
detail: "Box::new(expr)",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "call",
|
||||
source_range: 89..89,
|
||||
delete: 85..89,
|
||||
insert: "${1}(bar)",
|
||||
detail: "function(expr)",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "dbg",
|
||||
source_range: 89..89,
|
||||
|
@ -334,6 +351,13 @@ mod tests {
|
|||
insert: "Box::new(bar)",
|
||||
detail: "Box::new(expr)",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "call",
|
||||
source_range: 210..210,
|
||||
delete: 206..210,
|
||||
insert: "${1}(bar)",
|
||||
detail: "function(expr)",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "dbg",
|
||||
source_range: 210..210,
|
||||
|
@ -413,6 +437,13 @@ mod tests {
|
|||
insert: "Box::new(bar)",
|
||||
detail: "Box::new(expr)",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "call",
|
||||
source_range: 211..211,
|
||||
delete: 207..211,
|
||||
insert: "${1}(bar)",
|
||||
detail: "function(expr)",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "dbg",
|
||||
source_range: 211..211,
|
||||
|
@ -487,6 +518,13 @@ mod tests {
|
|||
insert: "Box::new(bar)",
|
||||
detail: "Box::new(expr)",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "call",
|
||||
source_range: 91..91,
|
||||
delete: 87..91,
|
||||
insert: "${1}(bar)",
|
||||
detail: "function(expr)",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "dbg",
|
||||
source_range: 91..91,
|
||||
|
@ -546,6 +584,13 @@ mod tests {
|
|||
insert: "Box::new(42)",
|
||||
detail: "Box::new(expr)",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "call",
|
||||
source_range: 52..52,
|
||||
delete: 49..52,
|
||||
insert: "${1}(42)",
|
||||
detail: "function(expr)",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "dbg",
|
||||
source_range: 52..52,
|
||||
|
@ -607,6 +652,13 @@ mod tests {
|
|||
insert: "Box::new(bar)",
|
||||
detail: "Box::new(expr)",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "call",
|
||||
source_range: 149..150,
|
||||
delete: 145..150,
|
||||
insert: "${1}(bar)",
|
||||
detail: "function(expr)",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "dbg",
|
||||
source_range: 149..150,
|
||||
|
@ -666,6 +718,13 @@ mod tests {
|
|||
insert: "Box::new(&&&&42)",
|
||||
detail: "Box::new(expr)",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "call",
|
||||
source_range: 56..56,
|
||||
delete: 49..56,
|
||||
insert: "${1}(&&&&42)",
|
||||
detail: "function(expr)",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "dbg",
|
||||
source_range: 56..56,
|
||||
|
|
Loading…
Reference in a new issue