From 00cdde2c5218020b8f6ec751042a436aeef923c7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 17 Oct 2018 19:52:25 +0300 Subject: Update rowan --- crates/ra_syntax/src/yellow/mod.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'crates/ra_syntax/src/yellow/mod.rs') diff --git a/crates/ra_syntax/src/yellow/mod.rs b/crates/ra_syntax/src/yellow/mod.rs index b5c9da813..650917214 100644 --- a/crates/ra_syntax/src/yellow/mod.rs +++ b/crates/ra_syntax/src/yellow/mod.rs @@ -10,7 +10,7 @@ use std::{ }; pub(crate) use self::builder::GreenBuilder; -pub use rowan::TreeRoot; +pub use rowan::{TreeRoot, WalkEvent}; #[derive(Debug, Clone, Copy)] pub enum RaTypes {} @@ -71,9 +71,9 @@ impl<'a> SyntaxNodeRef<'a> { crate::algo::generate(Some(self), |&node| node.parent()) } pub fn descendants(self) -> impl Iterator> { - crate::algo::walk::walk(self).filter_map(|event| match event { - crate::algo::walk::WalkEvent::Enter(node) => Some(node), - crate::algo::walk::WalkEvent::Exit(_) => None, + self.preorder().filter_map(|event| match event { + WalkEvent::Enter(node) => Some(node), + WalkEvent::Leave(_) => None, }) } pub fn siblings(self, direction: Direction) -> impl Iterator> { @@ -82,6 +82,12 @@ impl<'a> SyntaxNodeRef<'a> { Direction::Prev => node.prev_sibling(), }) } + pub fn preorder(self) -> impl Iterator>> { + self.0.preorder().map(|event| match event { + WalkEvent::Enter(n) => WalkEvent::Enter(SyntaxNode(n)), + WalkEvent::Leave(n) => WalkEvent::Leave(SyntaxNode(n)), + }) + } } impl> SyntaxNode { -- cgit v1.2.3