From 1a2a8dec14ec04ea8eeccae99fd885e7a280e45b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 2 Oct 2018 18:14:33 +0300 Subject: Make siblings an inherent method --- crates/ra_syntax/src/yellow/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'crates/ra_syntax/src/yellow') diff --git a/crates/ra_syntax/src/yellow/mod.rs b/crates/ra_syntax/src/yellow/mod.rs index 95d277a2f..710320f47 100644 --- a/crates/ra_syntax/src/yellow/mod.rs +++ b/crates/ra_syntax/src/yellow/mod.rs @@ -58,6 +58,13 @@ impl SyntaxNode { SyntaxNode(::rowan::SyntaxNode::new(green, errors)) } } + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Direction { + Next, + Prev, +} + impl<'a> SyntaxNodeRef<'a> { pub fn leaf_text(self) -> Option<&'a SmolStr> { self.0.leaf_text() @@ -71,6 +78,12 @@ impl<'a> SyntaxNodeRef<'a> { ::algo::walk::WalkEvent::Exit(_) => None, }) } + pub fn siblings(self, direction: Direction) -> impl Iterator> { + ::algo::generate(Some(self), move |&node| match direction { + Direction::Next => node.next_sibling(), + Direction::Prev => node.prev_sibling(), + }) + } } impl> SyntaxNode { -- cgit v1.2.3