Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
rebasing and adapting code to slots
Browse files Browse the repository at this point in the history
  • Loading branch information
xunilrj committed Nov 11, 2021
1 parent 1977fbf commit 8e328e6
Show file tree
Hide file tree
Showing 100 changed files with 456 additions and 3,596 deletions.
2 changes: 1 addition & 1 deletion crates/rome_formatter/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Formatter {
// need to be tracked for every node.
self.format_raw(&child_node)
}
SyntaxElement::Token(syntax_token) => token(&syntax_token.text_with_trivia()),
SyntaxElement::Token(syntax_token) => token(syntax_token.text_with_trivia()),
}))
}
}
2 changes: 1 addition & 1 deletion crates/rome_formatter/src/ts/statements/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{concat_elements, hard_line_break, join_elements, FormatElement, Formatter};
use crate::{hard_line_break, join_elements, FormatElement, Formatter};
use rslint_parser::ast::{AstNodeList, JsAnyStatement};
use rslint_parser::AstNode;

Expand Down
3 changes: 0 additions & 3 deletions crates/rome_rowan/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ impl<L: Language> SyntaxNode<L> {
self.raw.text_range()
}

<<<<<<< HEAD
=======
pub fn text_with_trivia_range(&self) -> TextRange {
self.raw.text_with_trivia_range()
}
Expand All @@ -153,7 +151,6 @@ impl<L: Language> SyntaxNode<L> {
self.raw.index()
}

