From 6f573bd84f4564f11b08db720401ae16a0f42f2f Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Sat, 17 Oct 2020 11:03:07 +0300 Subject: Allow hints after 'fn' keyword if it's an impl trait block --- crates/ide/src/completion/patterns.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'crates/ide/src/completion/patterns.rs') 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::{ }; #[cfg(test)] -use crate::completion::test_utils::check_pattern_is_applicable; +use crate::completion::test_utils::{check_pattern_is_applicable, check_pattern_is_not_applicable}; pub(crate) fn has_trait_parent(element: SyntaxElement) -> bool { not_same_range_ancestor(element) @@ -34,6 +34,22 @@ pub(crate) fn has_impl_parent(element: SyntaxElement) -> bool { fn test_has_impl_parent() { check_pattern_is_applicable(r"impl A { f<|> }", has_impl_parent); } + +pub(crate) fn has_impl_trait_parent(element: SyntaxElement) -> bool { + not_same_range_ancestor(element) + .filter(|it| it.kind() == ASSOC_ITEM_LIST) + .and_then(|it| it.parent()) + .filter(|it| it.kind() == IMPL) + .map(|it| ast::Impl::cast(it).unwrap()) + .map(|it| it.trait_().is_some()) + .unwrap_or(false) +} +#[test] +fn test_has_impl_trait_parent() { + check_pattern_is_applicable(r"impl Foo for Bar { f<|> }", has_impl_trait_parent); + check_pattern_is_not_applicable(r"impl A { f<|> }", has_impl_trait_parent); +} + pub(crate) fn has_field_list_parent(element: SyntaxElement) -> bool { not_same_range_ancestor(element).filter(|it| it.kind() == RECORD_FIELD_LIST).is_some() } -- cgit v1.2.3