diff options
author | Aleksey Kladov <[email protected]> | 2021-01-20 11:04:53 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-01-20 11:04:53 +0000 |
commit | 3429b32ad119756985e1a7bfa5e9e53042671f8b (patch) | |
tree | c73e213a5a1a2b7a344d7f5860edfd9531dfb65d | |
parent | 46b4f89c920c314caf1a8af2abdb09732d100d67 (diff) |
:arrow_up: rowan
It now stores text inline with tokens
-rw-r--r-- | Cargo.lock | 5 | ||||
-rw-r--r-- | crates/mbe/src/syntax_bridge.rs | 4 | ||||
-rw-r--r-- | crates/syntax/Cargo.toml | 5 | ||||
-rw-r--r-- | crates/syntax/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/syntax/src/parsing/reparsing.rs | 3 | ||||
-rw-r--r-- | crates/syntax/src/parsing/text_tree_sink.rs | 4 | ||||
-rw-r--r-- | crates/syntax/src/syntax_node.rs | 4 |
7 files changed, 12 insertions, 17 deletions
diff --git a/Cargo.lock b/Cargo.lock index 130722dec..6b420eef9 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1375,12 +1375,13 @@ checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" | |||
1375 | 1375 | ||
1376 | [[package]] | 1376 | [[package]] |
1377 | name = "rowan" | 1377 | name = "rowan" |
1378 | version = "0.11.0" | 1378 | version = "0.12.0" |
1379 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1380 | checksum = "bea4527c692099becd37ec777cfd6949d0534348528d2fc84ee420d2d5fac83d" | ||
1379 | dependencies = [ | 1381 | dependencies = [ |
1380 | "hashbrown", | 1382 | "hashbrown", |
1381 | "memoffset", | 1383 | "memoffset", |
1382 | "rustc-hash", | 1384 | "rustc-hash", |
1383 | "smol_str", | ||
1384 | "text-size", | 1385 | "text-size", |
1385 | ] | 1386 | ] |
1386 | 1387 | ||
diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs index 1e1123889..0cdc175be 100644 --- a/crates/mbe/src/syntax_bridge.rs +++ b/crates/mbe/src/syntax_bridge.rs | |||
@@ -682,10 +682,8 @@ impl<'a> TreeSink for TtTreeSink<'a> { | |||
682 | self.text_pos += TextSize::of(text); | 682 | self.text_pos += TextSize::of(text); |
683 | } | 683 | } |
684 | 684 | ||
685 | let text = SmolStr::new(self.buf.as_str()); | 685 | self.inner.token(kind, self.buf.as_str()); |
686 | self.buf.clear(); | 686 | self.buf.clear(); |
687 | self.inner.token(kind, text); | ||
688 | |||
689 | // Add whitespace between adjoint puncts | 687 | // Add whitespace between adjoint puncts |
690 | let next = last.bump(); | 688 | let next = last.bump(); |
691 | if let ( | 689 | if let ( |
diff --git a/crates/syntax/Cargo.toml b/crates/syntax/Cargo.toml index 165533388..55b437a3a 100644 --- a/crates/syntax/Cargo.toml +++ b/crates/syntax/Cargo.toml | |||
@@ -12,15 +12,12 @@ doctest = false | |||
12 | 12 | ||
13 | [dependencies] | 13 | [dependencies] |
14 | itertools = "0.10.0" | 14 | itertools = "0.10.0" |
15 | rowan = { path="../../../rowan" } | 15 | rowan = "0.12" |
16 | rustc_lexer = { version = "697.0.0", package = "rustc-ap-rustc_lexer" } | 16 | rustc_lexer = { version = "697.0.0", package = "rustc-ap-rustc_lexer" } |
17 | rustc-hash = "1.1.0" | 17 | rustc-hash = "1.1.0" |
18 | arrayvec = "0.5.1" | 18 | arrayvec = "0.5.1" |
19 | once_cell = "1.3.1" | 19 | once_cell = "1.3.1" |
20 | indexmap = "1.4.0" | 20 | indexmap = "1.4.0" |
21 | # This crate transitively depends on `smol_str` via `rowan`. | ||
22 | # ideally, `serde` should be enabled by `rust-analyzer`, but we enable it here | ||
23 | # to reduce number of compilations | ||
24 | smol_str = { version = "0.1.15", features = ["serde"] } | 21 | smol_str = { version = "0.1.15", features = ["serde"] } |
25 | serde = { version = "1.0.106", features = ["derive"] } | 22 | serde = { version = "1.0.106", features = ["derive"] } |
26 | 23 | ||
diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs index ea7482bb1..11294c5b2 100644 --- a/crates/syntax/src/lib.rs +++ b/crates/syntax/src/lib.rs | |||
@@ -56,9 +56,9 @@ pub use crate::{ | |||
56 | }; | 56 | }; |
57 | pub use parser::{SyntaxKind, T}; | 57 | pub use parser::{SyntaxKind, T}; |
58 | pub use rowan::{ | 58 | pub use rowan::{ |
59 | Direction, GreenNode, NodeOrToken, SmolStr, SyntaxText, TextRange, TextSize, TokenAtOffset, | 59 | Direction, GreenNode, NodeOrToken, SyntaxText, TextRange, TextSize, TokenAtOffset, WalkEvent, |
60 | WalkEvent, | ||
61 | }; | 60 | }; |
61 | pub use smol_str::SmolStr; | ||
62 | 62 | ||
63 | /// `Parse` is the result of the parsing: a syntax tree and a collection of | 63 | /// `Parse` is the result of the parsing: a syntax tree and a collection of |
64 | /// errors. | 64 | /// errors. |
diff --git a/crates/syntax/src/parsing/reparsing.rs b/crates/syntax/src/parsing/reparsing.rs index 76f01084c..3d637bf91 100644 --- a/crates/syntax/src/parsing/reparsing.rs +++ b/crates/syntax/src/parsing/reparsing.rs | |||
@@ -73,8 +73,7 @@ fn reparse_token<'node>( | |||
73 | new_text.pop(); | 73 | new_text.pop(); |
74 | } | 74 | } |
75 | 75 | ||
76 | let new_token = | 76 | let new_token = GreenToken::new(rowan::SyntaxKind(prev_token_kind.into()), &new_text); |
77 | GreenToken::new(rowan::SyntaxKind(prev_token_kind.into()), new_text.into()); | ||
78 | Some(( | 77 | Some(( |
79 | prev_token.replace_with(new_token), | 78 | prev_token.replace_with(new_token), |
80 | new_err.into_iter().collect(), | 79 | new_err.into_iter().collect(), |
diff --git a/crates/syntax/src/parsing/text_tree_sink.rs b/crates/syntax/src/parsing/text_tree_sink.rs index ce27c3dd9..d5ddc076f 100644 --- a/crates/syntax/src/parsing/text_tree_sink.rs +++ b/crates/syntax/src/parsing/text_tree_sink.rs | |||
@@ -8,7 +8,7 @@ use crate::{ | |||
8 | ast, | 8 | ast, |
9 | parsing::Token, | 9 | parsing::Token, |
10 | syntax_node::GreenNode, | 10 | syntax_node::GreenNode, |
11 | SmolStr, SyntaxError, | 11 | SyntaxError, |
12 | SyntaxKind::{self, *}, | 12 | SyntaxKind::{self, *}, |
13 | SyntaxTreeBuilder, TextRange, TextSize, | 13 | SyntaxTreeBuilder, TextRange, TextSize, |
14 | }; | 14 | }; |
@@ -135,7 +135,7 @@ impl<'a> TextTreeSink<'a> { | |||
135 | 135 | ||
136 | fn do_token(&mut self, kind: SyntaxKind, len: TextSize, n_tokens: usize) { | 136 | fn do_token(&mut self, kind: SyntaxKind, len: TextSize, n_tokens: usize) { |
137 | let range = TextRange::at(self.text_pos, len); | 137 | let range = TextRange::at(self.text_pos, len); |
138 | let text: SmolStr = self.text[range].into(); | 138 | let text = &self.text[range]; |
139 | self.text_pos += len; | 139 | self.text_pos += len; |
140 | self.token_pos += n_tokens; | 140 | self.token_pos += n_tokens; |
141 | self.inner.token(kind, text); | 141 | self.inner.token(kind, text); |
diff --git a/crates/syntax/src/syntax_node.rs b/crates/syntax/src/syntax_node.rs index cc30138fa..8f643b228 100644 --- a/crates/syntax/src/syntax_node.rs +++ b/crates/syntax/src/syntax_node.rs | |||
@@ -8,7 +8,7 @@ | |||
8 | 8 | ||
9 | use rowan::{GreenNodeBuilder, Language}; | 9 | use rowan::{GreenNodeBuilder, Language}; |
10 | 10 | ||
11 | use crate::{Parse, SmolStr, SyntaxError, SyntaxKind, TextSize}; | 11 | use crate::{Parse, SyntaxError, SyntaxKind, TextSize}; |
12 | 12 | ||
13 | pub(crate) use rowan::{GreenNode, GreenToken, NodeOrToken}; | 13 | pub(crate) use rowan::{GreenNode, GreenToken, NodeOrToken}; |
14 | 14 | ||
@@ -53,7 +53,7 @@ impl SyntaxTreeBuilder { | |||
53 | Parse::new(green, errors) | 53 | Parse::new(green, errors) |
54 | } | 54 | } |
55 | 55 | ||
56 | pub fn token(&mut self, kind: SyntaxKind, text: SmolStr) { | 56 | pub fn token(&mut self, kind: SyntaxKind, text: &str) { |
57 | let kind = RustLanguage::kind_to_raw(kind); | 57 | let kind = RustLanguage::kind_to_raw(kind); |
58 | self.inner.token(kind, text) | 58 | self.inner.token(kind, text) |
59 | } | 59 | } |