Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/ast/node_ext.rs')
| -rw-r--r-- | crates/syntax/src/ast/node_ext.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index ab47d4ece9..cb3bdaac1b 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -11,8 +11,8 @@ use rowan::{GreenNodeData, GreenTokenData}; use crate::{ ast::{ - self, support, AstChildren, AstNode, AstToken, AttrsOwner, GenericParamsOwner, NameOwner, - SyntaxNode, + self, support, AstNode, AstToken, AttrsOwner, GenericParamsOwner, ModuleItemOwner, + NameOwner, SyntaxNode, }, NodeOrToken, SmolStr, SyntaxElement, SyntaxToken, TokenText, T, }; @@ -50,14 +50,23 @@ fn text_of_first_token(node: &SyntaxNode) -> TokenText<'_> { } } +impl ast::ModuleItemOwner for ast::StmtList {} + impl ast::BlockExpr { - pub fn items(&self) -> AstChildren<ast::Item> { - support::children(self.syntax()) + // FIXME: remove all these methods, they belong to ast::StmtList + pub fn items(&self) -> impl Iterator<Item = ast::Item> { + self.stmt_list().into_iter().flat_map(|it| it.items()) } pub fn is_empty(&self) -> bool { self.statements().next().is_none() && self.tail_expr().is_none() } + pub fn statements(&self) -> impl Iterator<Item = ast::Stmt> { + self.stmt_list().into_iter().flat_map(|it| it.statements()) + } + pub fn tail_expr(&self) -> Option<ast::Expr> { + self.stmt_list()?.tail_expr() + } } #[derive(Debug, PartialEq, Eq, Clone)] |