diff options
Diffstat (limited to 'crates/ide/src/completion/patterns.rs')
-rw-r--r-- | crates/ide/src/completion/patterns.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/crates/ide/src/completion/patterns.rs b/crates/ide/src/completion/patterns.rs index bdce7a6e7..cf6d5947d 100644 --- a/crates/ide/src/completion/patterns.rs +++ b/crates/ide/src/completion/patterns.rs | |||
@@ -35,19 +35,22 @@ fn test_has_impl_parent() { | |||
35 | check_pattern_is_applicable(r"impl A { f<|> }", has_impl_parent); | 35 | check_pattern_is_applicable(r"impl A { f<|> }", has_impl_parent); |
36 | } | 36 | } |
37 | 37 | ||
38 | pub(crate) fn has_impl_trait_parent(element: SyntaxElement) -> bool { | 38 | pub(crate) fn inside_impl_trait_block(element: SyntaxElement) -> bool { |
39 | not_same_range_ancestor(element) | 39 | // Here we search `impl` keyword up through the all ancestors, unlike in `has_impl_parent`, |
40 | .filter(|it| it.kind() == ASSOC_ITEM_LIST) | 40 | // where we only check the first parent with different text range. |
41 | .and_then(|it| it.parent()) | 41 | element |
42 | .filter(|it| it.kind() == IMPL) | 42 | .ancestors() |
43 | .find(|it| it.kind() == IMPL) | ||
43 | .map(|it| ast::Impl::cast(it).unwrap()) | 44 | .map(|it| ast::Impl::cast(it).unwrap()) |
44 | .map(|it| it.trait_().is_some()) | 45 | .map(|it| it.trait_().is_some()) |
45 | .unwrap_or(false) | 46 | .unwrap_or(false) |
46 | } | 47 | } |
47 | #[test] | 48 | #[test] |
48 | fn test_has_impl_trait_parent() { | 49 | fn test_inside_impl_trait_block() { |
49 | check_pattern_is_applicable(r"impl Foo for Bar { f<|> }", has_impl_trait_parent); | 50 | check_pattern_is_applicable(r"impl Foo for Bar { f<|> }", inside_impl_trait_block); |
50 | check_pattern_is_not_applicable(r"impl A { f<|> }", has_impl_trait_parent); | 51 | check_pattern_is_applicable(r"impl Foo for Bar { fn f<|> }", inside_impl_trait_block); |
52 | check_pattern_is_not_applicable(r"impl A { f<|> }", inside_impl_trait_block); | ||
53 | check_pattern_is_not_applicable(r"impl A { fn f<|> }", inside_impl_trait_block); | ||
51 | } | 54 | } |
52 | 55 | ||
53 | pub(crate) fn has_field_list_parent(element: SyntaxElement) -> bool { | 56 | pub(crate) fn has_field_list_parent(element: SyntaxElement) -> bool { |