diff options
Diffstat (limited to 'crates/ide_completion/src/patterns.rs')
-rw-r--r-- | crates/ide_completion/src/patterns.rs | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/crates/ide_completion/src/patterns.rs b/crates/ide_completion/src/patterns.rs index f3ce91dd1..cf5ef07b7 100644 --- a/crates/ide_completion/src/patterns.rs +++ b/crates/ide_completion/src/patterns.rs | |||
@@ -184,11 +184,7 @@ fn test_has_impl_as_prev_sibling() { | |||
184 | } | 184 | } |
185 | 185 | ||
186 | pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool { | 186 | pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool { |
187 | let leaf = match element { | 187 | for node in element.ancestors() { |
188 | NodeOrToken::Node(node) => node, | ||
189 | NodeOrToken::Token(token) => token.parent(), | ||
190 | }; | ||
191 | for node in leaf.ancestors() { | ||
192 | if node.kind() == FN || node.kind() == CLOSURE_EXPR { | 188 | if node.kind() == FN || node.kind() == CLOSURE_EXPR { |
193 | break; | 189 | break; |
194 | } | 190 | } |
@@ -201,7 +197,7 @@ pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool { | |||
201 | } | 197 | } |
202 | }; | 198 | }; |
203 | if let Some(body) = loop_body { | 199 | if let Some(body) = loop_body { |
204 | if body.syntax().text_range().contains_range(leaf.text_range()) { | 200 | if body.syntax().text_range().contains_range(element.text_range()) { |
205 | return true; | 201 | return true; |
206 | } | 202 | } |
207 | } | 203 | } |
@@ -235,12 +231,8 @@ fn previous_sibling_or_ancestor_sibling(element: SyntaxElement) -> Option<Syntax | |||
235 | Some(sibling) | 231 | Some(sibling) |
236 | } else { | 232 | } else { |
237 | // if not trying to find first ancestor which has such a sibling | 233 | // if not trying to find first ancestor which has such a sibling |
238 | let node = match element { | 234 | let range = element.text_range(); |
239 | NodeOrToken::Node(node) => node, | 235 | let top_node = element.ancestors().take_while(|it| it.text_range() == range).last()?; |
240 | NodeOrToken::Token(token) => token.parent(), | ||
241 | }; | ||
242 | let range = node.text_range(); | ||
243 | let top_node = node.ancestors().take_while(|it| it.text_range() == range).last()?; | ||
244 | let prev_sibling_node = top_node.ancestors().find(|it| { | 236 | let prev_sibling_node = top_node.ancestors().find(|it| { |
245 | non_trivia_sibling(NodeOrToken::Node(it.to_owned()), Direction::Prev).is_some() | 237 | non_trivia_sibling(NodeOrToken::Node(it.to_owned()), Direction::Prev).is_some() |
246 | })?; | 238 | })?; |