>>>>>>> c96756449 (fixing text and text_with_trivia and ranges)
pub fn text(&self) -> SyntaxText {
self.raw.text()
}
Expand Down
39 changes: 12 additions & 27 deletions crates/rome_rowan/src/green/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ impl GreenNodeData {

pub fn leading_trailing_total_len(&self) -> (TextSize, TextSize, TextSize) {
let leading_len = match self.slice().first() {
Some(GreenChild::Node { node, .. }) => node.leading_trailing_total_len().0,
Some(GreenChild::Token { token, .. }) => token.leading_trailing_total_len().0,
None => 0.into(),
Some(Slot::Node { node, .. }) => node.leading_trailing_total_len().0,
Some(Slot::Token { token, .. }) => token.leading_trailing_total_len().0,
_ => 0.into(),
};

let trailing_len = match self.slice().last() {
Some(GreenChild::Node { node, .. }) => node.leading_trailing_total_len().1,
Some(GreenChild::Token { token, .. }) => token.leading_trailing_total_len().1,
None => 0.into(),
Some(Slot::Node { node, .. }) => node.leading_trailing_total_len().1,
Some(Slot::Token { token, .. }) => token.leading_trailing_total_len().1,
_ => 0.into(),
};

(
Expand Down Expand Up @@ -279,22 +279,12 @@ impl GreenNode {
I: IntoIterator<Item = Option<GreenElement>>,
I::IntoIter: ExactSizeIterator,
{
<<<<<<< HEAD
let mut text_len: TextSize = 0.into();
let slots = slots.into_iter().map(|el| {
let rel_offset = text_len;
text_len += el.text_len();
=======
// println!("GreenNode: {:?}", kind);
let mut text_with_trivia_len: TextSize = 0.into();
let children = children.into_iter().map(|el| {
let slots = slots.into_iter().map(|el| {
let rel_offset = text_with_trivia_len;
text_with_trivia_len += el.text_with_trivia_len();
// println!("\t\t{:?} text_len:{:?}", el, el.text_len());
>>>>>>> c96756449 (fixing text and text_with_trivia and ranges)
match el {
Some(el) => {
text_len += el.text_len();
text_with_trivia_len += el.text_with_trivia_len();
match el {
NodeOrToken::Node(node) => Slot::Node { rel_offset, node },
NodeOrToken::Token(token) => Slot::Token { rel_offset, token },
Expand Down Expand Up @@ -358,17 +348,12 @@ impl Slot {
}
#[inline]
fn rel_range(&self) -> TextRange {
<<<<<<< HEAD
let text_len = match self.as_ref() {
None => TextSize::from(0),
Some(element) => element.text_len(),
let len = match self {
Slot::Node { node, .. } => node.text_with_trivia_len(),
Slot::Token { token, .. } => token.text_with_trivia_len(),
_ => 0.into(),
};

TextRange::at(self.rel_offset(), text_len)
=======
let len = self.as_ref().text_with_trivia_len();
TextRange::at(self.rel_offset(), len)
>>>>>>> c96756449 (fixing text and text_with_trivia and ranges)
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/rome_rowan/src/green/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ impl Trivia {
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[allow(clippy::box_vec)]
pub enum GreenTokenTrivia {
None,
Whitespace(usize),
Expand Down
7 changes: 2 additions & 5 deletions crates/rome_rowan/src/tree_builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
cow_mut::CowMut,
green::{GreenElement, GreenTokenTrivia, NodeCache},
GreenNode, Language, Language, NodeOrToken, NodeOrToken, SyntaxNode, SyntaxNode,
GreenNode, Language, NodeOrToken, SyntaxNode,
};

/// A checkpoint for maybe wrapping a node. See `GreenNodeBuilder::checkpoint` for details.
Expand Down Expand Up @@ -67,18 +67,15 @@ impl<L: Language> TreeBuilder<'_, L> {
leading: GreenTokenTrivia,
trailing: GreenTokenTrivia,
) {
// println!("TreeBuilder::token_with_trivia {:?}", kind);
let (hash, token) =
self.cache
.token_with_trivia(L::kind_to_raw(kind), text, leading, trailing);
// println!("\ttoken: {:?}", token);
self.children.push((hash, token.into()));
self.children.push((hash, Some(token.into())));
}

/// Start new node and make it current.
#[inline]
pub fn start_node(&mut self, kind: L::Kind) {
// println!("TreeBuilder::start_node {:?}", kind);
let len = self.children.len();
self.parents.push((kind, len));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rslint_parser/src/lossless_tree_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ impl<'a> LosslessTreeSink<'a> {
};

use GreenTokenTrivia::*;
use Trivia::Whitespace as TWhitespace;
use Trivia::Comment as TComments;
use Trivia::Whitespace as TWhitespace;
trivia = match (trivia, current_trivia) {
(None, TWhitespace(len)) => Whitespace(len),
(None, TComments(len)) => Comment(len),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<<<<<<< HEAD
[email protected]
=======
[email protected]
>>>>>>> 56d750195 (trim format_raw when formatter finds an error)
[email protected]
[email protected]
[email protected]
[email protected]
Expand All @@ -12,85 +8,28 @@ [email protected]
None [email protected] "(" None
[email protected]
[email protected]
<<<<<<< HEAD
[email protected]
[email protected] "foo"
[email protected] " "
[email protected] "+"
[email protected] ")"
[email protected] ";"
[email protected] "\n"
[email protected]
[email protected]
[email protected]
[email protected] "foo"
[email protected] " "
[email protected] "+"
[email protected] " "
=======
[email protected]
None [email protected] "foo" Whitespace(1)
None [email protected] "+" None
None [email protected] ")" None
None [email protected] ";" None
EXPR_STMT@11..22
JS_EXPRESSION_STATEMENT@11..22
[email protected]
[email protected]
<<<<<<< HEAD
<<<<<<< HEAD
"\n" [email protected] "foo" " "
[email protected] "+" " "
>>>>>>> 56d750195 (trim format_raw when formatter finds an error)
=======
Whitespace(1) [email protected] "foo" Whitespace(1)
None [email protected] "+" Whitespace(1)
>>>>>>> 03257ad46 (greentoken slice contains everything from first leading to last trailing trivia)
=======
Whitespace(1) [email protected] "foo" Whitespace(1)
None [email protected] "+" Whitespace(1)
>>>>>>> c96756449 (fixing text and text_with_trivia and ranges)
[email protected]
None [email protected] "*" Whitespace(1)
[email protected]
<<<<<<< HEAD
<<<<<<< HEAD
[email protected] "2"
[email protected] ";"
[email protected] "\n"
[email protected]
[email protected]
[email protected]
[email protected] "!"
[email protected]
[email protected] "foo"
[email protected] " "
[email protected] "*"
[email protected] " "
=======
[email protected] "2"
[email protected] ";"
=======
None [email protected] "2" None
None [email protected] ";" None
>>>>>>> 03257ad46 (greentoken slice contains everything from first leading to last trailing trivia)
[email protected]
[email protected]
[email protected]
[email protected]
Whitespace(1) [email protected] "!" None
[email protected]
<<<<<<< HEAD
<<<<<<< HEAD
[email protected] "foo" " "
[email protected] "*" " "
>>>>>>> 56d750195 (trim format_raw when formatter finds an error)
=======
None [email protected] "foo" Whitespace(1)
None [email protected] "*" Whitespace(1)
>>>>>>> 03257ad46 (greentoken slice contains everything from first leading to last trailing trivia)
=======
None [email protected] "foo" Whitespace(1)
None [email protected] "*" Whitespace(1)
>>>>>>> c96756449 (fixing text and text_with_trivia and ranges)
[email protected]
None [email protected] "bar" None
None [email protected] ";" None
Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,18 @@
<<<<<<< HEAD
[email protected]
=======
[email protected]
>>>>>>> 56d750195 (trim format_raw when formatter finds an error)
[email protected]
[email protected]
[email protected]
[email protected]
None [email protected] "async" Whitespace(1)
[email protected]
None [email protected] "(" None
[email protected]
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
[email protected] ")"
[email protected] " "
[email protected] "=>"
[email protected] " "
[email protected]
[email protected] "{"
[email protected] " "
[email protected]
[email protected]
[email protected] "let"
[email protected] " "
=======
[email protected] ")" " "
[email protected] "=>" " "
=======
None [email protected] ")" Whitespace(1)
None [email protected] "=>" Whitespace(1)
>>>>>>> 03257ad46 (greentoken slice contains everything from first leading to last trailing trivia)
=======
None [email protected] ")" Whitespace(1)
None [email protected] "=>" Whitespace(1)
>>>>>>> c96756449 (fixing text and text_with_trivia and ranges)
[email protected]
[email protected]
None [email protected] "{" Whitespace(1)
[email protected]
[email protected]
<<<<<<< HEAD
<<<<<<< HEAD
[email protected] "let" " "
>>>>>>> 56d750195 (trim format_raw when formatter finds an error)
=======
None [email protected] "let" Whitespace(1)
>>>>>>> 03257ad46 (greentoken slice contains everything from first leading to last trailing trivia)
=======
None [email protected] "let" Whitespace(1)
>>>>>>> c96756449 (fixing text and text_with_trivia and ranges)
[email protected]
[email protected]
[email protected]
Expand All @@ -67,40 +31,12 @@ [email protected]
[email protected]
None [email protected] "(" None
[email protected]
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
[email protected] ")"
[email protected] " "
[email protected]
[email protected] "{"
[email protected] "\n "
[email protected]
[email protected]
[email protected] "let"
[email protected] " "
=======
[email protected] ")" " "
=======
None [email protected] ")" Whitespace(1)
>>>>>>> 03257ad46 (greentoken slice contains everything from first leading to last trailing trivia)
=======
None [email protected] ")" Whitespace(1)
>>>>>>> c96756449 (fixing text and text_with_trivia and ranges)
[email protected]
[email protected]
None [email protected] "{" None
[email protected]
[email protected]
<<<<<<< HEAD
<<<<<<< HEAD
"\n " [email protected] "let" " "
>>>>>>> 56d750195 (trim format_raw when formatter finds an error)
=======
Whitespace(4) [email protected] "let" Whitespace(1)
>>>>>>> 03257ad46 (greentoken slice contains everything from first leading to last trailing trivia)
=======
Whitespace(4) [email protected] "let" Whitespace(1)
>>>>>>> c96756449 (fixing text and text_with_trivia and ranges)
[email protected]
[email protected]
[email protected]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<<<<<<< HEAD
[email protected]
=======
[email protected]
>>>>>>> 56d750195 (trim format_raw when formatter finds an error)
[email protected]
[email protected]
[email protected]
None [email protected] "class" Whitespace(1)
Expand Down
Loading

0 comments on commit 8e328e6

Please sign in to comment.