aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion/patterns.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/completion/patterns.rs')
-rw-r--r--crates/ra_ide/src/completion/patterns.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs
index 464032cb4..fdcd3faa5 100644
--- a/crates/ra_ide/src/completion/patterns.rs
+++ b/crates/ra_ide/src/completion/patterns.rs
@@ -38,6 +38,14 @@ pub(crate) fn has_ref_parent(element: SyntaxElement) -> bool {
38 .is_some() 38 .is_some()
39} 39}
40 40
41pub(crate) fn has_item_list_or_source_file_parent(element: SyntaxElement) -> bool {
42 let ancestor = not_same_range_ancestor(element);
43 if !ancestor.is_some() {
44 return true;
45 }
46 ancestor.filter(|it| it.kind() == SOURCE_FILE || it.kind() == ITEM_LIST).is_some()
47}
48
41pub(crate) fn is_match_arm(element: SyntaxElement) -> bool { 49pub(crate) fn is_match_arm(element: SyntaxElement) -> bool {
42 not_same_range_ancestor(element.clone()).filter(|it| it.kind() == MATCH_ARM).is_some() 50 not_same_range_ancestor(element.clone()).filter(|it| it.kind() == MATCH_ARM).is_some()
43 && previous_sibling_or_ancestor_sibling(element) 51 && previous_sibling_or_ancestor_sibling(element)
@@ -139,8 +147,8 @@ fn previous_sibling_or_ancestor_sibling(element: SyntaxElement) -> Option<Syntax
139mod tests { 147mod tests {
140 use super::{ 148 use super::{
141 has_bind_pat_parent, has_block_expr_parent, has_impl_as_prev_sibling, has_impl_parent, 149 has_bind_pat_parent, has_block_expr_parent, has_impl_as_prev_sibling, has_impl_parent,
142 has_ref_parent, has_trait_as_prev_sibling, has_trait_parent, if_is_prev, is_match_arm, 150 has_item_list_or_source_file_parent, has_ref_parent, has_trait_as_prev_sibling,
143 unsafe_is_prev, 151 has_trait_parent, if_is_prev, is_match_arm, unsafe_is_prev,
144 }; 152 };
145 use crate::completion::test_utils::check_pattern_is_applicable; 153 use crate::completion::test_utils::check_pattern_is_applicable;
146 154
@@ -203,4 +211,14 @@ mod tests {
203 fn test_is_match_arm() { 211 fn test_is_match_arm() {
204 check_pattern_is_applicable(r"fn my_fn() { match () { () => m<|> } }", is_match_arm); 212 check_pattern_is_applicable(r"fn my_fn() { match () { () => m<|> } }", is_match_arm);
205 } 213 }
214
215 #[test]
216 fn test_has_source_file_parent() {
217 check_pattern_is_applicable(r"i<|>", has_item_list_or_source_file_parent);
218 }
219
220 #[test]
221 fn test_has_item_list_parent() {
222 check_pattern_is_applicable(r"impl { f<|> }", has_item_list_or_source_file_parent);
223 }
206} 224}