From d3f28166cb0408da9ae86d0342362c261c1b3edf Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 30 Nov 2021 12:26:12 -0700 Subject: [PATCH 1/3] Rename buffer crate to text and name its entrypoint after the crate Co-Authored-By: Max Brunsfeld --- Cargo.lock | 40 +++++++++---------- crates/editor/Cargo.toml | 6 +-- crates/editor/src/display_map.rs | 2 +- crates/editor/src/display_map/block_map.rs | 4 +- crates/editor/src/display_map/fold_map.rs | 26 +++++------- crates/editor/src/display_map/patch.rs | 2 +- crates/editor/src/display_map/tab_map.rs | 4 +- crates/editor/src/display_map/wrap_map.rs | 4 +- crates/editor/src/element.rs | 2 +- crates/editor/src/items.rs | 2 +- crates/editor/src/lib.rs | 4 +- crates/editor/src/movement.rs | 2 +- crates/go_to_line/Cargo.toml | 2 +- crates/go_to_line/src/lib.rs | 2 +- crates/language/Cargo.toml | 6 +-- crates/language/src/lib.rs | 18 ++++----- crates/language/src/proto.rs | 22 +++++----- crates/project/Cargo.toml | 4 +- crates/project/src/fs.rs | 2 +- crates/project/src/worktree.rs | 4 +- crates/{buffer => text}/Cargo.toml | 5 ++- crates/{buffer => text}/src/anchor.rs | 0 .../{buffer => text}/src/operation_queue.rs | 0 crates/{buffer => text}/src/point.rs | 0 crates/{buffer => text}/src/point_utf16.rs | 0 .../{buffer => text}/src/random_char_iter.rs | 0 crates/{buffer => text}/src/rope.rs | 0 crates/{buffer => text}/src/selection.rs | 0 crates/{buffer => text}/src/tests.rs | 0 .../{buffer/src/lib.rs => text/src/text.rs} | 0 crates/zed/Cargo.toml | 6 +-- 31 files changed, 84 insertions(+), 85 deletions(-) rename crates/{buffer => text}/Cargo.toml (92%) rename crates/{buffer => text}/src/anchor.rs (100%) rename crates/{buffer => text}/src/operation_queue.rs (100%) rename crates/{buffer => text}/src/point.rs (100%) rename crates/{buffer => text}/src/point_utf16.rs (100%) rename crates/{buffer => text}/src/random_char_iter.rs (100%) rename crates/{buffer => text}/src/rope.rs (100%) rename crates/{buffer => text}/src/selection.rs (100%) rename crates/{buffer => text}/src/tests.rs (100%) rename crates/{buffer/src/lib.rs => text/src/text.rs} (100%) diff --git a/Cargo.lock b/Cargo.lock index f5a668565b3a89471ac3ce4f40154720acf15133..d84236e1cf710068a7c88c84dae4b4b9f2f1f667 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -739,21 +739,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "buffer" -version = "0.1.0" -dependencies = [ - "anyhow", - "arrayvec 0.7.1", - "clock", - "collections", - "gpui", - "log", - "rand 0.8.3", - "smallvec", - "sum_tree", -] - [[package]] name = "build_const" version = "0.2.2" @@ -1541,7 +1526,6 @@ version = "0.1.0" dependencies = [ "aho-corasick", "anyhow", - "buffer", "clock", "ctor", "env_logger", @@ -1557,6 +1541,7 @@ dependencies = [ "smallvec", "smol", "sum_tree", + "text", "theme", "tree-sitter", "tree-sitter-rust", @@ -2107,10 +2092,10 @@ dependencies = [ name = "go_to_line" version = "0.1.0" dependencies = [ - "buffer", "editor", "gpui", "postage", + "text", "workspace", ] @@ -2589,7 +2574,6 @@ name = "language" version = "0.1.0" dependencies = [ "anyhow", - "buffer", "clock", "futures", "gpui", @@ -2603,6 +2587,7 @@ dependencies = [ "serde", "similar", "smol", + "text", "theme", "tree-sitter", "tree-sitter-rust", @@ -3451,7 +3436,6 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", - "buffer", "client", "clock", "fsevent", @@ -3474,6 +3458,7 @@ dependencies = [ "smol", "sum_tree", "tempdir", + "text", "toml", "unindent", "util", @@ -4856,6 +4841,21 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "text" +version = "0.1.0" +dependencies = [ + "anyhow", + "arrayvec 0.7.1", + "clock", + "collections", + "gpui", + "log", + "rand 0.8.3", + "smallvec", + "sum_tree", +] + [[package]] name = "textwrap" version = "0.11.0" @@ -5676,7 +5676,6 @@ dependencies = [ "async-recursion", "async-trait", "async-tungstenite", - "buffer", "chat_panel", "client", "clock", @@ -5721,6 +5720,7 @@ dependencies = [ "sum_tree", "surf", "tempdir", + "text", "theme", "theme_selector", "thiserror", diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.toml index e2d4b312083020842c077398fb79da8599c128ad..3160be8be6f6ea98fd5f0852f457ee8eb3708781 100644 --- a/crates/editor/Cargo.toml +++ b/crates/editor/Cargo.toml @@ -5,13 +5,13 @@ edition = "2018" [features] test-support = [ - "buffer/test-support", + "text/test-support", "language/test-support", "gpui/test-support", ] [dependencies] -buffer = { path = "../buffer" } +text = { path = "../text" } clock = { path = "../clock" } gpui = { path = "../gpui" } language = { path = "../language" } @@ -31,7 +31,7 @@ smallvec = { version = "1.6", features = ["union"] } smol = "1.2" [dev-dependencies] -buffer = { path = "../buffer", features = ["test-support"] } +text = { path = "../text", features = ["test-support"] } language = { path = "../language", features = ["test-support"] } gpui = { path = "../gpui", features = ["test-support"] } ctor = "0.1" diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index da92260ec812dc27e334216cb513ddbc2035a6fe..bbf03637e1f924bf78b9188a267b6efe1c4fb10a 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -6,7 +6,6 @@ mod wrap_map; pub use block_map::{BlockDisposition, BlockId, BlockProperties, BufferRows, Chunks}; use block_map::{BlockMap, BlockPoint}; -use buffer::Rope; use fold_map::{FoldMap, ToFoldPoint as _}; use gpui::{ fonts::{FontId, HighlightStyle}, @@ -19,6 +18,7 @@ use std::{ }; use sum_tree::Bias; use tab_map::TabMap; +use text::Rope; use theme::{BlockStyle, SyntaxTheme}; use wrap_map::WrapMap; diff --git a/crates/editor/src/display_map/block_map.rs b/crates/editor/src/display_map/block_map.rs index b45274d691ef8c4c3885b59ee0be221bb16331fc..d28d8d7efd591dfa4a784ce7989cd1b83f3a2b7f 100644 --- a/crates/editor/src/display_map/block_map.rs +++ b/crates/editor/src/display_map/block_map.rs @@ -2,7 +2,6 @@ use super::{ wrap_map::{self, Edit as WrapEdit, Snapshot as WrapSnapshot, WrapPoint}, BlockStyle, DisplayRow, }; -use buffer::{rope, Anchor, Bias, Edit, Point, Rope, ToOffset, ToPoint as _}; use gpui::{fonts::HighlightStyle, AppContext, ModelHandle}; use language::{Buffer, Chunk}; use parking_lot::Mutex; @@ -19,6 +18,7 @@ use std::{ vec, }; use sum_tree::SumTree; +use text::{rope, Anchor, Bias, Edit, Point, Rope, ToOffset, ToPoint as _}; use theme::SyntaxTheme; pub struct BlockMap { @@ -1003,11 +1003,11 @@ fn offset_for_row(s: &str, target: u32) -> (u32, usize) { mod tests { use super::*; use crate::display_map::{fold_map::FoldMap, tab_map::TabMap, wrap_map::WrapMap}; - use buffer::RandomCharIter; use gpui::color::Color; use language::Buffer; use rand::prelude::*; use std::env; + use text::RandomCharIter; #[gpui::test] fn test_offset_for_row() { diff --git a/crates/editor/src/display_map/fold_map.rs b/crates/editor/src/display_map/fold_map.rs index 26d3ff3a7d559e7959de5cb105e47daeeb03059e..840497447b17150b65bb8ab66889f91adef023a2 100644 --- a/crates/editor/src/display_map/fold_map.rs +++ b/crates/editor/src/display_map/fold_map.rs @@ -110,7 +110,7 @@ impl<'a> FoldMapWriter<'a> { if range.start != range.end { let fold = Fold(buffer.anchor_after(range.start)..buffer.anchor_before(range.end)); folds.push(fold); - edits.push(buffer::Edit { + edits.push(text::Edit { old: range.clone(), new: range, }); @@ -154,7 +154,7 @@ impl<'a> FoldMapWriter<'a> { let mut folds_cursor = intersecting_folds(&buffer, &self.0.folds, range, true); while let Some(fold) = folds_cursor.item() { let offset_range = fold.0.start.to_offset(&buffer)..fold.0.end.to_offset(&buffer); - edits.push(buffer::Edit { + edits.push(text::Edit { old: offset_range.clone(), new: offset_range, }); @@ -285,11 +285,7 @@ impl FoldMap { } } - fn apply_edits( - &self, - buffer_edits: Vec>, - cx: &AppContext, - ) -> Vec { + fn apply_edits(&self, buffer_edits: Vec>, cx: &AppContext) -> Vec { let buffer = self.buffer.read(cx).snapshot(); let mut buffer_edits_iter = buffer_edits.iter().cloned().peekable(); @@ -713,7 +709,7 @@ impl Snapshot { } fn intersecting_folds<'a, T>( - buffer: &'a buffer::Snapshot, + buffer: &'a text::Snapshot, folds: &'a SumTree, range: Range, inclusive: bool, @@ -738,7 +734,7 @@ where ) } -fn consolidate_buffer_edits(edits: &mut Vec>) { +fn consolidate_buffer_edits(edits: &mut Vec>) { edits.sort_unstable_by(|a, b| { a.old .start @@ -864,9 +860,9 @@ impl Default for FoldSummary { } impl sum_tree::Summary for FoldSummary { - type Context = buffer::Snapshot; + type Context = text::Snapshot; - fn add_summary(&mut self, other: &Self, buffer: &buffer::Snapshot) { + fn add_summary(&mut self, other: &Self, buffer: &text::Snapshot) { if other.min_start.cmp(&self.min_start, buffer).unwrap() == Ordering::Less { self.min_start = other.min_start.clone(); } @@ -890,20 +886,20 @@ impl sum_tree::Summary for FoldSummary { } impl<'a> sum_tree::Dimension<'a, FoldSummary> for Fold { - fn add_summary(&mut self, summary: &'a FoldSummary, _: &buffer::Snapshot) { + fn add_summary(&mut self, summary: &'a FoldSummary, _: &text::Snapshot) { self.0.start = summary.start.clone(); self.0.end = summary.end.clone(); } } impl<'a> sum_tree::SeekTarget<'a, FoldSummary, Fold> for Fold { - fn cmp(&self, other: &Self, buffer: &buffer::Snapshot) -> Ordering { + fn cmp(&self, other: &Self, buffer: &text::Snapshot) -> Ordering { self.0.cmp(&other.0, buffer).unwrap() } } impl<'a> sum_tree::Dimension<'a, FoldSummary> for usize { - fn add_summary(&mut self, summary: &'a FoldSummary, _: &buffer::Snapshot) { + fn add_summary(&mut self, summary: &'a FoldSummary, _: &text::Snapshot) { *self += summary.count; } } @@ -1078,9 +1074,9 @@ impl FoldEdit { mod tests { use super::*; use crate::{test::sample_text, ToPoint}; - use buffer::RandomCharIter; use rand::prelude::*; use std::{env, mem}; + use text::RandomCharIter; use Bias::{Left, Right}; #[gpui::test] diff --git a/crates/editor/src/display_map/patch.rs b/crates/editor/src/display_map/patch.rs index 1fa940d91c88e3da13a172b9ed856ac5ffd84d25..fd6117d3a6b765aa2469a7c3e2d6230f923ace63 100644 --- a/crates/editor/src/display_map/patch.rs +++ b/crates/editor/src/display_map/patch.rs @@ -1,6 +1,6 @@ use std::{cmp, mem}; -type Edit = buffer::Edit; +type Edit = text::Edit; #[derive(Default, Debug, PartialEq, Eq)] pub struct Patch(Vec); diff --git a/crates/editor/src/display_map/tab_map.rs b/crates/editor/src/display_map/tab_map.rs index 675ce9132ebdf90e786a95bc1c7c97615cd78ff3..778e63b6a10a9127c021be4e00904a1e582b1cee 100644 --- a/crates/editor/src/display_map/tab_map.rs +++ b/crates/editor/src/display_map/tab_map.rs @@ -1,9 +1,9 @@ use super::fold_map::{self, FoldEdit, FoldPoint, Snapshot as FoldSnapshot, ToFoldPoint}; -use buffer::Point; use language::{rope, Chunk}; use parking_lot::Mutex; use std::{cmp, mem, ops::Range}; use sum_tree::Bias; +use text::Point; use theme::SyntaxTheme; pub struct TabMap(Mutex); @@ -451,9 +451,9 @@ impl<'a> Iterator for Chunks<'a> { mod tests { use super::*; use crate::display_map::fold_map::FoldMap; - use buffer::{RandomCharIter, Rope}; use language::Buffer; use rand::{prelude::StdRng, Rng}; + use text::{RandomCharIter, Rope}; #[test] fn test_expand_tabs() { diff --git a/crates/editor/src/display_map/wrap_map.rs b/crates/editor/src/display_map/wrap_map.rs index 565c016f3bf00ba9dc5fd36ce0f0d9f40c7e70e8..2349b1974df41a6437bbd7078ab1a86fe87d4184 100644 --- a/crates/editor/src/display_map/wrap_map.rs +++ b/crates/editor/src/display_map/wrap_map.rs @@ -16,7 +16,7 @@ use sum_tree::{Bias, Cursor, SumTree}; use theme::SyntaxTheme; pub use super::tab_map::TextSummary; -pub type Edit = buffer::Edit; +pub type Edit = text::Edit; pub struct WrapMap { snapshot: Snapshot, @@ -991,10 +991,10 @@ mod tests { display_map::{fold_map::FoldMap, tab_map::TabMap}, test::Observer, }; - use buffer::Rope; use language::{Buffer, RandomCharIter}; use rand::prelude::*; use std::{cmp, env}; + use text::Rope; #[gpui::test(iterations = 100)] async fn test_random_wraps(mut cx: gpui::TestAppContext, mut rng: StdRng) { diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index c8e307c0acee665d5fa002e9136d80dc8fc72893..5acc5260140ca7509c99a6bddeda2cd3a2dd3b3b 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -931,7 +931,7 @@ pub struct LayoutState { line_height: f32, em_width: f32, em_advance: f32, - selections: HashMap>>, + selections: HashMap>>, overscroll: Vector2F, text_offset: Vector2F, max_visible_line_width: f32, diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index e5dc4fb224d7af879d02b4c216fd49684aefa52d..f4261c30bbf306446a70a97b5b49ec39c5310165 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -1,6 +1,5 @@ use crate::{Editor, EditorSettings, Event}; use anyhow::Result; -use buffer::{Point, Selection, ToPoint}; use gpui::{ elements::*, fonts::TextStyle, AppContext, Entity, ModelContext, ModelHandle, MutableAppContext, RenderContext, Subscription, Task, View, ViewContext, ViewHandle, @@ -11,6 +10,7 @@ use postage::watch; use project::{ProjectPath, Worktree}; use std::fmt::Write; use std::path::Path; +use text::{Point, Selection, ToPoint}; use workspace::{ settings, EntryOpener, ItemHandle, ItemView, ItemViewHandle, Settings, StatusItemView, WeakItemHandle, diff --git a/crates/editor/src/lib.rs b/crates/editor/src/lib.rs index 2a893a25b0198f0b1759a012ce9c70ef28a6ee59..27a31addb32ccdf034791f707f769b0eca50f5e0 100644 --- a/crates/editor/src/lib.rs +++ b/crates/editor/src/lib.rs @@ -7,7 +7,6 @@ pub mod movement; mod test; use aho_corasick::AhoCorasick; -use buffer::rope::TextDimension; use clock::ReplicaId; use display_map::*; pub use display_map::{DisplayPoint, DisplayRow}; @@ -35,6 +34,7 @@ use std::{ time::Duration, }; use sum_tree::Bias; +use text::rope::TextDimension; use theme::{DiagnosticStyle, EditorStyle, SyntaxTheme}; use util::post_inc; use workspace::{EntryOpener, Workspace}; @@ -3731,7 +3731,7 @@ pub fn diagnostic_style( mod tests { use super::*; use crate::test::sample_text; - use buffer::Point; + use text::Point; use unindent::Unindent; #[gpui::test] diff --git a/crates/editor/src/movement.rs b/crates/editor/src/movement.rs index b3d9610e0244c869ac15d8dcdae8f4349d620803..dbf0f0f7e2bfb18df08a2de57a52100e0609706d 100644 --- a/crates/editor/src/movement.rs +++ b/crates/editor/src/movement.rs @@ -1,7 +1,7 @@ use super::{Bias, DisplayMapSnapshot, DisplayPoint, SelectionGoal, ToDisplayPoint}; use anyhow::Result; -use buffer::ToPoint; use std::{cmp, ops::Range}; +use text::ToPoint; pub fn left(map: &DisplayMapSnapshot, mut point: DisplayPoint) -> Result { if point.column() > 0 { diff --git a/crates/go_to_line/Cargo.toml b/crates/go_to_line/Cargo.toml index c1cf2863dfc665c9e77a7d9d332e017ad5780c33..bebdcf1b40e38db324d7daff7ac03bc79ca374d0 100644 --- a/crates/go_to_line/Cargo.toml +++ b/crates/go_to_line/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2018" [dependencies] -buffer = { path = "../buffer" } +text = { path = "../text" } editor = { path = "../editor" } gpui = { path = "../gpui" } workspace = { path = "../workspace" } diff --git a/crates/go_to_line/src/lib.rs b/crates/go_to_line/src/lib.rs index 4e493b57a07b1aef0d9258a6295bd76edf42bcba..77942b105fd315eddbf737be1d6968360c1b0b53 100644 --- a/crates/go_to_line/src/lib.rs +++ b/crates/go_to_line/src/lib.rs @@ -1,4 +1,4 @@ -use buffer::{Bias, Point, Selection}; +use text::{Bias, Point, Selection}; use editor::{display_map::ToDisplayPoint, Autoscroll, Editor, EditorSettings}; use gpui::{ action, elements::*, geometry::vector::Vector2F, keymap::Binding, Axis, Entity, diff --git a/crates/language/Cargo.toml b/crates/language/Cargo.toml index 39423268e7b9489c12f319c746434a5e7f22bb8f..76659e54288a9537f882c62633d9146a6976d98c 100644 --- a/crates/language/Cargo.toml +++ b/crates/language/Cargo.toml @@ -6,13 +6,13 @@ edition = "2018" [features] test-support = [ "rand", - "buffer/test-support", + "text/test-support", "lsp/test-support", "tree-sitter-rust", ] [dependencies] -buffer = { path = "../buffer" } +text = { path = "../text" } clock = { path = "../clock" } gpui = { path = "../gpui" } lsp = { path = "../lsp" } @@ -33,7 +33,7 @@ tree-sitter = "0.19.5" tree-sitter-rust = { version = "0.19.0", optional = true } [dev-dependencies] -buffer = { path = "../buffer", features = ["test-support"] } +text = { path = "../text", features = ["test-support"] } gpui = { path = "../gpui", features = ["test-support"] } lsp = { path = "../lsp", features = ["test-support"] } rand = "0.8.3" diff --git a/crates/language/src/lib.rs b/crates/language/src/lib.rs index 07602e227f7df1e82cd38e361e0f558bf8c4886e..d70ea71be173dc033731162cf74b0348f3c23fe7 100644 --- a/crates/language/src/lib.rs +++ b/crates/language/src/lib.rs @@ -12,7 +12,6 @@ pub use self::{ }, }; use anyhow::{anyhow, Result}; -pub use buffer::{Buffer as TextBuffer, Operation as _, *}; use clock::ReplicaId; use futures::FutureExt as _; use gpui::{fonts::HighlightStyle, AppContext, Entity, ModelContext, MutableAppContext, Task}; @@ -37,6 +36,7 @@ use std::{ time::{Duration, Instant, SystemTime, UNIX_EPOCH}, vec, }; +pub use text::{Buffer as TextBuffer, Operation as _, *}; use theme::SyntaxTheme; use tree_sitter::{InputEdit, Parser, QueryCursor, Tree}; use util::{post_inc, TryFutureExt as _}; @@ -77,7 +77,7 @@ pub struct Buffer { } pub struct Snapshot { - text: buffer::Snapshot, + text: text::Snapshot, tree: Option, diagnostics: AnchorRangeMultimap, is_parsing: bool, @@ -102,14 +102,14 @@ struct LanguageServerState { #[derive(Clone)] struct LanguageServerSnapshot { - buffer_snapshot: buffer::Snapshot, + buffer_snapshot: text::Snapshot, version: usize, path: Arc, } #[derive(Clone)] pub enum Operation { - Buffer(buffer::Operation), + Buffer(text::Operation), UpdateDiagnostics(AnchorRangeMultimap), } @@ -269,11 +269,11 @@ impl Buffer { cx: &mut ModelContext, ) -> Result { let mut buffer = - buffer::Buffer::new(replica_id, message.id, History::new(message.content.into())); + text::Buffer::new(replica_id, message.id, History::new(message.content.into())); let ops = message .history .into_iter() - .map(|op| buffer::Operation::Edit(proto::deserialize_edit_operation(op))); + .map(|op| text::Operation::Edit(proto::deserialize_edit_operation(op))); buffer.apply_ops(ops)?; for set in message.selections { let set = proto::deserialize_selection_set(set); @@ -1321,7 +1321,7 @@ impl Buffer { } self.end_transaction(None, cx).unwrap(); - self.send_operation(Operation::Buffer(buffer::Operation::Edit(edit)), cx); + self.send_operation(Operation::Buffer(text::Operation::Edit(edit)), cx); } fn did_edit( @@ -1354,7 +1354,7 @@ impl Buffer { cx: &mut ModelContext, ) -> SelectionSetId { let operation = self.text.add_selection_set(selections); - if let buffer::Operation::UpdateSelections { set_id, .. } = &operation { + if let text::Operation::UpdateSelections { set_id, .. } = &operation { let set_id = *set_id; cx.notify(); self.send_operation(Operation::Buffer(operation), cx); @@ -1746,7 +1746,7 @@ impl Clone for Snapshot { } impl Deref for Snapshot { - type Target = buffer::Snapshot; + type Target = text::Snapshot; fn deref(&self) -> &Self::Target { &self.text diff --git a/crates/language/src/proto.rs b/crates/language/src/proto.rs index 23a6e2b656471403ac8f1b6ff3626358b0041a00..c5e25fe751d4ce7a3bc61e2ef02b491dce63264b 100644 --- a/crates/language/src/proto.rs +++ b/crates/language/src/proto.rs @@ -4,20 +4,20 @@ use crate::Diagnostic; use super::Operation; use anyhow::{anyhow, Result}; -use buffer::*; use clock::ReplicaId; use lsp::DiagnosticSeverity; use rpc::proto; +use text::*; pub use proto::Buffer; pub fn serialize_operation(operation: &Operation) -> proto::Operation { proto::Operation { variant: Some(match operation { - Operation::Buffer(buffer::Operation::Edit(edit)) => { + Operation::Buffer(text::Operation::Edit(edit)) => { proto::operation::Variant::Edit(serialize_edit_operation(edit)) } - Operation::Buffer(buffer::Operation::Undo { + Operation::Buffer(text::Operation::Undo { undo, lamport_timestamp, }) => proto::operation::Variant::Undo(proto::operation::Undo { @@ -43,7 +43,7 @@ pub fn serialize_operation(operation: &Operation) -> proto::Operation { .collect(), version: From::from(&undo.version), }), - Operation::Buffer(buffer::Operation::UpdateSelections { + Operation::Buffer(text::Operation::UpdateSelections { set_id, selections, lamport_timestamp, @@ -62,7 +62,7 @@ pub fn serialize_operation(operation: &Operation) -> proto::Operation { }) .collect(), }), - Operation::Buffer(buffer::Operation::RemoveSelections { + Operation::Buffer(text::Operation::RemoveSelections { set_id, lamport_timestamp, }) => proto::operation::Variant::RemoveSelections(proto::operation::RemoveSelections { @@ -70,7 +70,7 @@ pub fn serialize_operation(operation: &Operation) -> proto::Operation { local_timestamp: set_id.value, lamport_timestamp: lamport_timestamp.value, }), - Operation::Buffer(buffer::Operation::SetActiveSelections { + Operation::Buffer(text::Operation::SetActiveSelections { set_id, lamport_timestamp, }) => proto::operation::Variant::SetActiveSelections( @@ -155,9 +155,9 @@ pub fn deserialize_operation(message: proto::Operation) -> Result { .ok_or_else(|| anyhow!("missing operation variant"))? { proto::operation::Variant::Edit(edit) => { - Operation::Buffer(buffer::Operation::Edit(deserialize_edit_operation(edit))) + Operation::Buffer(text::Operation::Edit(deserialize_edit_operation(edit))) } - proto::operation::Variant::Undo(undo) => Operation::Buffer(buffer::Operation::Undo { + proto::operation::Variant::Undo(undo) => Operation::Buffer(text::Operation::Undo { lamport_timestamp: clock::Lamport { replica_id: undo.replica_id as ReplicaId, value: undo.lamport_timestamp, @@ -211,7 +211,7 @@ pub fn deserialize_operation(message: proto::Operation) -> Result { entries, ); - Operation::Buffer(buffer::Operation::UpdateSelections { + Operation::Buffer(text::Operation::UpdateSelections { set_id: clock::Lamport { replica_id: message.replica_id as ReplicaId, value: message.local_timestamp, @@ -224,7 +224,7 @@ pub fn deserialize_operation(message: proto::Operation) -> Result { }) } proto::operation::Variant::RemoveSelections(message) => { - Operation::Buffer(buffer::Operation::RemoveSelections { + Operation::Buffer(text::Operation::RemoveSelections { set_id: clock::Lamport { replica_id: message.replica_id as ReplicaId, value: message.local_timestamp, @@ -236,7 +236,7 @@ pub fn deserialize_operation(message: proto::Operation) -> Result { }) } proto::operation::Variant::SetActiveSelections(message) => { - Operation::Buffer(buffer::Operation::SetActiveSelections { + Operation::Buffer(text::Operation::SetActiveSelections { set_id: message.local_timestamp.map(|value| clock::Lamport { replica_id: message.replica_id as ReplicaId, value, diff --git a/crates/project/Cargo.toml b/crates/project/Cargo.toml index b19516055e0e8fda8f39fa8c9f28ffee78320603..98b73508f64a27258ba7907cdf108e9342d00771 100644 --- a/crates/project/Cargo.toml +++ b/crates/project/Cargo.toml @@ -4,10 +4,10 @@ version = "0.1.0" edition = "2018" [features] -test-support = ["language/test-support", "buffer/test-support"] +test-support = ["language/test-support", "text/test-support"] [dependencies] -buffer = { path = "../buffer" } +text = { path = "../text" } client = { path = "../client" } clock = { path = "../clock" } fsevent = { path = "../fsevent" } diff --git a/crates/project/src/fs.rs b/crates/project/src/fs.rs index 650cb4a8ec9901cb7d7b48868225f12d025a38c9..85c0e45fb002a606907a16bec3af9c6cb5b59d8f 100644 --- a/crates/project/src/fs.rs +++ b/crates/project/src/fs.rs @@ -1,5 +1,4 @@ use anyhow::{anyhow, Result}; -use buffer::Rope; use fsevent::EventStream; use futures::{Stream, StreamExt}; use postage::prelude::Sink as _; @@ -11,6 +10,7 @@ use std::{ pin::Pin, time::{Duration, SystemTime}, }; +use text::Rope; #[async_trait::async_trait] pub trait Fs: Send + Sync { diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index 36df02112c701b520916c08860ac3d01e1b065e7..42ded059a4c674f356e3853820579b3172aa628b 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -3004,7 +3004,6 @@ mod tests { use super::*; use crate::fs::FakeFs; use anyhow::Result; - use buffer::Point; use client::test::{FakeHttpClient, FakeServer}; use fs::RealFs; use language::{tree_sitter_rust, LanguageServerConfig}; @@ -3018,6 +3017,7 @@ mod tests { fmt::Write, time::{SystemTime, UNIX_EPOCH}, }; + use text::Point; use util::test::temp_tree; #[gpui::test] @@ -3559,8 +3559,8 @@ mod tests { #[gpui::test] async fn test_buffer_file_changes_on_disk(mut cx: gpui::TestAppContext) { - use buffer::{Point, Selection, SelectionGoal}; use std::fs; + use text::{Point, Selection, SelectionGoal}; let initial_contents = "aaa\nbbbbb\nc\n"; let dir = temp_tree(json!({ "the-file": initial_contents })); diff --git a/crates/buffer/Cargo.toml b/crates/text/Cargo.toml similarity index 92% rename from crates/buffer/Cargo.toml rename to crates/text/Cargo.toml index b69627eb7339a5992a41a4c132f964d2409de44f..bda69006bec88003ec9804cbe951a3ea4b591198 100644 --- a/crates/buffer/Cargo.toml +++ b/crates/text/Cargo.toml @@ -1,8 +1,11 @@ [package] -name = "buffer" +name = "text" version = "0.1.0" edition = "2021" +[lib] +path = "src/text.rs" + [features] test-support = ["rand"] diff --git a/crates/buffer/src/anchor.rs b/crates/text/src/anchor.rs similarity index 100% rename from crates/buffer/src/anchor.rs rename to crates/text/src/anchor.rs diff --git a/crates/buffer/src/operation_queue.rs b/crates/text/src/operation_queue.rs similarity index 100% rename from crates/buffer/src/operation_queue.rs rename to crates/text/src/operation_queue.rs diff --git a/crates/buffer/src/point.rs b/crates/text/src/point.rs similarity index 100% rename from crates/buffer/src/point.rs rename to crates/text/src/point.rs diff --git a/crates/buffer/src/point_utf16.rs b/crates/text/src/point_utf16.rs similarity index 100% rename from crates/buffer/src/point_utf16.rs rename to crates/text/src/point_utf16.rs diff --git a/crates/buffer/src/random_char_iter.rs b/crates/text/src/random_char_iter.rs similarity index 100% rename from crates/buffer/src/random_char_iter.rs rename to crates/text/src/random_char_iter.rs diff --git a/crates/buffer/src/rope.rs b/crates/text/src/rope.rs similarity index 100% rename from crates/buffer/src/rope.rs rename to crates/text/src/rope.rs diff --git a/crates/buffer/src/selection.rs b/crates/text/src/selection.rs similarity index 100% rename from crates/buffer/src/selection.rs rename to crates/text/src/selection.rs diff --git a/crates/buffer/src/tests.rs b/crates/text/src/tests.rs similarity index 100% rename from crates/buffer/src/tests.rs rename to crates/text/src/tests.rs diff --git a/crates/buffer/src/lib.rs b/crates/text/src/text.rs similarity index 100% rename from crates/buffer/src/lib.rs rename to crates/text/src/text.rs diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 4186f66372c4b2225e9aebcc9bfb00e3db1afd87..485011d5e42183c7a7238af7c089543c7657e4fd 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -15,7 +15,7 @@ path = "src/main.rs" [features] test-support = [ - "buffer/test-support", + "text/test-support", "client/test-support", "editor/test-support", "gpui/test-support", @@ -28,7 +28,7 @@ test-support = [ ] [dependencies] -buffer = { path = "../buffer" } +text = { path = "../text" } chat_panel = { path = "../chat_panel" } client = { path = "../client" } clock = { path = "../clock" } @@ -89,7 +89,7 @@ tree-sitter-rust = "0.19.0" url = "2.2" [dev-dependencies] -buffer = { path = "../buffer", features = ["test-support"] } +text = { path = "../text", features = ["test-support"] } editor = { path = "../editor", features = ["test-support"] } gpui = { path = "../gpui", features = ["test-support"] } language = { path = "../language", features = ["test-support"] } From 748b1ba6022e77146ca4debd53d1ffa54a7766fa Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 30 Nov 2021 12:27:00 -0700 Subject: [PATCH 2/3] Fix warning Co-Authored-By: Max Brunsfeld --- crates/server/src/rpc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/server/src/rpc.rs b/crates/server/src/rpc.rs index 54440bbd56faa2bf46d18c82a5513d3cd74250df..96949d05ff57192341f14995d1fd50fdd875cd4a 100644 --- a/crates/server/src/rpc.rs +++ b/crates/server/src/rpc.rs @@ -2233,7 +2233,7 @@ mod tests { .await; worktree_a - .condition(&cx_a, |worktree, cx| { + .condition(&cx_a, |worktree, _| { worktree.collaborators().contains_key(&client_b.peer_id) }) .await; From 1445ce10b5d97b9f51dca7a5555a617eee78d3d5 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 30 Nov 2021 12:46:39 -0700 Subject: [PATCH 3/3] Name the root file of every crate after the crate to ease navigation Co-Authored-By: Max Brunsfeld --- crates/chat_panel/Cargo.toml | 3 + .../chat_panel/src/{lib.rs => chat_panel.rs} | 0 crates/client/Cargo.toml | 3 + crates/client/src/{lib.rs => client.rs} | 0 crates/clock/Cargo.toml | 3 + crates/clock/src/{lib.rs => clock.rs} | 0 crates/collections/Cargo.toml | 3 + .../src/{lib.rs => collections.rs} | 0 crates/contacts_panel/Cargo.toml | 3 + .../src/{lib.rs => contacts_panel.rs} | 0 crates/editor/Cargo.toml | 3 + crates/editor/src/{lib.rs => editor.rs} | 0 crates/file_finder/Cargo.toml | 3 + .../src/{lib.rs => file_finder.rs} | 0 crates/fsevent/Cargo.toml | 3 + crates/fsevent/src/{lib.rs => fsevent.rs} | 0 crates/fuzzy/Cargo.toml | 3 + crates/fuzzy/src/{lib.rs => fuzzy.rs} | 0 crates/go_to_line/Cargo.toml | 3 + .../go_to_line/src/{lib.rs => go_to_line.rs} | 0 crates/gpui/Cargo.toml | 3 + crates/gpui/src/{lib.rs => gpui.rs} | 0 crates/gpui_macros/Cargo.toml | 1 + .../src/{lib.rs => gpui_macros.rs} | 0 crates/language/Cargo.toml | 3 + crates/language/src/{lib.rs => buffer.rs} | 30 ++++----- crates/language/src/language.rs | 63 +++---------------- crates/language/src/proto.rs | 4 +- crates/language/src/tests.rs | 52 ++++++++++++++- crates/lsp/Cargo.toml | 3 + crates/lsp/src/{lib.rs => lsp.rs} | 0 crates/project/Cargo.toml | 3 + crates/project/src/{lib.rs => project.rs} | 0 crates/project_panel/Cargo.toml | 3 + .../src/{lib.rs => project_panel.rs} | 0 crates/rpc/Cargo.toml | 3 + crates/rpc/src/{lib.rs => rpc.rs} | 0 crates/sum_tree/Cargo.toml | 3 + crates/sum_tree/src/{lib.rs => sum_tree.rs} | 0 crates/theme/Cargo.toml | 3 + crates/theme/src/{lib.rs => theme.rs} | 0 crates/theme_selector/Cargo.toml | 3 + .../src/{lib.rs => theme_selector.rs} | 0 crates/workspace/Cargo.toml | 3 + crates/workspace/src/{lib.rs => workspace.rs} | 0 crates/zed/Cargo.toml | 2 +- crates/zed/src/{lib.rs => zed.rs} | 0 47 files changed, 133 insertions(+), 79 deletions(-) rename crates/chat_panel/src/{lib.rs => chat_panel.rs} (100%) rename crates/client/src/{lib.rs => client.rs} (100%) rename crates/clock/src/{lib.rs => clock.rs} (100%) rename crates/collections/src/{lib.rs => collections.rs} (100%) rename crates/contacts_panel/src/{lib.rs => contacts_panel.rs} (100%) rename crates/editor/src/{lib.rs => editor.rs} (100%) rename crates/file_finder/src/{lib.rs => file_finder.rs} (100%) rename crates/fsevent/src/{lib.rs => fsevent.rs} (100%) rename crates/fuzzy/src/{lib.rs => fuzzy.rs} (100%) rename crates/go_to_line/src/{lib.rs => go_to_line.rs} (100%) rename crates/gpui/src/{lib.rs => gpui.rs} (100%) rename crates/gpui_macros/src/{lib.rs => gpui_macros.rs} (100%) rename crates/language/src/{lib.rs => buffer.rs} (99%) rename crates/lsp/src/{lib.rs => lsp.rs} (100%) rename crates/project/src/{lib.rs => project.rs} (100%) rename crates/project_panel/src/{lib.rs => project_panel.rs} (100%) rename crates/rpc/src/{lib.rs => rpc.rs} (100%) rename crates/sum_tree/src/{lib.rs => sum_tree.rs} (100%) rename crates/theme/src/{lib.rs => theme.rs} (100%) rename crates/theme_selector/src/{lib.rs => theme_selector.rs} (100%) rename crates/workspace/src/{lib.rs => workspace.rs} (100%) rename crates/zed/src/{lib.rs => zed.rs} (100%) diff --git a/crates/chat_panel/Cargo.toml b/crates/chat_panel/Cargo.toml index 9b7d3664d7f9a34846faf63108c3228b87b4f559..7f34579c8778969eee5d429d8e165c3437af7082 100644 --- a/crates/chat_panel/Cargo.toml +++ b/crates/chat_panel/Cargo.toml @@ -3,6 +3,9 @@ name = "chat_panel" version = "0.1.0" edition = "2018" +[lib] +path = "src/chat_panel.rs" + [dependencies] client = { path = "../client" } editor = { path = "../editor" } diff --git a/crates/chat_panel/src/lib.rs b/crates/chat_panel/src/chat_panel.rs similarity index 100% rename from crates/chat_panel/src/lib.rs rename to crates/chat_panel/src/chat_panel.rs diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index 455e6a00fe023d5cc821628edc1882a063e607d1..bec27f84c55cb08f69210348b7006f424938b276 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -3,6 +3,9 @@ name = "client" version = "0.1.0" edition = "2018" +[lib] +path = "src/client.rs" + [features] test-support = ["rpc/test-support"] diff --git a/crates/client/src/lib.rs b/crates/client/src/client.rs similarity index 100% rename from crates/client/src/lib.rs rename to crates/client/src/client.rs diff --git a/crates/clock/Cargo.toml b/crates/clock/Cargo.toml index 3e5d84935d9ea36ac57e1395c4dab8cf27c64ae7..7ddb64872a7a83456f88fdbd76c10fcc1a24a77e 100644 --- a/crates/clock/Cargo.toml +++ b/crates/clock/Cargo.toml @@ -3,6 +3,9 @@ name = "clock" version = "0.1.0" edition = "2018" +[lib] +path = "src/clock.rs" + [dependencies] smallvec = { version = "1.6", features = ["union"] } rpc = { path = "../rpc" } diff --git a/crates/clock/src/lib.rs b/crates/clock/src/clock.rs similarity index 100% rename from crates/clock/src/lib.rs rename to crates/clock/src/clock.rs diff --git a/crates/collections/Cargo.toml b/crates/collections/Cargo.toml index b0b1a8bd3867eac134638896795aa9dc75e8f573..8ca3ccd4e960a5cb6c6e6ad6538e67265670347b 100644 --- a/crates/collections/Cargo.toml +++ b/crates/collections/Cargo.toml @@ -3,6 +3,9 @@ name = "collections" version = "0.1.0" edition = "2021" +[lib] +path = "src/collections.rs" + [features] test-support = ["seahash"] diff --git a/crates/collections/src/lib.rs b/crates/collections/src/collections.rs similarity index 100% rename from crates/collections/src/lib.rs rename to crates/collections/src/collections.rs diff --git a/crates/contacts_panel/Cargo.toml b/crates/contacts_panel/Cargo.toml index ffeb8e6a3d426b40e2b969504984c4ffbac24a8d..38d0c026093a56e3521b379a513eacd5c6df3be1 100644 --- a/crates/contacts_panel/Cargo.toml +++ b/crates/contacts_panel/Cargo.toml @@ -3,6 +3,9 @@ name = "contacts_panel" version = "0.1.0" edition = "2018" +[lib] +path = "src/contacts_panel.rs" + [dependencies] client = { path = "../client" } gpui = { path = "../gpui" } diff --git a/crates/contacts_panel/src/lib.rs b/crates/contacts_panel/src/contacts_panel.rs similarity index 100% rename from crates/contacts_panel/src/lib.rs rename to crates/contacts_panel/src/contacts_panel.rs diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.toml index 3160be8be6f6ea98fd5f0852f457ee8eb3708781..ed0d1b74133945a798bacb1f3b32c64361fec240 100644 --- a/crates/editor/Cargo.toml +++ b/crates/editor/Cargo.toml @@ -3,6 +3,9 @@ name = "editor" version = "0.1.0" edition = "2018" +[lib] +path = "src/editor.rs" + [features] test-support = [ "text/test-support", diff --git a/crates/editor/src/lib.rs b/crates/editor/src/editor.rs similarity index 100% rename from crates/editor/src/lib.rs rename to crates/editor/src/editor.rs diff --git a/crates/file_finder/Cargo.toml b/crates/file_finder/Cargo.toml index 81995e2e7aedec1ac758a21857587c3854deb067..521eefb6fc2c80d2d4df30c095e862af35e5a43b 100644 --- a/crates/file_finder/Cargo.toml +++ b/crates/file_finder/Cargo.toml @@ -3,6 +3,9 @@ name = "file_finder" version = "0.1.0" edition = "2018" +[lib] +path = "src/file_finder.rs" + [dependencies] editor = { path = "../editor" } fuzzy = { path = "../fuzzy" } diff --git a/crates/file_finder/src/lib.rs b/crates/file_finder/src/file_finder.rs similarity index 100% rename from crates/file_finder/src/lib.rs rename to crates/file_finder/src/file_finder.rs diff --git a/crates/fsevent/Cargo.toml b/crates/fsevent/Cargo.toml index 03b565cb9f06b2d39c245bbc2549e254069f35a7..f4d1b1d04aebb2257da4727654578045744f5414 100644 --- a/crates/fsevent/Cargo.toml +++ b/crates/fsevent/Cargo.toml @@ -4,6 +4,9 @@ version = "2.0.2" license = "MIT" edition = "2018" +[lib] +path = "src/fsevent.rs" + [dependencies] bitflags = "1" fsevent-sys = "3.0.2" diff --git a/crates/fsevent/src/lib.rs b/crates/fsevent/src/fsevent.rs similarity index 100% rename from crates/fsevent/src/lib.rs rename to crates/fsevent/src/fsevent.rs diff --git a/crates/fuzzy/Cargo.toml b/crates/fuzzy/Cargo.toml index 0a60e0973d6e326d29f2f1b3a3af217e4926b363..dec485ffe3411740c205fd28ab50062a0fadbfab 100644 --- a/crates/fuzzy/Cargo.toml +++ b/crates/fuzzy/Cargo.toml @@ -3,6 +3,9 @@ name = "fuzzy" version = "0.1.0" edition = "2018" +[lib] +path = "src/fuzzy.rs" + [dependencies] gpui = { path = "../gpui" } util = { path = "../util" } diff --git a/crates/fuzzy/src/lib.rs b/crates/fuzzy/src/fuzzy.rs similarity index 100% rename from crates/fuzzy/src/lib.rs rename to crates/fuzzy/src/fuzzy.rs diff --git a/crates/go_to_line/Cargo.toml b/crates/go_to_line/Cargo.toml index bebdcf1b40e38db324d7daff7ac03bc79ca374d0..f98b1b2ee031616cae39e6894e94204a68943ff0 100644 --- a/crates/go_to_line/Cargo.toml +++ b/crates/go_to_line/Cargo.toml @@ -3,6 +3,9 @@ name = "go_to_line" version = "0.1.0" edition = "2018" +[lib] +path = "src/go_to_line.rs" + [dependencies] text = { path = "../text" } editor = { path = "../editor" } diff --git a/crates/go_to_line/src/lib.rs b/crates/go_to_line/src/go_to_line.rs similarity index 100% rename from crates/go_to_line/src/lib.rs rename to crates/go_to_line/src/go_to_line.rs diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.toml index dc1edc654741f69e26d7a69e4957c5dcdd6a874f..7c237d48e59c8d8605436814b4961f4febe8373f 100644 --- a/crates/gpui/Cargo.toml +++ b/crates/gpui/Cargo.toml @@ -4,6 +4,9 @@ edition = "2018" name = "gpui" version = "0.1.0" +[lib] +path = "src/gpui.rs" + [features] test-support = ["env_logger"] diff --git a/crates/gpui/src/lib.rs b/crates/gpui/src/gpui.rs similarity index 100% rename from crates/gpui/src/lib.rs rename to crates/gpui/src/gpui.rs diff --git a/crates/gpui_macros/Cargo.toml b/crates/gpui_macros/Cargo.toml index a5d7373463b8d50b5e205cba1e96eb738602a5a8..8f1c9faba5c5379d4844cd8995553252714227b7 100644 --- a/crates/gpui_macros/Cargo.toml +++ b/crates/gpui_macros/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2018" [lib] +path = "src/gpui_macros.rs" proc-macro = true [dependencies] diff --git a/crates/gpui_macros/src/lib.rs b/crates/gpui_macros/src/gpui_macros.rs similarity index 100% rename from crates/gpui_macros/src/lib.rs rename to crates/gpui_macros/src/gpui_macros.rs diff --git a/crates/language/Cargo.toml b/crates/language/Cargo.toml index 76659e54288a9537f882c62633d9146a6976d98c..ad0f84b4dcd620309202ce14f0ab60b6cfb020b6 100644 --- a/crates/language/Cargo.toml +++ b/crates/language/Cargo.toml @@ -3,6 +3,9 @@ name = "language" version = "0.1.0" edition = "2018" +[lib] +path = "src/language.rs" + [features] test-support = [ "rand", diff --git a/crates/language/src/lib.rs b/crates/language/src/buffer.rs similarity index 99% rename from crates/language/src/lib.rs rename to crates/language/src/buffer.rs index d70ea71be173dc033731162cf74b0348f3c23fe7..d71662d0d9b416cba31281904489b201a877f669 100644 --- a/crates/language/src/lib.rs +++ b/crates/language/src/buffer.rs @@ -1,15 +1,7 @@ -mod highlight_map; -mod language; -pub mod proto; -#[cfg(test)] -mod tests; - -pub use self::{ +pub use crate::{ highlight_map::{HighlightId, HighlightMap}, - language::{ - BracketPair, Grammar, Language, LanguageConfig, LanguageRegistry, LanguageServerConfig, - PLAIN_TEXT, - }, + proto, BracketPair, Grammar, Language, LanguageConfig, LanguageRegistry, LanguageServerConfig, + PLAIN_TEXT, }; use anyhow::{anyhow, Result}; use clock::ReplicaId; @@ -73,7 +65,7 @@ pub struct Buffer { diagnostics_update_count: usize, language_server: Option, #[cfg(test)] - operations: Vec, + pub(crate) operations: Vec, } pub struct Snapshot { @@ -217,7 +209,7 @@ pub struct Chunk<'a> { pub diagnostic: Option, } -struct Diff { +pub(crate) struct Diff { base_version: clock::Global, new_text: Arc, changes: Vec<(ChangeTag, usize)>, @@ -573,7 +565,7 @@ impl Buffer { self.parse_count } - fn syntax_tree(&self) -> Option { + pub(crate) fn syntax_tree(&self) -> Option { if let Some(syntax_tree) = self.syntax_tree.lock().as_mut() { self.interpolate_tree(syntax_tree); Some(syntax_tree.tree.clone()) @@ -1094,7 +1086,7 @@ impl Buffer { .min_by_key(|(open_range, close_range)| close_range.end - open_range.start) } - fn diff(&self, new_text: Arc, cx: &AppContext) -> Task { + pub(crate) fn diff(&self, new_text: Arc, cx: &AppContext) -> Task { // TODO: it would be nice to not allocate here. let old_text = self.text(); let base_version = self.version(); @@ -1111,7 +1103,7 @@ impl Buffer { }) } - fn apply_diff(&mut self, diff: Diff, cx: &mut ModelContext) -> bool { + pub(crate) fn apply_diff(&mut self, diff: Diff, cx: &mut ModelContext) -> bool { if self.version == diff.base_version { self.start_transaction(None).unwrap(); let mut offset = 0; @@ -1153,7 +1145,7 @@ impl Buffer { self.start_transaction_at(selection_set_ids, Instant::now()) } - fn start_transaction_at( + pub(crate) fn start_transaction_at( &mut self, selection_set_ids: impl IntoIterator, now: Instant, @@ -1169,7 +1161,7 @@ impl Buffer { self.end_transaction_at(selection_set_ids, Instant::now(), cx) } - fn end_transaction_at( + pub(crate) fn end_transaction_at( &mut self, selection_set_ids: impl IntoIterator, now: Instant, @@ -1995,7 +1987,7 @@ fn diagnostic_ranges<'a>( )) } -fn contiguous_ranges( +pub fn contiguous_ranges( values: impl IntoIterator, max_len: usize, ) -> impl Iterator> { diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index f8201b179b44682a2e8bcc7412c4a8a6897985a3..77d01c7ecf85b4b231d4cc03856a13e0c6f48dc8 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -1,6 +1,14 @@ -use crate::HighlightMap; +mod buffer; +mod highlight_map; +pub mod proto; +#[cfg(test)] +mod tests; + use anyhow::{anyhow, Result}; +pub use buffer::Operation; +pub use buffer::*; use gpui::{executor::Background, AppContext}; +use highlight_map::HighlightMap; use lazy_static::lazy_static; use lsp::LanguageServer; use parking_lot::Mutex; @@ -223,56 +231,3 @@ impl LanguageServerConfig { ) } } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_select_language() { - let registry = LanguageRegistry { - languages: vec![ - Arc::new(Language::new( - LanguageConfig { - name: "Rust".to_string(), - path_suffixes: vec!["rs".to_string()], - ..Default::default() - }, - Some(tree_sitter_rust::language()), - )), - Arc::new(Language::new( - LanguageConfig { - name: "Make".to_string(), - path_suffixes: vec!["Makefile".to_string(), "mk".to_string()], - ..Default::default() - }, - Some(tree_sitter_rust::language()), - )), - ], - }; - - // matching file extension - assert_eq!( - registry.select_language("zed/lib.rs").map(|l| l.name()), - Some("Rust") - ); - assert_eq!( - registry.select_language("zed/lib.mk").map(|l| l.name()), - Some("Make") - ); - - // matching filename - assert_eq!( - registry.select_language("zed/Makefile").map(|l| l.name()), - Some("Make") - ); - - // matching suffix that is not the full file extension or filename - assert_eq!(registry.select_language("zed/cars").map(|l| l.name()), None); - assert_eq!( - registry.select_language("zed/a.cars").map(|l| l.name()), - None - ); - assert_eq!(registry.select_language("zed/sumk").map(|l| l.name()), None); - } -} diff --git a/crates/language/src/proto.rs b/crates/language/src/proto.rs index c5e25fe751d4ce7a3bc61e2ef02b491dce63264b..3e3455c6714c16acb512cbf32681a37348dd2e2f 100644 --- a/crates/language/src/proto.rs +++ b/crates/language/src/proto.rs @@ -1,8 +1,6 @@ use std::sync::Arc; -use crate::Diagnostic; - -use super::Operation; +use crate::{Diagnostic, Operation}; use anyhow::{anyhow, Result}; use clock::ReplicaId; use lsp::DiagnosticSeverity; diff --git a/crates/language/src/tests.rs b/crates/language/src/tests.rs index 4a05f108cfdd882858bea3b03aa888edf750cf1c..800bd6629030d370c55fd70c7f1f2bc1a6a07138 100644 --- a/crates/language/src/tests.rs +++ b/crates/language/src/tests.rs @@ -1,8 +1,56 @@ use super::*; -use gpui::{ModelHandle, MutableAppContext}; -use std::{iter::FromIterator, rc::Rc}; +use gpui::{ModelHandle, MutableAppContext, Task}; +use std::{any::Any, cell::RefCell, ffi::OsString, iter::FromIterator, ops::Range, path::PathBuf, rc::Rc, time::{Duration, Instant, SystemTime}}; use unindent::Unindent as _; +#[test] +fn test_select_language() { + let registry = LanguageRegistry { + languages: vec![ + Arc::new(Language::new( + LanguageConfig { + name: "Rust".to_string(), + path_suffixes: vec!["rs".to_string()], + ..Default::default() + }, + Some(tree_sitter_rust::language()), + )), + Arc::new(Language::new( + LanguageConfig { + name: "Make".to_string(), + path_suffixes: vec!["Makefile".to_string(), "mk".to_string()], + ..Default::default() + }, + Some(tree_sitter_rust::language()), + )), + ], + }; + + // matching file extension + assert_eq!( + registry.select_language("zed/lib.rs").map(|l| l.name()), + Some("Rust") + ); + assert_eq!( + registry.select_language("zed/lib.mk").map(|l| l.name()), + Some("Make") + ); + + // matching filename + assert_eq!( + registry.select_language("zed/Makefile").map(|l| l.name()), + Some("Make") + ); + + // matching suffix that is not the full file extension or filename + assert_eq!(registry.select_language("zed/cars").map(|l| l.name()), None); + assert_eq!( + registry.select_language("zed/a.cars").map(|l| l.name()), + None + ); + assert_eq!(registry.select_language("zed/sumk").map(|l| l.name()), None); +} + #[gpui::test] fn test_edit_events(cx: &mut gpui::MutableAppContext) { let mut now = Instant::now(); diff --git a/crates/lsp/Cargo.toml b/crates/lsp/Cargo.toml index 263eed76fb9d515e0194835a94bcf9c79c08d909..76387182f38509712114da25275dff298e11e3e2 100644 --- a/crates/lsp/Cargo.toml +++ b/crates/lsp/Cargo.toml @@ -3,6 +3,9 @@ name = "lsp" version = "0.1.0" edition = "2018" +[lib] +path = "src/lsp.rs" + [features] test-support = ["async-pipe"] diff --git a/crates/lsp/src/lib.rs b/crates/lsp/src/lsp.rs similarity index 100% rename from crates/lsp/src/lib.rs rename to crates/lsp/src/lsp.rs diff --git a/crates/project/Cargo.toml b/crates/project/Cargo.toml index 98b73508f64a27258ba7907cdf108e9342d00771..fce637c8e7a2b6c3ea4b68def5072ff1dd5b66ca 100644 --- a/crates/project/Cargo.toml +++ b/crates/project/Cargo.toml @@ -3,6 +3,9 @@ name = "project" version = "0.1.0" edition = "2018" +[lib] +path = "src/project.rs" + [features] test-support = ["language/test-support", "text/test-support"] diff --git a/crates/project/src/lib.rs b/crates/project/src/project.rs similarity index 100% rename from crates/project/src/lib.rs rename to crates/project/src/project.rs diff --git a/crates/project_panel/Cargo.toml b/crates/project_panel/Cargo.toml index 180ea078e1c090d664f1cda6fb95e5ba249b526d..eb9d76eaa98dc40ae17861e14243fba79cf5cd86 100644 --- a/crates/project_panel/Cargo.toml +++ b/crates/project_panel/Cargo.toml @@ -3,6 +3,9 @@ name = "project_panel" version = "0.1.0" edition = "2018" +[lib] +path = "src/project_panel.rs" + [dependencies] gpui = { path = "../gpui" } project = { path = "../project" } diff --git a/crates/project_panel/src/lib.rs b/crates/project_panel/src/project_panel.rs similarity index 100% rename from crates/project_panel/src/lib.rs rename to crates/project_panel/src/project_panel.rs diff --git a/crates/rpc/Cargo.toml b/crates/rpc/Cargo.toml index f8c1e7d39c4f840d718dae7e5bfb823ba4fd57a3..55f8a50d7ff18bba1138d626ed41a7ca737e1e49 100644 --- a/crates/rpc/Cargo.toml +++ b/crates/rpc/Cargo.toml @@ -4,6 +4,9 @@ edition = "2018" name = "rpc" version = "0.1.0" +[lib] +path = "src/rpc.rs" + [features] test-support = [] diff --git a/crates/rpc/src/lib.rs b/crates/rpc/src/rpc.rs similarity index 100% rename from crates/rpc/src/lib.rs rename to crates/rpc/src/rpc.rs diff --git a/crates/sum_tree/Cargo.toml b/crates/sum_tree/Cargo.toml index 6a9893502e3f31a015a1afaff31944a2a32c4ea8..20d652620474913d734882ba7564a594c2f84dcd 100644 --- a/crates/sum_tree/Cargo.toml +++ b/crates/sum_tree/Cargo.toml @@ -3,6 +3,9 @@ name = "sum_tree" version = "0.1.0" edition = "2018" +[lib] +path = "src/sum_tree.rs" + [dependencies] arrayvec = "0.7.1" diff --git a/crates/sum_tree/src/lib.rs b/crates/sum_tree/src/sum_tree.rs similarity index 100% rename from crates/sum_tree/src/lib.rs rename to crates/sum_tree/src/sum_tree.rs diff --git a/crates/theme/Cargo.toml b/crates/theme/Cargo.toml index a02683ec075bb29a0fb2ee76c8f1cfb60e7b1ab7..1e5d38f44d3f83365a2458adf7cac791f93b2bf0 100644 --- a/crates/theme/Cargo.toml +++ b/crates/theme/Cargo.toml @@ -3,6 +3,9 @@ name = "theme" version = "0.1.0" edition = "2018" +[lib] +path = "src/theme.rs" + [dependencies] gpui = { path = "../gpui" } anyhow = "1.0.38" diff --git a/crates/theme/src/lib.rs b/crates/theme/src/theme.rs similarity index 100% rename from crates/theme/src/lib.rs rename to crates/theme/src/theme.rs diff --git a/crates/theme_selector/Cargo.toml b/crates/theme_selector/Cargo.toml index e4ef6d768d6b41f28d3b8f133fe4f3545d154f64..e1b253595fac3f455fa905d0b42f3ee001e802e3 100644 --- a/crates/theme_selector/Cargo.toml +++ b/crates/theme_selector/Cargo.toml @@ -3,6 +3,9 @@ name = "theme_selector" version = "0.1.0" edition = "2018" +[lib] +path = "src/theme_selector.rs" + [dependencies] editor = { path = "../editor" } fuzzy = { path = "../fuzzy" } diff --git a/crates/theme_selector/src/lib.rs b/crates/theme_selector/src/theme_selector.rs similarity index 100% rename from crates/theme_selector/src/lib.rs rename to crates/theme_selector/src/theme_selector.rs diff --git a/crates/workspace/Cargo.toml b/crates/workspace/Cargo.toml index b20ab232f90a4b917756fda4b083f6f2592dbf03..29e25148e5480c85dfc8a120d0d71eb40ead34b3 100644 --- a/crates/workspace/Cargo.toml +++ b/crates/workspace/Cargo.toml @@ -3,6 +3,9 @@ name = "workspace" version = "0.1.0" edition = "2018" +[lib] +path = "src/workspace.rs" + [features] test-support = [ "client/test-support", diff --git a/crates/workspace/src/lib.rs b/crates/workspace/src/workspace.rs similarity index 100% rename from crates/workspace/src/lib.rs rename to crates/workspace/src/workspace.rs diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 485011d5e42183c7a7238af7c089543c7657e4fd..9657691fc94947dfa65d580f80a699291b2db2bb 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -7,7 +7,7 @@ version = "0.9.0" [lib] name = "zed" -path = "src/lib.rs" +path = "src/zed.rs" [[bin]] name = "Zed" diff --git a/crates/zed/src/lib.rs b/crates/zed/src/zed.rs similarity index 100% rename from crates/zed/src/lib.rs rename to crates/zed/src/zed.rs