diff --git a/crates/chat_panel/Cargo.toml b/crates/chat_panel/Cargo.toml index 9b7d3664d7..7f34579c87 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 455e6a00fe..bec27f84c5 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 3e5d84935d..7ddb64872a 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 b0b1a8bd38..8ca3ccd4e9 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 ffeb8e6a3d..38d0c02609 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 3160be8be6..ed0d1b7413 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 81995e2e7a..521eefb6fc 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 03b565cb9f..f4d1b1d04a 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 0a60e0973d..dec485ffe3 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 bebdcf1b40..f98b1b2ee0 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 dc1edc6547..7c237d48e5 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 a5d7373463..8f1c9faba5 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 76659e5428..ad0f84b4dc 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 d70ea71be1..d71662d0d9 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 f8201b179b..77d01c7ecf 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 c5e25fe751..3e3455c671 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 4a05f108cf..800bd66290 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 263eed76fb..76387182f3 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 98b73508f6..fce637c8e7 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 180ea078e1..eb9d76eaa9 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 f8c1e7d39c..55f8a50d7f 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 6a9893502e..20d6526204 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 a02683ec07..1e5d38f44d 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 e4ef6d768d..e1b253595f 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 b20ab232f9..29e25148e5 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 485011d5e4..9657691fc9 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