diff options
Diffstat (limited to 'crates/ra_ide_api/src')
5 files changed, 52 insertions, 13 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index 48be812a0..e3bf82304 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs | |||
@@ -257,7 +257,8 @@ impl Builder { | |||
257 | // If not an import, add parenthesis automatically. | 257 | // If not an import, add parenthesis automatically. |
258 | if ctx.use_item_syntax.is_none() && !ctx.is_call { | 258 | if ctx.use_item_syntax.is_none() && !ctx.is_call { |
259 | tested_by!(inserts_parens_for_function_calls); | 259 | tested_by!(inserts_parens_for_function_calls); |
260 | if function.signature(ctx.db).params().is_empty() { | 260 | let sig = function.signature(ctx.db); |
261 | if sig.params().is_empty() || sig.has_self_param() && sig.params().len() == 1 { | ||
261 | self.insert_text = Some(format!("{}()$0", self.label)); | 262 | self.insert_text = Some(format!("{}()$0", self.label)); |
262 | } else { | 263 | } else { |
263 | self.insert_text = Some(format!("{}($0)", self.label)); | 264 | self.insert_text = Some(format!("{}($0)", self.label)); |
@@ -374,6 +375,18 @@ mod tests { | |||
374 | fn main() { with_<|> } | 375 | fn main() { with_<|> } |
375 | ", | 376 | ", |
376 | ); | 377 | ); |
378 | check_reference_completion( | ||
379 | "inserts_parens_for_function_calls3", | ||
380 | r" | ||
381 | struct S {} | ||
382 | impl S { | ||
383 | fn foo(&self) {} | ||
384 | } | ||
385 | fn bar(s: &S) { | ||
386 | s.f<|> | ||
387 | } | ||
388 | ", | ||
389 | ) | ||
377 | } | 390 | } |
378 | 391 | ||
379 | #[test] | 392 | #[test] |
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls3.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls3.snap new file mode 100644 index 000000000..92068e50a --- /dev/null +++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls3.snap | |||
@@ -0,0 +1,26 @@ | |||
1 | --- | ||
2 | created: "2019-01-23T13:19:23.525922020+00:00" | ||
3 | creator: [email protected] | ||
4 | expression: kind_completions | ||
5 | source: crates/ra_ide_api/src/completion/completion_item.rs | ||
6 | --- | ||
7 | [ | ||
8 | CompletionItem { | ||
9 | completion_kind: Reference, | ||
10 | label: "foo", | ||
11 | kind: Some( | ||
12 | Method | ||
13 | ), | ||
14 | detail: Some( | ||
15 | "fn foo(&self)" | ||
16 | ), | ||
17 | documentation: None, | ||
18 | lookup: None, | ||
19 | insert_text: Some( | ||
20 | "foo()$0" | ||
21 | ), | ||
22 | insert_text_format: Snippet, | ||
23 | source_range: [139; 140), | ||
24 | text_edit: None | ||
25 | } | ||
26 | ] | ||
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap index ffeac0bf4..10fe59248 100644 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap +++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap | |||
@@ -1,8 +1,8 @@ | |||
1 | --- | 1 | --- |
2 | created: "2019-01-22T15:38:19.541947400+00:00" | 2 | created: "2019-01-23T13:19:23.501258181+00:00" |
3 | creator: insta@0.4.0 | 3 | creator: insta@0.5.2 |
4 | expression: kind_completions | 4 | expression: kind_completions |
5 | source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" | 5 | source: crates/ra_ide_api/src/completion/completion_item.rs |
6 | --- | 6 | --- |
7 | [ | 7 | [ |
8 | CompletionItem { | 8 | CompletionItem { |
@@ -17,7 +17,7 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" | |||
17 | documentation: None, | 17 | documentation: None, |
18 | lookup: None, | 18 | lookup: None, |
19 | insert_text: Some( | 19 | insert_text: Some( |
20 | "the_method($0)" | 20 | "the_method()$0" |
21 | ), | 21 | ), |
22 | insert_text_format: Snippet, | 22 | insert_text_format: Snippet, |
23 | source_range: [144; 144), | 23 | source_range: [144; 144), |
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap index 5ef140b28..5f5df0033 100644 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap +++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap | |||
@@ -1,8 +1,8 @@ | |||
1 | --- | 1 | --- |
2 | created: "2019-01-22T15:38:19.541947400+00:00" | 2 | created: "2019-01-23T13:19:23.501353210+00:00" |
3 | creator: insta@0.4.0 | 3 | creator: insta@0.5.2 |
4 | expression: kind_completions | 4 | expression: kind_completions |
5 | source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" | 5 | source: crates/ra_ide_api/src/completion/completion_item.rs |
6 | --- | 6 | --- |
7 | [ | 7 | [ |
8 | CompletionItem { | 8 | CompletionItem { |
@@ -33,7 +33,7 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" | |||
33 | documentation: None, | 33 | documentation: None, |
34 | lookup: None, | 34 | lookup: None, |
35 | insert_text: Some( | 35 | insert_text: Some( |
36 | "foo($0)" | 36 | "foo()$0" |
37 | ), | 37 | ), |
38 | insert_text_format: Snippet, | 38 | insert_text_format: Snippet, |
39 | source_range: [126; 126), | 39 | source_range: [126; 126), |
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap index b7903c5bc..80e8f3df5 100644 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap +++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap | |||
@@ -1,8 +1,8 @@ | |||
1 | --- | 1 | --- |
2 | created: "2019-01-22T15:38:19.541947400+00:00" | 2 | created: "2019-01-23T13:19:23.501297515+00:00" |
3 | creator: insta@0.4.0 | 3 | creator: insta@0.5.2 |
4 | expression: kind_completions | 4 | expression: kind_completions |
5 | source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" | 5 | source: crates/ra_ide_api/src/completion/completion_item.rs |
6 | --- | 6 | --- |
7 | [ | 7 | [ |
8 | CompletionItem { | 8 | CompletionItem { |
@@ -33,7 +33,7 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" | |||
33 | documentation: None, | 33 | documentation: None, |
34 | lookup: None, | 34 | lookup: None, |
35 | insert_text: Some( | 35 | insert_text: Some( |
36 | "foo($0)" | 36 | "foo()$0" |
37 | ), | 37 | ), |
38 | insert_text_format: Snippet, | 38 | insert_text_format: Snippet, |
39 | source_range: [121; 121), | 39 | source_range: [121; 121), |