diff options
Diffstat (limited to 'crates')
4 files changed, 26 insertions, 6 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 65bba6dc7..80d0b1663 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs | |||
@@ -16,7 +16,7 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Ca | |||
16 | None => return Ok(()), | 16 | None => return Ok(()), |
17 | }; | 17 | }; |
18 | let receiver_ty = infer_result[expr].clone(); | 18 | let receiver_ty = infer_result[expr].clone(); |
19 | if !ctx.is_method_call { | 19 | if !ctx.is_call { |
20 | complete_fields(acc, ctx, receiver_ty)?; | 20 | complete_fields(acc, ctx, receiver_ty)?; |
21 | } | 21 | } |
22 | Ok(()) | 22 | Ok(()) |
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 4723a65a6..2494d28ed 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -125,4 +125,18 @@ mod tests { | |||
125 | "foo", | 125 | "foo", |
126 | ) | 126 | ) |
127 | } | 127 | } |
128 | |||
129 | #[test] | ||
130 | fn dont_render_function_parens_if_already_call() { | ||
131 | check_reference_completion( | ||
132 | " | ||
133 | //- /lib.rs | ||
134 | fn frobnicate() {} | ||
135 | fn main() { | ||
136 | frob<|>(); | ||
137 | } | ||
138 | ", | ||
139 | "main;frobnicate", | ||
140 | ) | ||
141 | } | ||
128 | } | 142 | } |
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index 01786bb69..113f6c070 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs | |||
@@ -32,8 +32,8 @@ pub(super) struct CompletionContext<'a> { | |||
32 | pub(super) is_new_item: bool, | 32 | pub(super) is_new_item: bool, |
33 | /// The receiver if this is a field or method access, i.e. writing something.<|> | 33 | /// The receiver if this is a field or method access, i.e. writing something.<|> |
34 | pub(super) dot_receiver: Option<&'a ast::Expr>, | 34 | pub(super) dot_receiver: Option<&'a ast::Expr>, |
35 | /// If this is a method call in particular, i.e. the () are already there. | 35 | /// If this is a call (method or function) in particular, i.e. the () are already there. |
36 | pub(super) is_method_call: bool, | 36 | pub(super) is_call: bool, |
37 | } | 37 | } |
38 | 38 | ||
39 | impl<'a> CompletionContext<'a> { | 39 | impl<'a> CompletionContext<'a> { |
@@ -60,7 +60,7 @@ impl<'a> CompletionContext<'a> { | |||
60 | can_be_stmt: false, | 60 | can_be_stmt: false, |
61 | is_new_item: false, | 61 | is_new_item: false, |
62 | dot_receiver: None, | 62 | dot_receiver: None, |
63 | is_method_call: false, | 63 | is_call: false, |
64 | }; | 64 | }; |
65 | ctx.fill(original_file, position.offset); | 65 | ctx.fill(original_file, position.offset); |
66 | Ok(Some(ctx)) | 66 | Ok(Some(ctx)) |
@@ -172,6 +172,12 @@ impl<'a> CompletionContext<'a> { | |||
172 | } | 172 | } |
173 | } | 173 | } |
174 | } | 174 | } |
175 | self.is_call = path | ||
176 | .syntax() | ||
177 | .parent() | ||
178 | .and_then(ast::PathExpr::cast) | ||
179 | .and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast)) | ||
180 | .is_some() | ||
175 | } | 181 | } |
176 | if let Some(field_expr) = ast::FieldExpr::cast(parent) { | 182 | if let Some(field_expr) = ast::FieldExpr::cast(parent) { |
177 | // The receiver comes before the point of insertion of the fake | 183 | // The receiver comes before the point of insertion of the fake |
@@ -187,7 +193,7 @@ impl<'a> CompletionContext<'a> { | |||
187 | .expr() | 193 | .expr() |
188 | .map(|e| e.syntax().range()) | 194 | .map(|e| e.syntax().range()) |
189 | .and_then(|r| find_node_with_range(original_file.syntax(), r)); | 195 | .and_then(|r| find_node_with_range(original_file.syntax(), r)); |
190 | self.is_method_call = true; | 196 | self.is_call = true; |
191 | } | 197 | } |
192 | } | 198 | } |
193 | } | 199 | } |
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index 334449fae..6a9770429 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs | |||
@@ -165,7 +165,7 @@ impl Builder { | |||
165 | 165 | ||
166 | fn from_function(mut self, ctx: &CompletionContext, function: hir::Function) -> Builder { | 166 | fn from_function(mut self, ctx: &CompletionContext, function: hir::Function) -> Builder { |
167 | // If not an import, add parenthesis automatically. | 167 | // If not an import, add parenthesis automatically. |
168 | if ctx.use_item_syntax.is_none() { | 168 | if ctx.use_item_syntax.is_none() && !ctx.is_call { |
169 | if function.signature(ctx.db).args().is_empty() { | 169 | if function.signature(ctx.db).args().is_empty() { |
170 | self.snippet = Some(format!("{}()$0", self.label)); | 170 | self.snippet = Some(format!("{}()$0", self.label)); |
171 | } else { | 171 | } else { |