diff --git a/Cargo.lock b/Cargo.lock index 2e1c1d2dd6..8b0e92ebb1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5259,6 +5259,21 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "theme" +version = "0.1.0" +dependencies = [ + "anyhow", + "editor", + "gpui", + "indexmap", + "parking_lot", + "serde 1.0.125", + "serde_json 1.0.64", + "serde_path_to_error", + "toml 0.5.8", +] + [[package]] name = "thiserror" version = "1.0.29" @@ -6097,6 +6112,7 @@ dependencies = [ "sum_tree", "surf", "tempdir", + "theme", "thiserror", "time 0.3.2", "tiny_http", diff --git a/crates/theme/Cargo.toml b/crates/theme/Cargo.toml new file mode 100644 index 0000000000..3d0d22f605 --- /dev/null +++ b/crates/theme/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "theme" +version = "0.1.0" +edition = "2018" + +[dependencies] +editor = { path = "../editor" } +gpui = { path = "../gpui" } +anyhow = "1.0.38" +indexmap = "1.6.2" +parking_lot = "0.11.1" +serde = { version = "1", features = ["derive"] } +serde_json = { version = "1.0.64", features = ["preserve_order"] } +serde_path_to_error = "0.1.4" +toml = "0.5" diff --git a/crates/zed/src/theme.rs b/crates/theme/src/lib.rs similarity index 100% rename from crates/zed/src/theme.rs rename to crates/theme/src/lib.rs diff --git a/crates/zed/src/theme/resolution.rs b/crates/theme/src/resolution.rs similarity index 100% rename from crates/zed/src/theme/resolution.rs rename to crates/theme/src/resolution.rs diff --git a/crates/zed/src/theme/theme_registry.rs b/crates/theme/src/theme_registry.rs similarity index 93% rename from crates/zed/src/theme/theme_registry.rs rename to crates/theme/src/theme_registry.rs index c5cf8f2fcb..c3910dc4d2 100644 --- a/crates/zed/src/theme/theme_registry.rs +++ b/crates/theme/src/theme_registry.rs @@ -1,12 +1,10 @@ -use super::resolution::resolve_references; +use crate::{resolution::resolve_references, Theme}; use anyhow::{Context, Result}; use gpui::{fonts, AssetSource, FontCache}; use parking_lot::Mutex; use serde_json::{Map, Value}; use std::{collections::HashMap, sync::Arc}; -use super::Theme; - pub struct ThemeRegistry { assets: Box, themes: Mutex>>, @@ -122,24 +120,9 @@ fn deep_merge_json(base: &mut Map, extension: Map) #[cfg(test)] mod tests { use super::*; - use crate::{test::test_app_state, theme::DEFAULT_THEME_NAME}; use anyhow::anyhow; use gpui::MutableAppContext; - #[gpui::test] - fn test_bundled_themes(cx: &mut MutableAppContext) { - let app_state = test_app_state(cx); - let mut has_default_theme = false; - for theme_name in app_state.themes.list() { - let theme = app_state.themes.get(&theme_name).unwrap(); - if theme.name == DEFAULT_THEME_NAME { - has_default_theme = true; - } - assert_eq!(theme.name, theme_name); - } - assert!(has_default_theme); - } - #[gpui::test] fn test_theme_extension(cx: &mut MutableAppContext) { let assets = TestAssets(&[ diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index b024560a0c..1315176340 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -34,8 +34,8 @@ gpui = { path = "../gpui" } project = { path = "../project" } rpc = { path = "../rpc" } sum_tree = { path = "../sum_tree" } +theme = { path = "../theme" } util = { path = "../util" } - anyhow = "1.0.38" async-recursion = "0.3" async-trait = "0.1" @@ -83,7 +83,6 @@ project = { path = "../project", features = ["test-support"] } rpc = { path = "../rpc", features = ["test-support"] } client = { path = "../client", features = ["test-support"] } util = { path = "../util", features = ["test-support"] } - cargo-bundle = "0.5.0" env_logger = "0.8" serde_json = { version = "1.0.64", features = ["preserve_order"] } diff --git a/crates/zed/src/chat_panel.rs b/crates/zed/src/chat_panel.rs index e81946ed6a..34afbf053b 100644 --- a/crates/zed/src/chat_panel.rs +++ b/crates/zed/src/chat_panel.rs @@ -1,4 +1,4 @@ -use crate::{theme, Settings}; +use crate::Settings; use client::{ channel::{Channel, ChannelEvent, ChannelList, ChannelMessage}, Client, diff --git a/crates/zed/src/lib.rs b/crates/zed/src/lib.rs index 05343713c9..c41ec01c12 100644 --- a/crates/zed/src/lib.rs +++ b/crates/zed/src/lib.rs @@ -8,7 +8,6 @@ pub mod project_panel; pub mod settings; #[cfg(any(test, feature = "test-support"))] pub mod test; -pub mod theme; pub mod theme_selector; pub mod workspace; @@ -31,6 +30,7 @@ pub use project::{self, fs}; use project_panel::ProjectPanel; pub use settings::Settings; use std::{path::PathBuf, sync::Arc}; +use theme::ThemeRegistry; use util::TryFutureExt; use crate::workspace::Workspace; @@ -48,7 +48,7 @@ pub struct AppState { pub settings_tx: Arc>>, pub settings: watch::Receiver, pub languages: Arc, - pub themes: Arc, + pub themes: Arc, pub client: Arc, pub user_store: ModelHandle, pub fs: Arc, @@ -198,6 +198,7 @@ mod tests { use super::*; use crate::{test::test_app_state, workspace::ItemView}; use serde_json::json; + use theme::DEFAULT_THEME_NAME; use util::test::temp_tree; #[gpui::test] @@ -299,4 +300,18 @@ mod tests { assert!(!editor.is_dirty(cx)); }); } + + #[gpui::test] + fn test_bundled_themes(cx: &mut MutableAppContext) { + let app_state = test_app_state(cx); + let mut has_default_theme = false; + for theme_name in app_state.themes.list() { + let theme = app_state.themes.get(&theme_name).unwrap(); + if theme.name == DEFAULT_THEME_NAME { + has_default_theme = true; + } + assert_eq!(theme.name, theme_name); + } + assert!(has_default_theme); + } } diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 9a1f93fc89..8356c516f6 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -7,6 +7,7 @@ use log::LevelFilter; use parking_lot::Mutex; use simplelog::SimpleLogger; use std::{fs, path::PathBuf, sync::Arc}; +use theme::ThemeRegistry; use zed::{ self, assets::Assets, @@ -30,7 +31,7 @@ fn main() { .collect::>(); app.platform().fonts().add_fonts(&embedded_fonts).unwrap(); - let themes = settings::ThemeRegistry::new(Assets, app.font_cache()); + let themes = ThemeRegistry::new(Assets, app.font_cache()); let (settings_tx, settings) = settings::channel("Inconsolata", &app.font_cache(), &themes).unwrap(); let languages = Arc::new(language::build_language_registry()); diff --git a/crates/zed/src/people_panel.rs b/crates/zed/src/people_panel.rs index 9ea408d5b7..3360e58c5f 100644 --- a/crates/zed/src/people_panel.rs +++ b/crates/zed/src/people_panel.rs @@ -1,4 +1,4 @@ -use crate::{theme::Theme, workspace::Workspace, Settings}; +use crate::{workspace::Workspace, Settings}; use client::{Collaborator, UserStore}; use gpui::{ action, @@ -9,6 +9,7 @@ use gpui::{ Subscription, View, ViewContext, }; use postage::watch; +use theme::Theme; action!(JoinWorktree, u64); action!(LeaveWorktree, u64); diff --git a/crates/zed/src/project_panel.rs b/crates/zed/src/project_panel.rs index cbeab41ae5..09b75e2dec 100644 --- a/crates/zed/src/project_panel.rs +++ b/crates/zed/src/project_panel.rs @@ -1,6 +1,5 @@ use crate::{ project::{self, Project, ProjectEntry, ProjectPath}, - theme, workspace::Workspace, Settings, }; diff --git a/crates/zed/src/settings.rs b/crates/zed/src/settings.rs index 52c0f7f61e..c6060119ef 100644 --- a/crates/zed/src/settings.rs +++ b/crates/zed/src/settings.rs @@ -1,9 +1,8 @@ -use crate::theme::{self, DEFAULT_THEME_NAME}; use anyhow::Result; use gpui::font_cache::{FamilyId, FontCache}; use postage::watch; use std::sync::Arc; -pub use theme::{Theme, ThemeRegistry}; +use theme::{Theme, ThemeRegistry, DEFAULT_THEME_NAME}; #[derive(Clone)] pub struct Settings { diff --git a/crates/zed/src/test.rs b/crates/zed/src/test.rs index ac50a7af5e..c2a276e337 100644 --- a/crates/zed/src/test.rs +++ b/crates/zed/src/test.rs @@ -1,10 +1,4 @@ -use crate::{ - assets::Assets, - language, - settings::Settings, - theme::{Theme, ThemeRegistry, DEFAULT_THEME_NAME}, - AppState, -}; +use crate::{assets::Assets, language, settings::Settings, AppState}; use buffer::LanguageRegistry; use client::{http::ServerResponse, test::FakeHttpClient, ChannelList, Client, UserStore}; use gpui::{AssetSource, MutableAppContext}; @@ -12,6 +6,7 @@ use parking_lot::Mutex; use postage::watch; use project::fs::FakeFs; use std::sync::Arc; +use theme::{Theme, ThemeRegistry, DEFAULT_THEME_NAME}; #[cfg(test)] #[ctor::ctor] diff --git a/crates/zed/src/theme_selector.rs b/crates/zed/src/theme_selector.rs index f10e4c6821..963e35d0d2 100644 --- a/crates/zed/src/theme_selector.rs +++ b/crates/zed/src/theme_selector.rs @@ -1,4 +1,4 @@ -use crate::{settings::ThemeRegistry, workspace::Workspace, AppState, Settings}; +use crate::{workspace::Workspace, AppState, Settings}; use editor::{Editor, EditorSettings}; use fuzzy::{match_strings, StringMatch, StringMatchCandidate}; use gpui::{ @@ -11,6 +11,7 @@ use gpui::{ use parking_lot::Mutex; use postage::watch; use std::{cmp, sync::Arc}; +use theme::ThemeRegistry; pub struct ThemeSelector { settings_tx: Arc>>, diff --git a/crates/zed/src/workspace/pane_group.rs b/crates/zed/src/workspace/pane_group.rs index ce7a9c69d9..f61fd6f1af 100644 --- a/crates/zed/src/workspace/pane_group.rs +++ b/crates/zed/src/workspace/pane_group.rs @@ -1,6 +1,6 @@ -use crate::theme::Theme; use anyhow::{anyhow, Result}; use gpui::{elements::*, Axis}; +use theme::Theme; #[derive(Clone, Debug, Eq, PartialEq)] pub struct PaneGroup { diff --git a/crates/zed/src/workspace/sidebar.rs b/crates/zed/src/workspace/sidebar.rs index 377e5a16f5..ea3b3cb920 100644 --- a/crates/zed/src/workspace/sidebar.rs +++ b/crates/zed/src/workspace/sidebar.rs @@ -1,5 +1,5 @@ use super::Workspace; -use crate::{theme, Settings}; +use crate::Settings; use gpui::{ action, elements::*, platform::CursorStyle, AnyViewHandle, MutableAppContext, RenderContext, };