Skip to content

Commit 3da53ab

Browse files
bors[bot]matklad
andauthored
Merge #3125
3125: Add couple of utility methods r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 9701e59 + f2424f9 commit 3da53ab

File tree

1 file changed

+19
-3
lines changed
  • crates/ra_hir_expand/src

1 file changed

+19
-3
lines changed

crates/ra_hir_expand/src/lib.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,18 @@ impl<T: Clone> InFile<&T> {
323323
}
324324
}
325325

326+
impl<T> InFile<Option<T>> {
327+
pub fn transpose(self) -> Option<InFile<T>> {
328+
let value = self.value?;
329+
Some(InFile::new(self.file_id, value))
330+
}
331+
}
332+
326333
impl InFile<SyntaxNode> {
327-
pub fn ancestors_with_macros<'a>(
334+
pub fn ancestors_with_macros(
328335
self,
329-
db: &'a impl crate::db::AstDatabase,
330-
) -> impl Iterator<Item = InFile<SyntaxNode>> + 'a {
336+
db: &impl crate::db::AstDatabase,
337+
) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ {
331338
std::iter::successors(Some(self), move |node| match node.value.parent() {
332339
Some(parent) => Some(node.with_value(parent)),
333340
None => {
@@ -338,6 +345,15 @@ impl InFile<SyntaxNode> {
338345
}
339346
}
340347

348+
impl InFile<SyntaxToken> {
349+
pub fn ancestors_with_macros(
350+
self,
351+
db: &impl crate::db::AstDatabase,
352+
) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ {
353+
self.map(|it| it.parent()).ancestors_with_macros(db)
354+
}
355+
}
356+
341357
impl<N: AstNode> InFile<N> {
342358
pub fn descendants<T: AstNode>(self) -> impl Iterator<Item = InFile<T>> {
343359
self.value.syntax().descendants().filter_map(T::cast).map(move |n| self.with_value(n))

0 commit comments

Comments
 (0)