diff options
author | Igor Aleksanov <[email protected]> | 2020-10-17 09:03:07 +0100 |
---|---|---|
committer | Igor Aleksanov <[email protected]> | 2020-10-17 09:03:07 +0100 |
commit | 6f573bd84f4564f11b08db720401ae16a0f42f2f (patch) | |
tree | 774202cfd275bd30380bc7618885da5e012b5690 /crates/ide/src/completion/patterns.rs | |
parent | 8f303daf458ae798b678d7e908ce5b2f27504111 (diff) |
Allow hints after 'fn' keyword if it's an impl trait block
Diffstat (limited to 'crates/ide/src/completion/patterns.rs')
-rw-r--r-- | crates/ide/src/completion/patterns.rs | 18 |
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)] |
12 | use crate::completion::test_utils::check_pattern_is_applicable; | 12 | use crate::completion::test_utils::{check_pattern_is_applicable, check_pattern_is_not_applicable}; |
13 | 13 | ||
14 | pub(crate) fn has_trait_parent(element: SyntaxElement) -> bool { | 14 | pub(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 { | |||
34 | fn test_has_impl_parent() { | 34 | 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 | |||
38 | pub(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] | ||
48 | fn 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 | |||
37 | pub(crate) fn has_field_list_parent(element: SyntaxElement) -> bool { | 53 | pub(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 | } |