Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions crates/ra_hir_expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,18 @@ impl<T: Clone> InFile<&T> {
}
}

impl<T> InFile<Option<T>> {
pub fn transpose(self) -> Option<InFile<T>> {
let value = self.value?;
Some(InFile::new(self.file_id, value))
}
}

impl InFile<SyntaxNode> {
pub fn ancestors_with_macros<'a>(
pub fn ancestors_with_macros(
self,
db: &'a impl crate::db::AstDatabase,
) -> impl Iterator<Item = InFile<SyntaxNode>> + 'a {
db: &impl crate::db::AstDatabase,
) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ {
std::iter::successors(Some(self), move |node| match node.value.parent() {
Some(parent) => Some(node.with_value(parent)),
None => {
Expand All @@ -338,6 +345,15 @@ impl InFile<SyntaxNode> {
}
}

impl InFile<SyntaxToken> {
pub fn ancestors_with_macros(
self,
db: &impl crate::db::AstDatabase,
) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ {
self.map(|it| it.parent()).ancestors_with_macros(db)
}
}

impl<N: AstNode> InFile<N> {
pub fn descendants<T: AstNode>(self) -> impl Iterator<Item = InFile<T>> {
self.value.syntax().descendants().filter_map(T::cast).map(move |n| self.with_value(n))
Expand Down