From e18f00882dd75cd5d9e89fc76e1cf67bbeaf36c5 Mon Sep 17 00:00:00 2001 From: vain0x Date: Sat, 9 May 2020 16:14:33 +0900 Subject: Add call postfix completion To make it easier to wrap an expression with Ok/Some/Rc::new etc. --- crates/ra_ide/src/completion/complete_postfix.rs | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_postfix.rs b/crates/ra_ide/src/completion/complete_postfix.rs index f2a52a407..02e660ca8 100644 --- a/crates/ra_ide/src/completion/complete_postfix.rs +++ b/crates/ra_ide/src/completion/complete_postfix.rs @@ -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, -- cgit v1.2.3