diff --git a/Cargo.lock b/Cargo.lock index 07a6c0a1a2e7a6fa399ee22dee16fec0bdcb7045..29ae3f3cfc068f9ffa3f636ba9dac7e586357f37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -750,21 +750,12 @@ dependencies = [ "arrayvec 0.7.1", "clock", "gpui", - "lazy_static", "log", - "parking_lot", "rand 0.8.3", "rpc", "seahash", - "serde 1.0.125", - "similar", "smallvec", - "smol", "sum_tree", - "theme", - "tree-sitter", - "tree-sitter-rust", - "unindent", ] [[package]] @@ -2822,7 +2813,6 @@ name = "language" version = "0.1.0" dependencies = [ "anyhow", - "arrayvec 0.7.1", "buffer", "clock", "gpui", @@ -2831,12 +2821,9 @@ dependencies = [ "parking_lot", "rand 0.8.3", "rpc", - "seahash", "serde 1.0.125", "similar", - "smallvec", "smol", - "sum_tree", "theme", "tree-sitter", "tree-sitter-rust", diff --git a/crates/buffer/Cargo.toml b/crates/buffer/Cargo.toml index 0cb283aa463ac6f7c90b17e3284d9982f88df97c..e4112c20d5a4c8ecf95d697ecdc2412a92d4b5d6 100644 --- a/crates/buffer/Cargo.toml +++ b/crates/buffer/Cargo.toml @@ -4,30 +4,20 @@ version = "0.1.0" edition = "2018" [features] -test-support = ["rand"] +test-support = ["rand", "seahash"] [dependencies] clock = { path = "../clock" } -gpui = { path = "../gpui" } rpc = { path = "../rpc" } sum_tree = { path = "../sum_tree" } -theme = { path = "../theme" } anyhow = "1.0.38" arrayvec = "0.7.1" -lazy_static = "1.4" log = "0.4" -parking_lot = "0.11.1" rand = { version = "0.8.3", optional = true } -seahash = "4.1" -serde = { version = "1", features = ["derive"] } -similar = "1.3" +seahash = { version = "4.1", optional = true } smallvec = { version = "1.6", features = ["union"] } -smol = "1.2" -tree-sitter = "0.19.5" [dev-dependencies] gpui = { path = "../gpui", features = ["test-support"] } - +seahash = "4.1" rand = "0.8.3" -tree-sitter-rust = "0.19.0" -unindent = "0.1.7" diff --git a/crates/buffer/src/lib.rs b/crates/buffer/src/lib.rs index 3e17808b68a9735bb0e03abb48209928253dd175..715cd12eb4c7ca6988e85dde96d2c3461ff1d332 100644 --- a/crates/buffer/src/lib.rs +++ b/crates/buffer/src/lib.rs @@ -29,7 +29,8 @@ use std::{ sync::Arc, time::{Duration, Instant}, }; -use sum_tree::{Bias, FilterCursor, SumTree}; +pub use sum_tree::Bias; +use sum_tree::{FilterCursor, SumTree}; #[derive(Clone, Default)] struct DeterministicState; diff --git a/crates/buffer/src/point.rs b/crates/buffer/src/point.rs index 77dd9dfe378ba348a7d64cf7e60dd1f8bad190bf..a2da4e4f6ce245a1cf7198f7fa1bae0f1d622fe6 100644 --- a/crates/buffer/src/point.rs +++ b/crates/buffer/src/point.rs @@ -109,21 +109,3 @@ impl Ord for Point { } } } - -impl Into for Point { - fn into(self) -> tree_sitter::Point { - tree_sitter::Point { - row: self.row as usize, - column: self.column as usize, - } - } -} - -impl From for Point { - fn from(point: tree_sitter::Point) -> Self { - Self { - row: point.row as u32, - column: point.column as u32, - } - } -} diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.toml index 1baf3b56112560d6154afb75fe31b27dbbf7c25f..59ed90d460558efcfdb9c478342144ca123e66f8 100644 --- a/crates/editor/Cargo.toml +++ b/crates/editor/Cargo.toml @@ -4,7 +4,11 @@ version = "0.1.0" edition = "2018" [features] -test-support = ["buffer/test-support", "gpui/test-support"] +test-support = [ + "buffer/test-support", + "language/test-support", + "gpui/test-support", +] [dependencies] buffer = { path = "../buffer" } diff --git a/crates/language/Cargo.toml b/crates/language/Cargo.toml index 06ac60c3b24bfbe239768642a2bec6ea04d4c8c7..236c3422289aab7bf5f351f745d3bc6daa6c6185 100644 --- a/crates/language/Cargo.toml +++ b/crates/language/Cargo.toml @@ -11,25 +11,20 @@ buffer = { path = "../buffer" } clock = { path = "../clock" } gpui = { path = "../gpui" } rpc = { path = "../rpc" } -sum_tree = { path = "../sum_tree" } theme = { path = "../theme" } anyhow = "1.0.38" -arrayvec = "0.7.1" lazy_static = "1.4" log = "0.4" parking_lot = "0.11.1" rand = { version = "0.8.3", optional = true } -seahash = "4.1" serde = { version = "1", features = ["derive"] } similar = "1.3" -smallvec = { version = "1.6", features = ["union"] } smol = "1.2" tree-sitter = "0.19.5" [dev-dependencies] buffer = { path = "../buffer", features = ["test-support"] } gpui = { path = "../gpui", features = ["test-support"] } - rand = "0.8.3" tree-sitter-rust = "0.19.0" unindent = "0.1.7" diff --git a/crates/language/src/lib.rs b/crates/language/src/lib.rs index c7b866f003271a007dbd4598c8448add5c4071b1..d05d0811a4e094eff6e75c882c9bd8dfaef366fa 100644 --- a/crates/language/src/lib.rs +++ b/crates/language/src/lib.rs @@ -30,7 +30,6 @@ use std::{ sync::Arc, time::{Duration, Instant, SystemTime, UNIX_EPOCH}, }; -use sum_tree::Bias; use tree_sitter::{InputEdit, Parser, QueryCursor, Tree}; thread_local! { @@ -456,12 +455,12 @@ impl Buffer { start_byte: start_offset, old_end_byte: start_offset + edit.deleted_bytes(), new_end_byte: start_offset + edit.inserted_bytes(), - start_position: start_point.into(), - old_end_position: (start_point + edit.deleted_lines()).into(), + start_position: start_point.to_ts_point(), + old_end_position: (start_point + edit.deleted_lines()).to_ts_point(), new_end_position: self .as_rope() .to_point(start_offset + edit.inserted_bytes()) - .into(), + .to_ts_point(), }); delta += edit.inserted_bytes() as isize - edit.deleted_bytes() as isize; } @@ -1150,8 +1149,8 @@ impl Snapshot { let indent_capture_ix = language.indents_query.capture_index_for_name("indent"); let end_capture_ix = language.indents_query.capture_index_for_name("end"); query_cursor.set_point_range( - Point::new(prev_non_blank_row.unwrap_or(row_range.start), 0).into() - ..Point::new(row_range.end, 0).into(), + Point::new(prev_non_blank_row.unwrap_or(row_range.start), 0).to_ts_point() + ..Point::new(row_range.end, 0).to_ts_point(), ); let mut indentation_ranges = Vec::<(Range, &'static str)>::new(); for mat in query_cursor.matches( @@ -1165,10 +1164,10 @@ impl Snapshot { for capture in mat.captures { if Some(capture.index) == indent_capture_ix { node_kind = capture.node.kind(); - start.get_or_insert(capture.node.start_position().into()); - end.get_or_insert(capture.node.end_position().into()); + start.get_or_insert(Point::from_ts_point(capture.node.start_position())); + end.get_or_insert(Point::from_ts_point(capture.node.end_position())); } else if Some(capture.index) == end_capture_ix { - end = Some(capture.node.start_position().into()); + end = Some(Point::from_ts_point(capture.node.start_position().into())); } } @@ -1439,11 +1438,26 @@ impl Drop for QueryCursorHandle { fn drop(&mut self) { let mut cursor = self.0.take().unwrap(); cursor.set_byte_range(0..usize::MAX); - cursor.set_point_range(Point::zero().into()..Point::MAX.into()); + cursor.set_point_range(Point::zero().to_ts_point()..Point::MAX.to_ts_point()); QUERY_CURSORS.lock().push(cursor) } } +trait ToTreeSitterPoint { + fn to_ts_point(self) -> tree_sitter::Point; + fn from_ts_point(point: tree_sitter::Point) -> Self; +} + +impl ToTreeSitterPoint for Point { + fn to_ts_point(self) -> tree_sitter::Point { + tree_sitter::Point::new(self.row as usize, self.column as usize) + } + + fn from_ts_point(point: tree_sitter::Point) -> Self { + Point::new(point.row as u32, point.column as u32) + } +} + fn contiguous_ranges( values: impl IntoIterator, max_len: usize,