From f2424f947cb10fa5bdcd33f34b4444b7ab78b07d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 12 Feb 2020 18:19:55 +0100 Subject: Add couple of utility methods --- crates/ra_hir_expand/src/lib.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_expand') diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 7cf3b59a7..9506f2e1c 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs @@ -323,11 +323,18 @@ impl InFile<&T> { } } +impl InFile> { + pub fn transpose(self) -> Option> { + let value = self.value?; + Some(InFile::new(self.file_id, value)) + } +} + impl InFile { - pub fn ancestors_with_macros<'a>( + pub fn ancestors_with_macros( self, - db: &'a impl crate::db::AstDatabase, - ) -> impl Iterator> + 'a { + db: &impl crate::db::AstDatabase, + ) -> impl Iterator> + '_ { std::iter::successors(Some(self), move |node| match node.value.parent() { Some(parent) => Some(node.with_value(parent)), None => { @@ -338,6 +345,15 @@ impl InFile { } } +impl InFile { + pub fn ancestors_with_macros( + self, + db: &impl crate::db::AstDatabase, + ) -> impl Iterator> + '_ { + self.map(|it| it.parent()).ancestors_with_macros(db) + } +} + impl InFile { pub fn descendants(self) -> impl Iterator> { self.value.syntax().descendants().filter_map(T::cast).map(move |n| self.with_value(n)) -- cgit v1.2.3