Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove tree-sitter-facade #632

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ license = "MIT"
[workspace]
members = ["topiary", "topiary-cli", "topiary-queries", "topiary-playground"]
exclude = ["samples"]
resolver = "2"

[profile.release]
lto = true
Expand Down Expand Up @@ -59,8 +60,8 @@ test-log = "0.2.11"
tokio = "1.32"
tokio-test = "0.4"
toml = "0.7"
tree-sitter = "0.20"
tree-sitter-bash = { git = "https://github.com/tree-sitter/tree-sitter-bash" }
tree-sitter-facade = { git = "https://github.com/tweag/tree-sitter-facade" }
tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json.git" }
tree-sitter-nickel = { git = "https://github.com/nickel-lang/tree-sitter-nickel", rev = "b1a4718601ebd29a62bf3a7fd1069a99ccf48093" }
tree-sitter-ocaml = { git = "https://github.com/tree-sitter/tree-sitter-ocaml.git" }
Expand Down
54 changes: 27 additions & 27 deletions flake.lock

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

2 changes: 1 addition & 1 deletion topiary-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ tokio = { workspace = true, features = ["fs", "rt-multi-thread", "sync", "macros
toml = { workspace = true }
topiary = { path = "../topiary" }
topiary-queries = { path = "../topiary-queries" }
tree-sitter-facade = { workspace = true }

tree-sitter = { workspace = true }
tree-sitter-json = { workspace = true }
tree-sitter-rust = { workspace = true }
tree-sitter-toml = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion topiary-cli/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<'cfg> InputFile<'cfg> {
QuerySource::Path(query) => tokio::fs::read_to_string(query).await?,
QuerySource::BuiltIn(contents) => contents.to_owned(),
};
let query = TopiaryQuery::new(&grammar, &contents)?;
let query = TopiaryQuery::new(grammar, &contents)?;

Ok(LanguageDefinition {
query,
Expand Down
2 changes: 1 addition & 1 deletion topiary-cli/src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{error::CLIResult, io::InputFile};
pub struct LanguageDefinition {
pub query: TopiaryQuery,
pub language: Language,
pub grammar: tree_sitter_facade::Language,
pub grammar: ::tree_sitter::Language,
}

/// Thread-safe language definition cache
Expand Down
4 changes: 2 additions & 2 deletions topiary-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async fn run() -> CLIResult<()> {
&mut buf_output,
&lang_def.query,
&lang_def.language,
&lang_def.grammar,
lang_def.grammar,
Operation::Format {
skip_idempotence,
tolerate_parsing_errors,
Expand Down Expand Up @@ -140,7 +140,7 @@ async fn run() -> CLIResult<()> {
&mut buf_output,
&lang_def.query,
&lang_def.language,
&lang_def.grammar,
lang_def.grammar,
Operation::Visualise {
output_format: format.into(),
},
Expand Down
1 change: 0 additions & 1 deletion topiary-playground/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ crate-type = ["cdylib"]
[dependencies]
cfg-if = { workspace = true }
topiary = { path = "../topiary" }
tree-sitter-facade = { workspace = true }
wasm-bindgen = { workspace = true }
wasm-bindgen-futures = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion topiary/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ regex = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
toml = { workspace = true }
tree-sitter-facade = { workspace = true }
tree-sitter = { workspace = true }
unescape = { workspace = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
4 changes: 2 additions & 2 deletions topiary/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn format() {
let configuration = Configuration::parse_default_configuration().unwrap();
let language = configuration.get_language("ocaml").unwrap();
let grammar = language.grammar().await.unwrap();
let query = TopiaryQuery::new(&grammar, &query_content).unwrap();
let query = TopiaryQuery::new(grammar, &query_content).unwrap();

let mut input = input.as_bytes();
let mut output = io::BufWriter::new(Vec::new());
Expand All @@ -21,7 +21,7 @@ async fn format() {
&mut output,
&query,
language,
&grammar,
grammar,
Operation::Format {
skip_idempotence: true,
tolerate_parsing_errors: false,
Expand Down
18 changes: 9 additions & 9 deletions topiary/src/atom_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
ops::Deref,
};

use tree_sitter_facade::Node;
use tree_sitter::Node;

use crate::{Atom, FormatterError, FormatterResult, ScopeCondition, ScopeInformation};

Expand Down Expand Up @@ -177,13 +177,13 @@ impl AtomCollection {
// instead of creating it for both branches, create them once here.
let scope_information_prepend = || -> FormatterResult<ScopeInformation> {
Ok(ScopeInformation {
line_number: node.start_position().row(),
line_number: node.start_position().row,
scope_id: requires_scope_id()?.to_owned(),
})
};
let scope_information_append = || -> FormatterResult<ScopeInformation> {
Ok(ScopeInformation {
line_number: node.end_position().row(),
line_number: node.end_position().row,
scope_id: requires_scope_id()?.to_owned(),
})
};
Expand Down Expand Up @@ -592,7 +592,7 @@ impl AtomCollection {
/// The second pass applies the modifications to the atoms.
fn post_process_scopes(&mut self) {
type ScopeId = String;
type LineIndex = u32;
type LineIndex = usize;
type ScopedNodeId = usize;
// `opened_scopes` maintains stacks of opened scopes,
// the line at which they started,
Expand Down Expand Up @@ -1026,8 +1026,8 @@ fn detect_multi_line_nodes(dfs_nodes: &[Node]) -> HashSet<usize> {
dfs_nodes
.iter()
.filter_map(|node| {
let start_line = node.start_position().row();
let end_line = node.end_position().row();
let start_line = node.start_position().row;
let end_line = node.end_position().row;

if end_line > start_line {
log::debug!("Multi-line node {}: {:?}", node.id(), node,);
Expand Down Expand Up @@ -1055,16 +1055,16 @@ fn detect_multi_line_nodes(dfs_nodes: &[Node]) -> HashSet<usize> {
///
/// A `NodesWithLinebreaks` struct that contains two sets of node IDs: one for the nodes that have a line break
/// before them, and one for the nodes that have a line break after them.
fn detect_line_breaks(dfs_nodes: &[Node], minimum_line_breaks: u32) -> NodesWithLinebreaks {
fn detect_line_breaks(dfs_nodes: &[Node], minimum_line_breaks: usize) -> NodesWithLinebreaks {
// Zip the flattened vector with its own tail => Iterator of pairs of adjacent nodes
// Filter this by the threshold distance between pair components
// Unzip into "nodes with spaces before" and "after" sets, respectively
let (before, after) = dfs_nodes
.iter()
.zip(dfs_nodes[1..].iter())
.filter_map(|(left, right)| {
let last = left.end_position().row();
let next = right.start_position().row();
let last = left.end_position().row;
let next = right.start_position().row;

if next >= last + minimum_line_breaks {
log::debug!(
Expand Down
20 changes: 7 additions & 13 deletions topiary/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ pub enum FormatterError {

/// Tree-sitter could not parse the input without errors.
Parsing {
start_line: u32,
start_column: u32,
end_line: u32,
end_column: u32,
start_line: usize,
start_column: usize,
end_line: usize,
end_column: usize,
},

/// The query contains a pattern that had no match in the input file.
Expand All @@ -33,7 +33,7 @@ pub enum FormatterError {

/// There was an error in the query file. If this happened using our
/// provided query files, it is a bug. Please log an issue.
Query(String, Option<tree_sitter_facade::QueryError>),
Query(String, Option<tree_sitter::QueryError>),

/// Could not detect the input language from the (filename,
/// Option<extension>)
Expand Down Expand Up @@ -204,21 +204,15 @@ impl From<serde_json::Error> for FormatterError {
}
}

impl From<tree_sitter_facade::LanguageError> for FormatterError {
fn from(e: tree_sitter_facade::LanguageError) -> Self {
impl From<tree_sitter::LanguageError> for FormatterError {
fn from(e: tree_sitter::LanguageError) -> Self {
Self::Internal(
"Error while loading language grammar".into(),
Some(Box::new(e)),
)
}
}

impl From<tree_sitter_facade::ParserError> for FormatterError {
fn from(e: tree_sitter_facade::ParserError) -> Self {
Self::Internal("Error while parsing".into(), Some(Box::new(e)))
}
}

impl From<toml::de::Error> for FormatterError {
fn from(e: toml::de::Error) -> Self {
Self::Internal(
Expand Down
Loading
Loading