From 00cdde2c5218020b8f6ec751042a436aeef923c7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 17 Oct 2018 19:52:25 +0300 Subject: [PATCH] Update rowan --- Cargo.lock | 14 +++++++------- crates/ra_editor/src/symbols.rs | 6 +++--- crates/ra_syntax/Cargo.toml | 2 +- crates/ra_syntax/src/algo/mod.rs | 2 +- crates/ra_syntax/src/algo/walk.rs | 28 ---------------------------- crates/ra_syntax/src/lib.rs | 2 +- crates/ra_syntax/src/utils.rs | 7 +++---- crates/ra_syntax/src/yellow/mod.rs | 14 ++++++++++---- 8 files changed, 26 insertions(+), 49 deletions(-) delete mode 100644 crates/ra_syntax/src/algo/walk.rs diff --git a/Cargo.lock b/Cargo.lock index 79da84ebcc2..bb93b8b0e1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -484,7 +484,7 @@ dependencies = [ "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.11 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -684,7 +684,7 @@ dependencies = [ "drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rowan 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rowan 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "test_utils 0.1.0", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -804,7 +804,7 @@ dependencies = [ [[package]] name = "rowan" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -898,7 +898,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.11 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -973,7 +973,7 @@ dependencies = [ [[package]] name = "syn" -version = "0.15.11" +version = "0.15.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1355,7 +1355,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum relative-path 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "e614f96449605730b4f7ad2c019e88c1652d730634b4eba07b810801856635e3" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum ron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c48677d8a9247a4e0d1f3f9cb4b0a8e29167fdc3c04f383a5e669cd7a960ae0f" -"checksum rowan 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4a1a7366ece9deee5e7df8316a136d585d5c5042854c2297f7f1aee3014c9130" +"checksum rowan 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bb1f952404091f61bfea7cd09c564090a0fcee3d22223f98084e8756e01c04d" "checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395" "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" @@ -1377,7 +1377,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b50b13d42370e0f5fc62eafdd5c2d20065eaf5458dab215ff3e20e63eea96b30" "checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" -"checksum syn 0.15.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b036b7b35e846707c0e55c2c9441fa47867c0f87fca416921db3261b1d8c741a" +"checksum syn 0.15.12 (registry+https://github.com/rust-lang/crates.io-index)" = "34ab9797e47d24cb76b8dc4d24ff36807018c7cc549c4cba050b068be0c586b0" "checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum tera 0.11.18 (registry+https://github.com/rust-lang/crates.io-index)" = "6c87cae42cc4fc480278c7583792cc5da2d51a25be916b7921cbb45c43063b8d" diff --git a/crates/ra_editor/src/symbols.rs b/crates/ra_editor/src/symbols.rs index b768b34bc59..c3c66680d58 100644 --- a/crates/ra_editor/src/symbols.rs +++ b/crates/ra_editor/src/symbols.rs @@ -3,10 +3,10 @@ use crate::TextRange; use ra_syntax::{ algo::{ visit::{visitor, Visitor}, - walk::{walk, WalkEvent}, }, ast::{self, NameOwner}, AstNode, File, SmolStr, SyntaxKind, SyntaxNodeRef, + WalkEvent, }; #[derive(Debug, Clone)] @@ -54,7 +54,7 @@ pub fn file_structure(file: &File) -> Vec { let mut res = Vec::new(); let mut stack = Vec::new(); - for event in walk(file.syntax()) { + for event in file.syntax().preorder() { match event { WalkEvent::Enter(node) => match structure_node(node) { Some(mut symbol) => { @@ -64,7 +64,7 @@ pub fn file_structure(file: &File) -> Vec { } None => (), }, - WalkEvent::Exit(node) => { + WalkEvent::Leave(node) => { if structure_node(node).is_some() { stack.pop().unwrap(); } diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index 34bb1c591bf..7efebab8bde 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml @@ -10,7 +10,7 @@ unicode-xid = "0.1.0" itertools = "0.7.8" drop_bomb = "0.1.4" parking_lot = "0.6.0" -rowan = "0.1.0" +rowan = "0.1.1" [dev-dependencies] test_utils = { path = "../test_utils" } diff --git a/crates/ra_syntax/src/algo/mod.rs b/crates/ra_syntax/src/algo/mod.rs index b4896c48228..9d2014bc7c4 100644 --- a/crates/ra_syntax/src/algo/mod.rs +++ b/crates/ra_syntax/src/algo/mod.rs @@ -1,5 +1,5 @@ pub mod visit; -pub mod walk; +// pub mod walk; use crate::{ text_utils::{contains_offset_nonstrict, is_subrange}, diff --git a/crates/ra_syntax/src/algo/walk.rs b/crates/ra_syntax/src/algo/walk.rs deleted file mode 100644 index 9afa86401bf..00000000000 --- a/crates/ra_syntax/src/algo/walk.rs +++ /dev/null @@ -1,28 +0,0 @@ -use crate::{algo::generate, SyntaxNodeRef}; - -#[derive(Debug, Copy, Clone)] -pub enum WalkEvent<'a> { - Enter(SyntaxNodeRef<'a>), - Exit(SyntaxNodeRef<'a>), -} - -pub fn walk<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator> { - 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 => WalkEvent::Exit(node.parent().unwrap()), - } - } - }; - Some(next) - }) -} diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 7a9718aad4d..3698eccd7ad 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs @@ -52,7 +52,7 @@ pub use crate::{ reparsing::AtomEdit, rowan::{SmolStr, TextRange, TextUnit}, syntax_kinds::SyntaxKind, - yellow::{Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot}, + yellow::{Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot, WalkEvent}, }; use crate::yellow::GreenNode; diff --git a/crates/ra_syntax/src/utils.rs b/crates/ra_syntax/src/utils.rs index 27248ff324b..7d0ef2fa273 100644 --- a/crates/ra_syntax/src/utils.rs +++ b/crates/ra_syntax/src/utils.rs @@ -1,6 +1,5 @@ use crate::{ - algo::walk::{walk, WalkEvent}, - File, SyntaxKind, SyntaxNodeRef, + File, SyntaxKind, SyntaxNodeRef, WalkEvent }; use std::fmt::Write; @@ -19,7 +18,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String { }; } - for event in walk(syntax) { + for event in syntax.preorder() { match event { WalkEvent::Enter(node) => { indent!(); @@ -34,7 +33,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String { } level += 1; } - WalkEvent::Exit(_) => level -= 1, + WalkEvent::Leave(_) => level -= 1, } } diff --git a/crates/ra_syntax/src/yellow/mod.rs b/crates/ra_syntax/src/yellow/mod.rs index b5c9da81352..65091721423 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 {