mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
don't insert parens for self methods
This commit is contained in:
parent
2dbf58c579
commit
71b9f06c89
5 changed files with 52 additions and 13 deletions
|
@ -257,7 +257,8 @@ impl Builder {
|
||||||
// If not an import, add parenthesis automatically.
|
// If not an import, add parenthesis automatically.
|
||||||
if ctx.use_item_syntax.is_none() && !ctx.is_call {
|
if ctx.use_item_syntax.is_none() && !ctx.is_call {
|
||||||
tested_by!(inserts_parens_for_function_calls);
|
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));
|
self.insert_text = Some(format!("{}()$0", self.label));
|
||||||
} else {
|
} else {
|
||||||
self.insert_text = Some(format!("{}($0)", self.label));
|
self.insert_text = Some(format!("{}($0)", self.label));
|
||||||
|
@ -374,6 +375,18 @@ mod tests {
|
||||||
fn main() { with_<|> }
|
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]
|
#[test]
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
]
|
|
@ -1,8 +1,8 @@
|
||||||
---
|
---
|
||||||
created: "2019-01-22T15:38:19.541947400+00:00"
|
created: "2019-01-23T13:19:23.501258181+00:00"
|
||||||
creator: insta@0.4.0
|
creator: insta@0.5.2
|
||||||
expression: kind_completions
|
expression: kind_completions
|
||||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
source: crates/ra_ide_api/src/completion/completion_item.rs
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
CompletionItem {
|
CompletionItem {
|
||||||
|
@ -17,7 +17,7 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||||
documentation: None,
|
documentation: None,
|
||||||
lookup: None,
|
lookup: None,
|
||||||
insert_text: Some(
|
insert_text: Some(
|
||||||
"the_method($0)"
|
"the_method()$0"
|
||||||
),
|
),
|
||||||
insert_text_format: Snippet,
|
insert_text_format: Snippet,
|
||||||
source_range: [144; 144),
|
source_range: [144; 144),
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
---
|
---
|
||||||
created: "2019-01-22T15:38:19.541947400+00:00"
|
created: "2019-01-23T13:19:23.501353210+00:00"
|
||||||
creator: insta@0.4.0
|
creator: insta@0.5.2
|
||||||
expression: kind_completions
|
expression: kind_completions
|
||||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
source: crates/ra_ide_api/src/completion/completion_item.rs
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
CompletionItem {
|
CompletionItem {
|
||||||
|
@ -33,7 +33,7 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||||
documentation: None,
|
documentation: None,
|
||||||
lookup: None,
|
lookup: None,
|
||||||
insert_text: Some(
|
insert_text: Some(
|
||||||
"foo($0)"
|
"foo()$0"
|
||||||
),
|
),
|
||||||
insert_text_format: Snippet,
|
insert_text_format: Snippet,
|
||||||
source_range: [126; 126),
|
source_range: [126; 126),
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
---
|
---
|
||||||
created: "2019-01-22T15:38:19.541947400+00:00"
|
created: "2019-01-23T13:19:23.501297515+00:00"
|
||||||
creator: insta@0.4.0
|
creator: insta@0.5.2
|
||||||
expression: kind_completions
|
expression: kind_completions
|
||||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
source: crates/ra_ide_api/src/completion/completion_item.rs
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
CompletionItem {
|
CompletionItem {
|
||||||
|
@ -33,7 +33,7 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||||
documentation: None,
|
documentation: None,
|
||||||
lookup: None,
|
lookup: None,
|
||||||
insert_text: Some(
|
insert_text: Some(
|
||||||
"foo($0)"
|
"foo()$0"
|
||||||
),
|
),
|
||||||
insert_text_format: Snippet,
|
insert_text_format: Snippet,
|
||||||
source_range: [121; 121),
|
source_range: [121; 121),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue