diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide/src/completion/patterns.rs | 59 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/test_utils.rs | 2 |
2 files changed, 50 insertions, 11 deletions
diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs index df2594152..25be0c307 100644 --- a/crates/ra_ide/src/completion/patterns.rs +++ b/crates/ra_ide/src/completion/patterns.rs | |||
@@ -6,10 +6,6 @@ use ra_syntax::{ | |||
6 | SyntaxNode, SyntaxToken, | 6 | SyntaxNode, SyntaxToken, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | pub(crate) fn inside_impl(element: SyntaxElement) -> bool { | ||
10 | element.ancestors().find(|it| it.kind() == IMPL_DEF).is_some() | ||
11 | } | ||
12 | |||
13 | pub(crate) fn inside_trait(element: SyntaxElement) -> bool { | 9 | pub(crate) fn inside_trait(element: SyntaxElement) -> bool { |
14 | element.ancestors().find(|it| it.kind() == TRAIT_DEF).is_some() | 10 | element.ancestors().find(|it| it.kind() == TRAIT_DEF).is_some() |
15 | } | 11 | } |
@@ -42,10 +38,6 @@ pub(crate) fn has_block_expr_parent(element: SyntaxElement) -> bool { | |||
42 | not_same_range_ancestor(element).filter(|it| it.kind() == BLOCK_EXPR).is_some() | 38 | not_same_range_ancestor(element).filter(|it| it.kind() == BLOCK_EXPR).is_some() |
43 | } | 39 | } |
44 | 40 | ||
45 | pub(crate) fn has_item_list_parent(element: SyntaxElement) -> bool { | ||
46 | not_same_range_ancestor(element).filter(|it| it.kind() == ITEM_LIST).is_some() | ||
47 | } | ||
48 | |||
49 | pub(crate) fn has_trait_as_prev_sibling(element: SyntaxElement) -> bool { | 41 | pub(crate) fn has_trait_as_prev_sibling(element: SyntaxElement) -> bool { |
50 | previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == TRAIT_DEF).is_some() | 42 | previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == TRAIT_DEF).is_some() |
51 | } | 43 | } |
@@ -122,8 +114,8 @@ fn previous_sibling_or_ancestor_sibling(element: SyntaxElement) -> Option<Syntax | |||
122 | #[cfg(test)] | 114 | #[cfg(test)] |
123 | mod tests { | 115 | mod tests { |
124 | use super::{ | 116 | use super::{ |
125 | has_block_expr_parent, has_impl_as_prev_sibling, has_trait_as_prev_sibling, if_is_prev, | 117 | has_bind_pat_parent, has_block_expr_parent, has_impl_as_prev_sibling, has_ref_pat_parent, |
126 | inside_trait, unsafe_is_prev, | 118 | has_trait_as_prev_sibling, if_is_prev, inside_trait, unsafe_is_prev, |
127 | }; | 119 | }; |
128 | use crate::completion::test_utils::check_pattern_is_applicable; | 120 | use crate::completion::test_utils::check_pattern_is_applicable; |
129 | 121 | ||
@@ -193,4 +185,51 @@ mod tests { | |||
193 | has_block_expr_parent, | 185 | has_block_expr_parent, |
194 | ); | 186 | ); |
195 | } | 187 | } |
188 | |||
189 | #[test] | ||
190 | fn test_has_ref_pat_parent_in_func_parameters() { | ||
191 | check_pattern_is_applicable( | ||
192 | r" | ||
193 | fn my_fn(&<|>) { | ||
194 | let a = 2; | ||
195 | } | ||
196 | ", | ||
197 | has_ref_pat_parent, | ||
198 | ); | ||
199 | } | ||
200 | |||
201 | #[test] | ||
202 | fn test_has_ref_pat_parent_in_let_statement() { | ||
203 | check_pattern_is_applicable( | ||
204 | r" | ||
205 | fn my_fn() { | ||
206 | let &<|> | ||
207 | } | ||
208 | ", | ||
209 | has_ref_pat_parent, | ||
210 | ); | ||
211 | } | ||
212 | |||
213 | #[test] | ||
214 | fn test_has_bind_pat_parent_in_func_parameters() { | ||
215 | check_pattern_is_applicable( | ||
216 | r" | ||
217 | fn my_fn(m<|>) { | ||
218 | } | ||
219 | ", | ||
220 | has_bind_pat_parent, | ||
221 | ); | ||
222 | } | ||
223 | |||
224 | #[test] | ||
225 | fn test_has_bind_pat_parent_in_let_statement() { | ||
226 | check_pattern_is_applicable( | ||
227 | r" | ||
228 | fn my_fn() { | ||
229 | let m<|> | ||
230 | } | ||
231 | ", | ||
232 | has_bind_pat_parent, | ||
233 | ); | ||
234 | } | ||
196 | } | 235 | } |
diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs index 277d2904d..f439f974d 100644 --- a/crates/ra_ide/src/completion/test_utils.rs +++ b/crates/ra_ide/src/completion/test_utils.rs | |||
@@ -6,7 +6,7 @@ use crate::{ | |||
6 | CompletionItem, FilePosition, | 6 | CompletionItem, FilePosition, |
7 | }; | 7 | }; |
8 | use hir::Semantics; | 8 | use hir::Semantics; |
9 | use ra_syntax::{AstNode, NodeOrToken, SyntaxElement, SyntaxToken}; | 9 | use ra_syntax::{AstNode, NodeOrToken, SyntaxElement}; |
10 | 10 | ||
11 | pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> { | 11 | pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> { |
12 | do_completion_with_options(code, kind, &CompletionConfig::default()) | 12 | do_completion_with_options(code, kind, &CompletionConfig::default()) |