aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock14
-rw-r--r--crates/ra_editor/src/symbols.rs6
-rw-r--r--crates/ra_syntax/Cargo.toml2
-rw-r--r--crates/ra_syntax/src/algo/mod.rs2
-rw-r--r--crates/ra_syntax/src/algo/walk.rs28
-rw-r--r--crates/ra_syntax/src/lib.rs2
-rw-r--r--crates/ra_syntax/src/utils.rs7
-rw-r--r--crates/ra_syntax/src/yellow/mod.rs14
8 files changed, 26 insertions, 49 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 79da84ebc..bb93b8b0e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -484,7 +484,7 @@ dependencies = [
484 "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 484 "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
485 "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", 485 "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
486 "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", 486 "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
487 "syn 0.15.11 (registry+https://github.com/rust-lang/crates.io-index)", 487 "syn 0.15.12 (registry+https://github.com/rust-lang/crates.io-index)",
488] 488]
489 489
490[[package]] 490[[package]]
@@ -684,7 +684,7 @@ dependencies = [
684 "drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 684 "drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
685 "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", 685 "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
686 "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", 686 "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
687 "rowan 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 687 "rowan 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
688 "test_utils 0.1.0", 688 "test_utils 0.1.0",
689 "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 689 "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
690 "walkdir 2.2.5 (registry+https://github.com/rust-lang/crates.io-index)", 690 "walkdir 2.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -804,7 +804,7 @@ dependencies = [
804 804
805[[package]] 805[[package]]
806name = "rowan" 806name = "rowan"
807version = "0.1.0" 807version = "0.1.1"
808source = "registry+https://github.com/rust-lang/crates.io-index" 808source = "registry+https://github.com/rust-lang/crates.io-index"
809dependencies = [ 809dependencies = [
810 "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", 810 "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"
898dependencies = [ 898dependencies = [
899 "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", 899 "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
900 "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", 900 "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
901 "syn 0.15.11 (registry+https://github.com/rust-lang/crates.io-index)", 901 "syn 0.15.12 (registry+https://github.com/rust-lang/crates.io-index)",
902] 902]
903 903
904[[package]] 904[[package]]
@@ -973,7 +973,7 @@ dependencies = [
973 973
974[[package]] 974[[package]]
975name = "syn" 975name = "syn"
976version = "0.15.11" 976version = "0.15.12"
977source = "registry+https://github.com/rust-lang/crates.io-index" 977source = "registry+https://github.com/rust-lang/crates.io-index"
978dependencies = [ 978dependencies = [
979 "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", 979 "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"
1355"checksum relative-path 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "e614f96449605730b4f7ad2c019e88c1652d730634b4eba07b810801856635e3" 1355"checksum relative-path 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "e614f96449605730b4f7ad2c019e88c1652d730634b4eba07b810801856635e3"
1356"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" 1356"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
1357"checksum ron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c48677d8a9247a4e0d1f3f9cb4b0a8e29167fdc3c04f383a5e669cd7a960ae0f" 1357"checksum ron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c48677d8a9247a4e0d1f3f9cb4b0a8e29167fdc3c04f383a5e669cd7a960ae0f"
1358"checksum rowan 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4a1a7366ece9deee5e7df8316a136d585d5c5042854c2297f7f1aee3014c9130" 1358"checksum rowan 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bb1f952404091f61bfea7cd09c564090a0fcee3d22223f98084e8756e01c04d"
1359"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395" 1359"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395"
1360"checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" 1360"checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8"
1361"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" 1361"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"
1377"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" 1377"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
1378"checksum superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b50b13d42370e0f5fc62eafdd5c2d20065eaf5458dab215ff3e20e63eea96b30" 1378"checksum superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b50b13d42370e0f5fc62eafdd5c2d20065eaf5458dab215ff3e20e63eea96b30"
1379"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" 1379"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741"
1380"checksum syn 0.15.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b036b7b35e846707c0e55c2c9441fa47867c0f87fca416921db3261b1d8c741a" 1380"checksum syn 0.15.12 (registry+https://github.com/rust-lang/crates.io-index)" = "34ab9797e47d24cb76b8dc4d24ff36807018c7cc549c4cba050b068be0c586b0"
1381"checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7" 1381"checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7"
1382"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" 1382"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
1383"checksum tera 0.11.18 (registry+https://github.com/rust-lang/crates.io-index)" = "6c87cae42cc4fc480278c7583792cc5da2d51a25be916b7921cbb45c43063b8d" 1383"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 b768b34bc..c3c66680d 100644
--- a/crates/ra_editor/src/symbols.rs
+++ b/crates/ra_editor/src/symbols.rs
@@ -3,10 +3,10 @@ use crate::TextRange;
3use ra_syntax::{ 3use ra_syntax::{
4 algo::{ 4 algo::{
5 visit::{visitor, Visitor}, 5 visit::{visitor, Visitor},
6 walk::{walk, WalkEvent},
7 }, 6 },
8 ast::{self, NameOwner}, 7 ast::{self, NameOwner},
9 AstNode, File, SmolStr, SyntaxKind, SyntaxNodeRef, 8 AstNode, File, SmolStr, SyntaxKind, SyntaxNodeRef,
9 WalkEvent,
10}; 10};
11 11
12#[derive(Debug, Clone)] 12#[derive(Debug, Clone)]
@@ -54,7 +54,7 @@ pub fn file_structure(file: &File) -> Vec<StructureNode> {
54 let mut res = Vec::new(); 54 let mut res = Vec::new();
55 let mut stack = Vec::new(); 55 let mut stack = Vec::new();
56 56
57 for event in walk(file.syntax()) { 57 for event in file.syntax().preorder() {
58 match event { 58 match event {
59 WalkEvent::Enter(node) => match structure_node(node) { 59 WalkEvent::Enter(node) => match structure_node(node) {
60 Some(mut symbol) => { 60 Some(mut symbol) => {
@@ -64,7 +64,7 @@ pub fn file_structure(file: &File) -> Vec<StructureNode> {
64 } 64 }
65 None => (), 65 None => (),
66 }, 66 },
67 WalkEvent::Exit(node) => { 67 WalkEvent::Leave(node) => {
68 if structure_node(node).is_some() { 68 if structure_node(node).is_some() {
69 stack.pop().unwrap(); 69 stack.pop().unwrap();
70 } 70 }
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml
index 34bb1c591..7efebab8b 100644
--- a/crates/ra_syntax/Cargo.toml
+++ b/crates/ra_syntax/Cargo.toml
@@ -10,7 +10,7 @@ unicode-xid = "0.1.0"
10itertools = "0.7.8" 10itertools = "0.7.8"
11drop_bomb = "0.1.4" 11drop_bomb = "0.1.4"
12parking_lot = "0.6.0" 12parking_lot = "0.6.0"
13rowan = "0.1.0" 13rowan = "0.1.1"
14 14
15[dev-dependencies] 15[dev-dependencies]
16test_utils = { path = "../test_utils" } 16test_utils = { path = "../test_utils" }
diff --git a/crates/ra_syntax/src/algo/mod.rs b/crates/ra_syntax/src/algo/mod.rs
index b4896c482..9d2014bc7 100644
--- a/crates/ra_syntax/src/algo/mod.rs
+++ b/crates/ra_syntax/src/algo/mod.rs
@@ -1,5 +1,5 @@
1pub mod visit; 1pub mod visit;
2pub mod walk; 2// pub mod walk;
3 3
4use crate::{ 4use crate::{
5 text_utils::{contains_offset_nonstrict, is_subrange}, 5 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 9afa86401..000000000
--- a/crates/ra_syntax/src/algo/walk.rs
+++ /dev/null
@@ -1,28 +0,0 @@
1use crate::{algo::generate, SyntaxNodeRef};
2
3#[derive(Debug, Copy, Clone)]
4pub enum WalkEvent<'a> {
5 Enter(SyntaxNodeRef<'a>),
6 Exit(SyntaxNodeRef<'a>),
7}
8
9pub fn walk<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator<Item = WalkEvent<'a>> {
10 generate(Some(WalkEvent::Enter(root)), move |pos| {
11 let next = match *pos {
12 WalkEvent::Enter(node) => match node.first_child() {
13 Some(child) => WalkEvent::Enter(child),
14 None => WalkEvent::Exit(node),
15 },
16 WalkEvent::Exit(node) => {
17 if node == root {
18 return None;
19 }
20 match node.next_sibling() {
21 Some(sibling) => WalkEvent::Enter(sibling),
22 None => WalkEvent::Exit(node.parent().unwrap()),
23 }
24 }
25 };
26 Some(next)
27 })
28}
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index 7a9718aad..3698eccd7 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -52,7 +52,7 @@ pub use crate::{
52 reparsing::AtomEdit, 52 reparsing::AtomEdit,
53 rowan::{SmolStr, TextRange, TextUnit}, 53 rowan::{SmolStr, TextRange, TextUnit},
54 syntax_kinds::SyntaxKind, 54 syntax_kinds::SyntaxKind,
55 yellow::{Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot}, 55 yellow::{Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot, WalkEvent},
56}; 56};
57 57
58use crate::yellow::GreenNode; 58use crate::yellow::GreenNode;
diff --git a/crates/ra_syntax/src/utils.rs b/crates/ra_syntax/src/utils.rs
index 27248ff32..7d0ef2fa2 100644
--- a/crates/ra_syntax/src/utils.rs
+++ b/crates/ra_syntax/src/utils.rs
@@ -1,6 +1,5 @@
1use crate::{ 1use crate::{
2 algo::walk::{walk, WalkEvent}, 2 File, SyntaxKind, SyntaxNodeRef, WalkEvent
3 File, SyntaxKind, SyntaxNodeRef,
4}; 3};
5use std::fmt::Write; 4use std::fmt::Write;
6 5
@@ -19,7 +18,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String {
19 }; 18 };
20 } 19 }
21 20
22 for event in walk(syntax) { 21 for event in syntax.preorder() {
23 match event { 22 match event {
24 WalkEvent::Enter(node) => { 23 WalkEvent::Enter(node) => {
25 indent!(); 24 indent!();
@@ -34,7 +33,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String {
34 } 33 }
35 level += 1; 34 level += 1;
36 } 35 }
37 WalkEvent::Exit(_) => level -= 1, 36 WalkEvent::Leave(_) => level -= 1,
38 } 37 }
39 } 38 }
40 39
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
12pub(crate) use self::builder::GreenBuilder; 12pub(crate) use self::builder::GreenBuilder;
13pub use rowan::TreeRoot; 13pub use rowan::{TreeRoot, WalkEvent};
14 14
15#[derive(Debug, Clone, Copy)] 15#[derive(Debug, Clone, Copy)]
16pub enum RaTypes {} 16pub 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
87impl<R: TreeRoot<RaTypes>> SyntaxNode<R> { 93impl<R: TreeRoot<RaTypes>> SyntaxNode<R> {