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

Commit

Permalink
feat: fork rowan and replace rslint_rowan (#1714)
Browse files Browse the repository at this point in the history
Co-authored-by: Yasser Elassal <[email protected]>
  • Loading branch information
ematipico and yassere authored Oct 21, 2021
1 parent 401d630 commit 6799f74
Show file tree
Hide file tree
Showing 40 changed files with 3,155 additions and 2,818 deletions.
74 changes: 17 additions & 57 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/formatter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"

[dependencies]
rslint_parser = { path = "../rslint_parser" }
rslint_rowan = { path = "../rslint_rowan" }
rome_rowan = { path = "../rome_rowan" }
path = { version = "0.0.0", path = "../path" }
core = { version = "0.0.0", path = "../core" }

Expand Down
2 changes: 1 addition & 1 deletion crates/formatter/src/cst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl ToFormatElement for SyntaxToken {
SyntaxKind::STRING => rslint_parser::ast::String::cast(self.clone())
.unwrap()
.to_format_element(formatter),
_ => Some(token(self.text().as_str())),
_ => Some(token(self.text())),
}
}
}
4 changes: 2 additions & 2 deletions crates/formatter/src/format_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ fn tokenize_token(syntax_token: SyntaxToken) -> FormatElement {
SyntaxKind::NULL_KW => token("null"),
SyntaxKind::TRUE_KW => token("true"),
SyntaxKind::FALSE_KW => token("false"),
SyntaxKind::STRING => token(syntax_token.text().as_str()),
SyntaxKind::NUMBER => token(syntax_token.text().as_str()),
SyntaxKind::STRING => token(syntax_token.text()),
SyntaxKind::NUMBER => token(syntax_token.text()),
SyntaxKind::MINUS => token("-"),
_ => panic!("Unsupported JSON token {:?}", syntax_token),
}
Expand Down
8 changes: 4 additions & 4 deletions crates/formatter/src/formatter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::printer::Printer;
use crate::{concat_elements, token, FormatElement, FormatOptions, FormatResult, ToFormatElement};
use rome_rowan::SyntaxElement;
use rslint_parser::ast::AstChildren;
use rslint_parser::{AstNode, SyntaxNode, SyntaxToken};
use rslint_rowan::SyntaxElement;

/// Handles the formatting of a CST and stores the options how the CST should be formatted (user preferences).
/// The formatter is passed to the [ToFormatElement] implementation of every node in the CST so that they
Expand Down Expand Up @@ -81,11 +81,11 @@ impl Formatter {
///
/// use rome_formatter::{Formatter, token};
/// use rslint_parser::{SyntaxNode, T, SyntaxToken};
/// use rslint_rowan::{GreenNode, GreenToken, SmolStr, NodeOrToken, SyntaxKind};
/// use rome_rowan::{GreenNode, GreenToken, NodeOrToken, SyntaxKind};
///
/// let node = SyntaxNode::new_root(
/// GreenNode::new(SyntaxKind(1), vec![
/// NodeOrToken::Token(GreenToken::new(SyntaxKind(T![=>].into()), SmolStr::new("=>")))
/// NodeOrToken::Token(GreenToken::new(SyntaxKind(T![=>].into()), "=>"))
/// ])
/// );
///
Expand Down Expand Up @@ -134,7 +134,7 @@ impl Formatter {
// need to be tracked for every node.
self.format_raw(&child_node)
}
SyntaxElement::Token(syntax_token) => token(syntax_token.text().as_str()),
SyntaxElement::Token(syntax_token) => token(syntax_token.text()),
}))
}
}
23 changes: 23 additions & 0 deletions crates/rome_rowan/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "rome_rowan"
version = "0.0.0"
authors = ["Aleksey Kladov <[email protected]>"]
repository = "https://github.com/rust-analyzer/rowan"
license = "MIT OR Apache-2.0"
description = "Library for generic lossless syntax trees"
edition = "2018"

[dependencies]
rustc-hash = "1.0.1"
hashbrown = { version = "0.11.2", features = ["inline-more"], default-features = false }
text-size = "1.1.0"
memoffset = "0.6"
countme = "2.0.0"

serde = { version = "1.0.89", optional = true, default-features = false }

[dev-dependencies]
m_lexer = "0.0.4"

[features]
serde1 = [ "serde", "text-size/serde" ]
Loading

0 comments on commit 6799f74

Please sign in to comment.