mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 07:04:22 +00:00
⬆️ rowan
It now stores text inline with tokens
This commit is contained in:
parent
46b4f89c92
commit
3429b32ad1
7 changed files with 12 additions and 17 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -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",
|
||||
]
|
||||
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -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"] }
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue