From 3429b32ad119756985e1a7bfa5e9e53042671f8b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Jan 2021 14:04:53 +0300 Subject: :arrow_up: rowan It now stores text inline with tokens --- Cargo.lock | 5 +++-- crates/mbe/src/syntax_bridge.rs | 4 +--- crates/syntax/Cargo.toml | 5 +---- crates/syntax/src/lib.rs | 4 ++-- crates/syntax/src/parsing/reparsing.rs | 3 +-- crates/syntax/src/parsing/text_tree_sink.rs | 4 ++-- 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" [[package]] name = "rowan" -version = "0.11.0" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bea4527c692099becd37ec777cfd6949d0534348528d2fc84ee420d2d5fac83d" dependencies = [ "hashbrown", "memoffset", "rustc-hash", - "smol_str", "text-size", ] 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> { self.text_pos += TextSize::of(text); } - let text = SmolStr::new(self.buf.as_str()); + self.inner.token(kind, self.buf.as_str()); self.buf.clear(); - self.inner.token(kind, text); - // Add whitespace between adjoint puncts let next = last.bump(); 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 [dependencies] itertools = "0.10.0" -rowan = { path="../../../rowan" } +rowan = "0.12" rustc_lexer = { version = "697.0.0", package = "rustc-ap-rustc_lexer" } rustc-hash = "1.1.0" arrayvec = "0.5.1" once_cell = "1.3.1" indexmap = "1.4.0" -# This crate transitively depends on `smol_str` via `rowan`. -# ideally, `serde` should be enabled by `rust-analyzer`, but we enable it here -# to reduce number of compilations smol_str = { version = "0.1.15", features = ["serde"] } serde = { version = "1.0.106", features = ["derive"] } 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::{ }; pub use parser::{SyntaxKind, T}; pub use rowan::{ - Direction, GreenNode, NodeOrToken, SmolStr, SyntaxText, TextRange, TextSize, TokenAtOffset, - WalkEvent, + Direction, GreenNode, NodeOrToken, SyntaxText, TextRange, TextSize, TokenAtOffset, WalkEvent, }; +pub use smol_str::SmolStr; /// `Parse` is the result of the parsing: a syntax tree and a collection of /// 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>( new_text.pop(); } - let new_token = - GreenToken::new(rowan::SyntaxKind(prev_token_kind.into()), new_text.into()); + let new_token = GreenToken::new(rowan::SyntaxKind(prev_token_kind.into()), &new_text); Some(( prev_token.replace_with(new_token), 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::{ ast, parsing::Token, syntax_node::GreenNode, - SmolStr, SyntaxError, + SyntaxError, SyntaxKind::{self, *}, SyntaxTreeBuilder, TextRange, TextSize, }; @@ -135,7 +135,7 @@ impl<'a> TextTreeSink<'a> { fn do_token(&mut self, kind: SyntaxKind, len: TextSize, n_tokens: usize) { let range = TextRange::at(self.text_pos, len); - let text: SmolStr = self.text[range].into(); + let text = &self.text[range]; self.text_pos += len; self.token_pos += n_tokens; 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 @@ use rowan::{GreenNodeBuilder, Language}; -use crate::{Parse, SmolStr, SyntaxError, SyntaxKind, TextSize}; +use crate::{Parse, SyntaxError, SyntaxKind, TextSize}; pub(crate) use rowan::{GreenNode, GreenToken, NodeOrToken}; @@ -53,7 +53,7 @@ impl SyntaxTreeBuilder { Parse::new(green, errors) } - pub fn token(&mut self, kind: SyntaxKind, text: SmolStr) { + pub fn token(&mut self, kind: SyntaxKind, text: &str) { let kind = RustLanguage::kind_to_raw(kind); self.inner.token(kind, text) } -- cgit v1.2.3