aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/completion')
-rw-r--r--crates/ra_ide_api/src/completion/completion_context.rs13
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs11
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call_assoc_fn.snap24
3 files changed, 42 insertions, 6 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs
index 82bd4d606..b9f0abe19 100644
--- a/crates/ra_ide_api/src/completion/completion_context.rs
+++ b/crates/ra_ide_api/src/completion/completion_context.rs
@@ -137,6 +137,13 @@ impl<'a> CompletionContext<'a> {
137 }; 137 };
138 if let Some(segment) = ast::PathSegment::cast(parent) { 138 if let Some(segment) = ast::PathSegment::cast(parent) {
139 let path = segment.parent_path(); 139 let path = segment.parent_path();
140 self.is_call = path
141 .syntax()
142 .parent()
143 .and_then(ast::PathExpr::cast)
144 .and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast))
145 .is_some();
146
140 if let Some(mut path) = hir::Path::from_ast(path) { 147 if let Some(mut path) = hir::Path::from_ast(path) {
141 if !path.is_ident() { 148 if !path.is_ident() {
142 path.segments.pop().unwrap(); 149 path.segments.pop().unwrap();
@@ -176,12 +183,6 @@ impl<'a> CompletionContext<'a> {
176 } 183 }
177 } 184 }
178 } 185 }
179 self.is_call = path
180 .syntax()
181 .parent()
182 .and_then(ast::PathExpr::cast)
183 .and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast))
184 .is_some()
185 } 186 }
186 if let Some(field_expr) = ast::FieldExpr::cast(parent) { 187 if let Some(field_expr) = ast::FieldExpr::cast(parent) {
187 // The receiver comes before the point of insertion of the fake 188 // The receiver comes before the point of insertion of the fake
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index 6003e1d89..ed0b0b7e5 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -427,6 +427,17 @@ mod tests {
427 frob<|>(); 427 frob<|>();
428 } 428 }
429 ", 429 ",
430 );
431 check_reference_completion(
432 "dont_render_function_parens_if_already_call_assoc_fn",
433 "
434 //- /lib.rs
435 struct Foo {}
436 impl Foo { fn new() -> Foo {} }
437 fn main() {
438 Foo::ne<|>();
439 }
440 ",
430 ) 441 )
431 } 442 }
432 443
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call_assoc_fn.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call_assoc_fn.snap
new file mode 100644
index 000000000..18a187c6f
--- /dev/null
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call_assoc_fn.snap
@@ -0,0 +1,24 @@
1---
2created: "2019-02-17T18:29:14.513213526Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions
6---
7[
8 CompletionItem {
9 completion_kind: Reference,
10 label: "new",
11 kind: Some(
12 Method
13 ),
14 detail: Some(
15 "fn new() -> Foo"
16 ),
17 documentation: None,
18 lookup: None,
19 insert_text: None,
20 insert_text_format: PlainText,
21 source_range: [67; 69),
22 text_edit: None
23 }
24]