diff options
Diffstat (limited to 'crates/ide_completion/src/patterns.rs')
-rw-r--r-- | crates/ide_completion/src/patterns.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/crates/ide_completion/src/patterns.rs b/crates/ide_completion/src/patterns.rs index 080898aef..ee87bf461 100644 --- a/crates/ide_completion/src/patterns.rs +++ b/crates/ide_completion/src/patterns.rs | |||
@@ -4,7 +4,7 @@ use hir::Semantics; | |||
4 | use ide_db::RootDatabase; | 4 | use ide_db::RootDatabase; |
5 | use syntax::{ | 5 | use syntax::{ |
6 | algo::non_trivia_sibling, | 6 | algo::non_trivia_sibling, |
7 | ast::{self, LoopBodyOwner}, | 7 | ast::{self, ArgListOwner, LoopBodyOwner}, |
8 | match_ast, AstNode, Direction, SyntaxElement, | 8 | match_ast, AstNode, Direction, SyntaxElement, |
9 | SyntaxKind::*, | 9 | SyntaxKind::*, |
10 | SyntaxNode, SyntaxToken, TextRange, TextSize, T, | 10 | SyntaxNode, SyntaxToken, TextRange, TextSize, T, |
@@ -39,6 +39,7 @@ pub(crate) enum ImmediateLocation { | |||
39 | // Original file ast node | 39 | // Original file ast node |
40 | MethodCall { | 40 | MethodCall { |
41 | receiver: Option<ast::Expr>, | 41 | receiver: Option<ast::Expr>, |
42 | has_parens: bool, | ||
42 | }, | 43 | }, |
43 | // Original file ast node | 44 | // Original file ast node |
44 | FieldAccess { | 45 | FieldAccess { |
@@ -204,6 +205,7 @@ pub(crate) fn determine_location( | |||
204 | .receiver() | 205 | .receiver() |
205 | .map(|e| e.syntax().text_range()) | 206 | .map(|e| e.syntax().text_range()) |
206 | .and_then(|r| find_node_with_range(original_file, r)), | 207 | .and_then(|r| find_node_with_range(original_file, r)), |
208 | has_parens: it.arg_list().map_or(false, |it| it.l_paren_token().is_some()) | ||
207 | }, | 209 | }, |
208 | _ => return None, | 210 | _ => return None, |
209 | } | 211 | } |
@@ -270,9 +272,8 @@ fn test_for_is_prev2() { | |||
270 | check_pattern_is_applicable(r"for i i$0", for_is_prev2); | 272 | check_pattern_is_applicable(r"for i i$0", for_is_prev2); |
271 | } | 273 | } |
272 | 274 | ||
273 | pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool { | 275 | pub(crate) fn is_in_loop_body(node: &SyntaxNode) -> bool { |
274 | element | 276 | node.ancestors() |
275 | .ancestors() | ||
276 | .take_while(|it| it.kind() != FN && it.kind() != CLOSURE_EXPR) | 277 | .take_while(|it| it.kind() != FN && it.kind() != CLOSURE_EXPR) |
277 | .find_map(|it| { | 278 | .find_map(|it| { |
278 | let loop_body = match_ast! { | 279 | let loop_body = match_ast! { |
@@ -283,7 +284,7 @@ pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool { | |||
283 | _ => None, | 284 | _ => None, |
284 | } | 285 | } |
285 | }; | 286 | }; |
286 | loop_body.filter(|it| it.syntax().text_range().contains_range(element.text_range())) | 287 | loop_body.filter(|it| it.syntax().text_range().contains_range(node.text_range())) |
287 | }) | 288 | }) |
288 | .is_some() | 289 | .is_some() |
289 | } | 290 | } |