diff options
Diffstat (limited to 'crates/ra_syntax/src/yellow/mod.rs')
-rw-r--r-- | crates/ra_syntax/src/yellow/mod.rs | 14 |
1 files changed, 10 insertions, 4 deletions
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::{ | |||
10 | }; | 10 | }; |
11 | 11 | ||
12 | pub(crate) use self::builder::GreenBuilder; | 12 | pub(crate) use self::builder::GreenBuilder; |
13 | pub use rowan::TreeRoot; | 13 | pub use rowan::{TreeRoot, WalkEvent}; |
14 | 14 | ||
15 | #[derive(Debug, Clone, Copy)] | 15 | #[derive(Debug, Clone, Copy)] |
16 | pub enum RaTypes {} | 16 | pub enum RaTypes {} |
@@ -71,9 +71,9 @@ impl<'a> SyntaxNodeRef<'a> { | |||
71 | crate::algo::generate(Some(self), |&node| node.parent()) | 71 | crate::algo::generate(Some(self), |&node| node.parent()) |
72 | } | 72 | } |
73 | pub fn descendants(self) -> impl Iterator<Item = SyntaxNodeRef<'a>> { | 73 | pub fn descendants(self) -> impl Iterator<Item = SyntaxNodeRef<'a>> { |
74 | crate::algo::walk::walk(self).filter_map(|event| match event { | 74 | self.preorder().filter_map(|event| match event { |
75 | crate::algo::walk::WalkEvent::Enter(node) => Some(node), | 75 | WalkEvent::Enter(node) => Some(node), |
76 | crate::algo::walk::WalkEvent::Exit(_) => None, | 76 | WalkEvent::Leave(_) => None, |
77 | }) | 77 | }) |
78 | } | 78 | } |
79 | pub fn siblings(self, direction: Direction) -> impl Iterator<Item = SyntaxNodeRef<'a>> { | 79 | pub fn siblings(self, direction: Direction) -> impl Iterator<Item = SyntaxNodeRef<'a>> { |
@@ -82,6 +82,12 @@ impl<'a> SyntaxNodeRef<'a> { | |||
82 | Direction::Prev => node.prev_sibling(), | 82 | Direction::Prev => node.prev_sibling(), |
83 | }) | 83 | }) |
84 | } | 84 | } |
85 | pub fn preorder(self) -> impl Iterator<Item = WalkEvent<SyntaxNodeRef<'a>>> { | ||
86 | self.0.preorder().map(|event| match event { | ||
87 | WalkEvent::Enter(n) => WalkEvent::Enter(SyntaxNode(n)), | ||
88 | WalkEvent::Leave(n) => WalkEvent::Leave(SyntaxNode(n)), | ||
89 | }) | ||
90 | } | ||
85 | } | 91 | } |
86 | 92 | ||
87 | impl<R: TreeRoot<RaTypes>> SyntaxNode<R> { | 93 | impl<R: TreeRoot<RaTypes>> SyntaxNode<R> { |