From 71b9f06c89735b78439d0720e314b71969c17eb3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 23 Jan 2019 16:21:20 +0300 Subject: don't insert parens for self methods --- .../ra_ide_api/src/completion/completion_item.rs | 15 ++++++++++++- ...n_item__inserts_parens_for_function_calls3.snap | 26 ++++++++++++++++++++++ .../completion_item__method_completion.snap | 8 +++---- ...on_item__struct_field_completion_autoderef.snap | 8 +++---- ...pletion_item__struct_field_completion_self.snap | 8 +++---- 5 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls3.snap (limited to 'crates/ra_ide_api/src/completion') 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 { // If not an import, add parenthesis automatically. if ctx.use_item_syntax.is_none() && !ctx.is_call { tested_by!(inserts_parens_for_function_calls); - if function.signature(ctx.db).params().is_empty() { + let sig = function.signature(ctx.db); + if sig.params().is_empty() || sig.has_self_param() && sig.params().len() == 1 { self.insert_text = Some(format!("{}()$0", self.label)); } else { self.insert_text = Some(format!("{}($0)", self.label)); @@ -374,6 +375,18 @@ mod tests { fn main() { with_<|> } ", ); + check_reference_completion( + "inserts_parens_for_function_calls3", + r" + struct S {} + impl S { + fn foo(&self) {} + } + fn bar(s: &S) { + s.f<|> + } + ", + ) } #[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 @@ +--- +created: "2019-01-23T13:19:23.525922020+00:00" +creator: insta@0.5.2 +expression: kind_completions +source: crates/ra_ide_api/src/completion/completion_item.rs +--- +[ + CompletionItem { + completion_kind: Reference, + label: "foo", + kind: Some( + Method + ), + detail: Some( + "fn foo(&self)" + ), + documentation: None, + lookup: None, + insert_text: Some( + "foo()$0" + ), + insert_text_format: Snippet, + source_range: [139; 140), + text_edit: None + } +] 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 @@ --- -created: "2019-01-22T15:38:19.541947400+00:00" -creator: insta@0.4.0 +created: "2019-01-23T13:19:23.501258181+00:00" +creator: insta@0.5.2 expression: kind_completions -source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" +source: crates/ra_ide_api/src/completion/completion_item.rs --- [ CompletionItem { @@ -17,7 +17,7 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" documentation: None, lookup: None, insert_text: Some( - "the_method($0)" + "the_method()$0" ), insert_text_format: Snippet, 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 @@ --- -created: "2019-01-22T15:38:19.541947400+00:00" -creator: insta@0.4.0 +created: "2019-01-23T13:19:23.501353210+00:00" +creator: insta@0.5.2 expression: kind_completions -source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" +source: crates/ra_ide_api/src/completion/completion_item.rs --- [ CompletionItem { @@ -33,7 +33,7 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" documentation: None, lookup: None, insert_text: Some( - "foo($0)" + "foo()$0" ), insert_text_format: Snippet, 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 @@ --- -created: "2019-01-22T15:38:19.541947400+00:00" -creator: insta@0.4.0 +created: "2019-01-23T13:19:23.501297515+00:00" +creator: insta@0.5.2 expression: kind_completions -source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" +source: crates/ra_ide_api/src/completion/completion_item.rs --- [ CompletionItem { @@ -33,7 +33,7 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" documentation: None, lookup: None, insert_text: Some( - "foo($0)" + "foo()$0" ), insert_text_format: Snippet, source_range: [121; 121), -- cgit v1.2.3