aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/completion/patterns.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/completion/patterns.rs')
-rw-r--r--crates/ide/src/completion/patterns.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/crates/ide/src/completion/patterns.rs b/crates/ide/src/completion/patterns.rs
index f00ddeed7..bdce7a6e7 100644
--- a/crates/ide/src/completion/patterns.rs
+++ b/crates/ide/src/completion/patterns.rs
@@ -9,7 +9,7 @@ use syntax::{
9}; 9};
10 10
11#[cfg(test)] 11#[cfg(test)]
12use crate::completion::test_utils::check_pattern_is_applicable; 12use crate::completion::test_utils::{check_pattern_is_applicable, check_pattern_is_not_applicable};
13 13
14pub(crate) fn has_trait_parent(element: SyntaxElement) -> bool { 14pub(crate) fn has_trait_parent(element: SyntaxElement) -> bool {
15 not_same_range_ancestor(element) 15 not_same_range_ancestor(element)
@@ -34,6 +34,22 @@ pub(crate) fn has_impl_parent(element: SyntaxElement) -> bool {
34fn test_has_impl_parent() { 34fn 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
38pub(crate) fn has_impl_trait_parent(element: SyntaxElement) -> bool {
39 not_same_range_ancestor(element)
40 .filter(|it| it.kind() == ASSOC_ITEM_LIST)
41 .and_then(|it| it.parent())
42 .filter(|it| it.kind() == IMPL)
43 .map(|it| ast::Impl::cast(it).unwrap())
44 .map(|it| it.trait_().is_some())
45 .unwrap_or(false)
46}
47#[test]
48fn test_has_impl_trait_parent() {
49 check_pattern_is_applicable(r"impl Foo for Bar { f<|> }", has_impl_trait_parent);
50 check_pattern_is_not_applicable(r"impl A { f<|> }", has_impl_trait_parent);
51}
52
37pub(crate) fn has_field_list_parent(element: SyntaxElement) -> bool { 53pub(crate) fn has_field_list_parent(element: SyntaxElement) -> bool {
38 not_same_range_ancestor(element).filter(|it| it.kind() == RECORD_FIELD_LIST).is_some() 54 not_same_range_ancestor(element).filter(|it| it.kind() == RECORD_FIELD_LIST).is_some()
39} 55}