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]]
|
[[package]]
|
||||||
name = "rowan"
|
name = "rowan"
|
||||||
version = "0.11.0"
|
version = "0.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bea4527c692099becd37ec777cfd6949d0534348528d2fc84ee420d2d5fac83d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
"memoffset",
|
"memoffset",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"smol_str",
|
|
||||||
"text-size",
|
"text-size",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -682,10 +682,8 @@ impl<'a> TreeSink for TtTreeSink<'a> {
|
||||||
self.text_pos += TextSize::of(text);
|
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.buf.clear();
|
||||||
self.inner.token(kind, text);
|
|
||||||
|
|
||||||
// Add whitespace between adjoint puncts
|
// Add whitespace between adjoint puncts
|
||||||
let next = last.bump();
|
let next = last.bump();
|
||||||
if let (
|
if let (
|
||||||
|
|
|
@ -12,15 +12,12 @@ doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
itertools = "0.10.0"
|
itertools = "0.10.0"
|
||||||
rowan = { path="../../../rowan" }
|
rowan = "0.12"
|
||||||
rustc_lexer = { version = "697.0.0", package = "rustc-ap-rustc_lexer" }
|
rustc_lexer = { version = "697.0.0", package = "rustc-ap-rustc_lexer" }
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
arrayvec = "0.5.1"
|
arrayvec = "0.5.1"
|
||||||
once_cell = "1.3.1"
|
once_cell = "1.3.1"
|
||||||
indexmap = "1.4.0"
|
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"] }
|
smol_str = { version = "0.1.15", features = ["serde"] }
|
||||||
serde = { version = "1.0.106", features = ["derive"] }
|
serde = { version = "1.0.106", features = ["derive"] }
|
||||||
|
|
||||||
|
|
|
@ -56,9 +56,9 @@ pub use crate::{
|
||||||
};
|
};
|
||||||
pub use parser::{SyntaxKind, T};
|
pub use parser::{SyntaxKind, T};
|
||||||
pub use rowan::{
|
pub use rowan::{
|
||||||
Direction, GreenNode, NodeOrToken, SmolStr, SyntaxText, TextRange, TextSize, TokenAtOffset,
|
Direction, GreenNode, NodeOrToken, SyntaxText, TextRange, TextSize, TokenAtOffset, WalkEvent,
|
||||||
WalkEvent,
|
|
||||||
};
|
};
|
||||||
|
pub use smol_str::SmolStr;
|
||||||
|
|
||||||
/// `Parse` is the result of the parsing: a syntax tree and a collection of
|
/// `Parse` is the result of the parsing: a syntax tree and a collection of
|
||||||
/// errors.
|
/// errors.
|
||||||
|
|
|
@ -73,8 +73,7 @@ fn reparse_token<'node>(
|
||||||
new_text.pop();
|
new_text.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_token =
|
let new_token = GreenToken::new(rowan::SyntaxKind(prev_token_kind.into()), &new_text);
|
||||||
GreenToken::new(rowan::SyntaxKind(prev_token_kind.into()), new_text.into());
|
|
||||||
Some((
|
Some((
|
||||||
prev_token.replace_with(new_token),
|
prev_token.replace_with(new_token),
|
||||||
new_err.into_iter().collect(),
|
new_err.into_iter().collect(),
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
||||||
ast,
|
ast,
|
||||||
parsing::Token,
|
parsing::Token,
|
||||||
syntax_node::GreenNode,
|
syntax_node::GreenNode,
|
||||||
SmolStr, SyntaxError,
|
SyntaxError,
|
||||||
SyntaxKind::{self, *},
|
SyntaxKind::{self, *},
|
||||||
SyntaxTreeBuilder, TextRange, TextSize,
|
SyntaxTreeBuilder, TextRange, TextSize,
|
||||||
};
|
};
|
||||||
|
@ -135,7 +135,7 @@ impl<'a> TextTreeSink<'a> {
|
||||||
|
|
||||||
fn do_token(&mut self, kind: SyntaxKind, len: TextSize, n_tokens: usize) {
|
fn do_token(&mut self, kind: SyntaxKind, len: TextSize, n_tokens: usize) {
|
||||||
let range = TextRange::at(self.text_pos, len);
|
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.text_pos += len;
|
||||||
self.token_pos += n_tokens;
|
self.token_pos += n_tokens;
|
||||||
self.inner.token(kind, text);
|
self.inner.token(kind, text);
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
use rowan::{GreenNodeBuilder, Language};
|
use rowan::{GreenNodeBuilder, Language};
|
||||||
|
|
||||||
use crate::{Parse, SmolStr, SyntaxError, SyntaxKind, TextSize};
|
use crate::{Parse, SyntaxError, SyntaxKind, TextSize};
|
||||||
|
|
||||||
pub(crate) use rowan::{GreenNode, GreenToken, NodeOrToken};
|
pub(crate) use rowan::{GreenNode, GreenToken, NodeOrToken};
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ impl SyntaxTreeBuilder {
|
||||||
Parse::new(green, errors)
|
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);
|
let kind = RustLanguage::kind_to_raw(kind);
|
||||||
self.inner.token(kind, text)
|
self.inner.token(kind, text)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue