diff options
Diffstat (limited to 'crates/ide_completion/src/patterns.rs')
-rw-r--r-- | crates/ide_completion/src/patterns.rs | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/crates/ide_completion/src/patterns.rs b/crates/ide_completion/src/patterns.rs index 8f0d76661..04f2c532b 100644 --- a/crates/ide_completion/src/patterns.rs +++ b/crates/ide_completion/src/patterns.rs | |||
@@ -4,7 +4,7 @@ use syntax::{ | |||
4 | algo::non_trivia_sibling, | 4 | algo::non_trivia_sibling, |
5 | ast::{self, LoopBodyOwner}, | 5 | ast::{self, LoopBodyOwner}, |
6 | match_ast, AstNode, Direction, NodeOrToken, SyntaxElement, | 6 | match_ast, AstNode, Direction, NodeOrToken, SyntaxElement, |
7 | SyntaxKind::*, | 7 | SyntaxKind::{self, *}, |
8 | SyntaxNode, SyntaxToken, T, | 8 | SyntaxNode, SyntaxToken, T, |
9 | }; | 9 | }; |
10 | 10 | ||
@@ -73,6 +73,7 @@ fn test_has_block_expr_parent() { | |||
73 | pub(crate) fn has_bind_pat_parent(element: SyntaxElement) -> bool { | 73 | pub(crate) fn has_bind_pat_parent(element: SyntaxElement) -> bool { |
74 | element.ancestors().any(|it| it.kind() == IDENT_PAT) | 74 | element.ancestors().any(|it| it.kind() == IDENT_PAT) |
75 | } | 75 | } |
76 | |||
76 | #[test] | 77 | #[test] |
77 | fn test_has_bind_pat_parent() { | 78 | fn test_has_bind_pat_parent() { |
78 | check_pattern_is_applicable(r"fn my_fn(m$0) {}", has_bind_pat_parent); | 79 | check_pattern_is_applicable(r"fn my_fn(m$0) {}", has_bind_pat_parent); |
@@ -133,20 +134,12 @@ fn test_for_is_prev2() { | |||
133 | check_pattern_is_applicable(r"for i i$0", for_is_prev2); | 134 | check_pattern_is_applicable(r"for i i$0", for_is_prev2); |
134 | } | 135 | } |
135 | 136 | ||
136 | pub(crate) fn has_trait_as_prev_sibling(element: SyntaxElement) -> bool { | 137 | pub(crate) fn has_prev_sibling(element: SyntaxElement, kind: SyntaxKind) -> bool { |
137 | previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == TRAIT).is_some() | 138 | previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == kind).is_some() |
138 | } | ||
139 | #[test] | ||
140 | fn test_has_trait_as_prev_sibling() { | ||
141 | check_pattern_is_applicable(r"trait A w$0 {}", has_trait_as_prev_sibling); | ||
142 | } | ||
143 | |||
144 | pub(crate) fn has_impl_as_prev_sibling(element: SyntaxElement) -> bool { | ||
145 | previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == IMPL).is_some() | ||
146 | } | 139 | } |
147 | #[test] | 140 | #[test] |
148 | fn test_has_impl_as_prev_sibling() { | 141 | fn test_has_impl_as_prev_sibling() { |
149 | check_pattern_is_applicable(r"impl A w$0 {}", has_impl_as_prev_sibling); | 142 | check_pattern_is_applicable(r"impl A w$0 {}", |it| has_prev_sibling(it, IMPL)); |
150 | } | 143 | } |
151 | 144 | ||
152 | pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool { | 145 | pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool { |