don't insert parens for self methods

This commit is contained in:
Aleksey Kladov 2019-01-23 16:21:20 +03:00
parent 2dbf58c579
commit 71b9f06c89
5 changed files with 52 additions and 13 deletions

View File

@ -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]

View File

@ -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
}
]

View File

@ -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),

View File

@ -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),

View File

@ -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),