Fix runnables not seeing test and bench attributes

This commit is contained in:
Lukas Wirth 2021-08-18 16:30:09 +02:00
parent 351cec0cb4
commit 7342dcf0b0
3 changed files with 42 additions and 18 deletions

View file

@ -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.