Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir_expand/src/lib.rs')
-rw-r--r--crates/hir_expand/src/lib.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs
index 1452ab08d9..c9165a0cf6 100644
--- a/crates/hir_expand/src/lib.rs
+++ b/crates/hir_expand/src/lib.rs
@@ -562,6 +562,28 @@ impl<N: AstNode> InFile<N> {
pub fn syntax(&self) -> InFile<&SyntaxNode> {
self.with_value(self.value.syntax())
}
+
+ pub fn nodes_with_attributes<'db>(
+ self,
+ db: &'db dyn db::AstDatabase,
+ ) -> impl Iterator<Item = InFile<N>> + 'db
+ where
+ N: 'db,
+ {
+ std::iter::successors(Some(self), move |node| {
+ let InFile { file_id, value } = node.file_id.call_node(db)?;
+ N::cast(value).map(|n| InFile::new(file_id, n))
+ })
+ }
+
+ pub fn node_with_attributes(self, db: &dyn db::AstDatabase) -> InFile<N> {
+ std::iter::successors(Some(self), move |node| {
+ let InFile { file_id, value } = node.file_id.call_node(db)?;
+ N::cast(value).map(|n| InFile::new(file_id, n))
+ })
+ .last()
+ .unwrap()
+ }
}
/// Given a `MacroCallId`, return what `FragmentKind` it belongs to.