From 1ac934eafad34d8d665c8445981c146daa33ab50 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 30 Dec 2018 12:29:55 +0300 Subject: add paramthesis when completing functions --- .../ra_analysis/src/completion/complete_scope.rs | 36 +++++++++++++++++----- .../ra_analysis/src/completion/completion_item.rs | 13 ++++++-- 2 files changed, 39 insertions(+), 10 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/completion/complete_scope.rs b/crates/ra_analysis/src/completion/complete_scope.rs index 514fd2f88..cd98efe95 100644 --- a/crates/ra_analysis/src/completion/complete_scope.rs +++ b/crates/ra_analysis/src/completion/complete_scope.rs @@ -74,7 +74,7 @@ mod tests { let z = (); } ", - "y;x;quux", + r#"y;x;quux "quux($0)""#, ); } @@ -92,7 +92,7 @@ mod tests { } } ", - "b;a;quux", + r#"b;a;quux "quux()$0""#, ); } @@ -106,7 +106,7 @@ mod tests { } } ", - "x;quux", + r#"x;quux "quux()$0""#, ); } @@ -120,7 +120,7 @@ mod tests { <|> } ", - "quux;Foo;Baz", + r#"quux "quux()$0";Foo;Baz"#, ); } @@ -134,7 +134,7 @@ mod tests { fn quux() { <|> } } ", - "quux;Bar", + r#"quux "quux()$0";Bar"#, ); } @@ -145,12 +145,12 @@ mod tests { struct Foo; fn x() -> <|> ", - "Foo;x", + r#"Foo;x "x()$0""#, ) } #[test] - fn dont_show_to_completions_for_shadowing() { + fn dont_show_both_completions_for_shadowing() { check_reference_completion( r" fn foo() -> { @@ -161,7 +161,7 @@ mod tests { } } ", - "bar;foo", + r#"bar;foo "foo()$0""#, ) } @@ -169,4 +169,24 @@ mod tests { fn completes_self_in_methods() { check_reference_completion(r"impl S { fn foo(&self) { <|> } }", "self") } + + #[test] + fn inserts_parens_for_function_calls() { + check_reference_completion( + r" + fn no_args() {} + fn main() { no_<|> } + ", + r#"no_args "no_args()$0" + main "main()$0""#, + ); + check_reference_completion( + r" + fn with_args(x: i32, y: String) {} + fn main() { with_<|> } + ", + r#"main "main()$0" + with_args "with_args($0)""#, + ); + } } diff --git a/crates/ra_analysis/src/completion/completion_item.rs b/crates/ra_analysis/src/completion/completion_item.rs index 1d294c553..b8fa39ae3 100644 --- a/crates/ra_analysis/src/completion/completion_item.rs +++ b/crates/ra_analysis/src/completion/completion_item.rs @@ -138,9 +138,18 @@ impl Builder { .. } => CompletionItemKind::Enum, PerNs { - values: Some(hir::Def::Function(..)), + values: Some(hir::Def::Function(function)), .. - } => CompletionItemKind::Function, + } => { + if let Some(sig_info) = function.signature_info(db) { + if sig_info.params.is_empty() { + self.snippet = Some(format!("{}()$0", self.label)); + } else { + self.snippet = Some(format!("{}($0)", self.label)); + } + } + CompletionItemKind::Function + } _ => return self, }; self.kind = Some(kind); -- cgit v1.2.3