From e503ffe9ff175aa5f35facb107fcd985a8b1c4a4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 17 Feb 2019 21:30:46 +0300 Subject: Don't render `()` in calls to assoc functions --- .../src/completion/completion_context.rs | 13 ++++++------ .../ra_ide_api/src/completion/completion_item.rs | 11 ++++++++++ ...r_function_parens_if_already_call_assoc_fn.snap | 24 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call_assoc_fn.snap (limited to 'crates/ra_ide_api/src/completion') 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> { }; if let Some(segment) = ast::PathSegment::cast(parent) { let path = segment.parent_path(); + self.is_call = path + .syntax() + .parent() + .and_then(ast::PathExpr::cast) + .and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast)) + .is_some(); + if let Some(mut path) = hir::Path::from_ast(path) { if !path.is_ident() { path.segments.pop().unwrap(); @@ -176,12 +183,6 @@ impl<'a> CompletionContext<'a> { } } } - self.is_call = path - .syntax() - .parent() - .and_then(ast::PathExpr::cast) - .and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast)) - .is_some() } if let Some(field_expr) = ast::FieldExpr::cast(parent) { // 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 { frob<|>(); } ", + ); + check_reference_completion( + "dont_render_function_parens_if_already_call_assoc_fn", + " + //- /lib.rs + struct Foo {} + impl Foo { fn new() -> Foo {} } + fn main() { + Foo::ne<|>(); + } + ", ) } 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 @@ +--- +created: "2019-02-17T18:29:14.513213526Z" +creator: insta@0.6.2 +source: crates/ra_ide_api/src/completion/completion_item.rs +expression: kind_completions +--- +[ + CompletionItem { + completion_kind: Reference, + label: "new", + kind: Some( + Method + ), + detail: Some( + "fn new() -> Foo" + ), + documentation: None, + lookup: None, + insert_text: None, + insert_text_format: PlainText, + source_range: [67; 69), + text_edit: None + } +] -- cgit v1.2.3