From ac226021cfd26a9332b5971f3e05118d77822af5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 26 Aug 2018 12:09:28 +0300 Subject: scope based comletion --- crates/libsyntax2/src/algo/walk.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/libsyntax2/src/algo/walk.rs') diff --git a/crates/libsyntax2/src/algo/walk.rs b/crates/libsyntax2/src/algo/walk.rs index d8797c453..536ee705f 100644 --- a/crates/libsyntax2/src/algo/walk.rs +++ b/crates/libsyntax2/src/algo/walk.rs @@ -17,19 +17,19 @@ pub enum WalkEvent<'a> { } pub fn walk<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator> { - generate(Some(WalkEvent::Enter(root)), |pos| { + generate(Some(WalkEvent::Enter(root)), move |pos| { let next = match *pos { WalkEvent::Enter(node) => match node.first_child() { Some(child) => WalkEvent::Enter(child), None => WalkEvent::Exit(node), }, WalkEvent::Exit(node) => { + if node == root { + return None; + } match node.next_sibling() { Some(sibling) => WalkEvent::Enter(sibling), - None => match node.parent() { - Some(node) => WalkEvent::Exit(node), - None => return None, - }, + None => WalkEvent::Exit(node.parent().unwrap()), } } }; -- cgit v1.2.3