Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Parameterize `theme2::init` to allow loading just the base theme (#3345)
Marshall Bowersb559bfd80f23
diff --git a/crates/collab2/src/tests/test_server.rs b/crates/collab2/src/tests/test_server.rsindex de6f3e92a1b..090a32d4cae 100644--- a/crates/collab2/src/tests/test_server.rs+++ b/crates/collab2/src/tests/test_server.rs@@ -224,7 +224,7 @@ impl TestServer {});cx.update(|cx| {- theme::init(cx);+ theme::init(theme::LoadThemes::JustBase, cx);Project::init(&client, cx);client::init(&client, cx);language::init(cx);diff --git a/crates/command_palette2/src/command_palette.rs b/crates/command_palette2/src/command_palette.rsindex 8138f025d3d..31eb608ef56 100644--- a/crates/command_palette2/src/command_palette.rs+++ b/crates/command_palette2/src/command_palette.rs@@ -456,7 +456,7 @@ mod tests {fn init_test(cx: &mut TestAppContext) -> Arc<AppState> {cx.update(|cx| {let app_state = AppState::test(cx);- theme::init(cx);+ theme::init(theme::LoadThemes::JustBase, cx);language::init(cx);editor::init(cx);workspace::init(app_state.clone(), cx);diff --git a/crates/editor2/src/display_map/inlay_map.rs b/crates/editor2/src/display_map/inlay_map.rsindex a6bc6343f4f..84fad96a480 100644--- a/crates/editor2/src/display_map/inlay_map.rs+++ b/crates/editor2/src/display_map/inlay_map.rs@@ -1891,6 +1891,6 @@ mod tests {fn init_test(cx: &mut AppContext) {let store = SettingsStore::test(cx);cx.set_global(store);- theme::init(cx);+ theme::init(theme::LoadThemes::JustBase, cx);}}diff --git a/crates/editor2/src/editor_tests.rs b/crates/editor2/src/editor_tests.rsindex 63bc6179c20..bd69e7acdf5 100644--- a/crates/editor2/src/editor_tests.rs+++ b/crates/editor2/src/editor_tests.rs@@ -8277,7 +8277,7 @@ pub(crate) fn init_test(cx: &mut TestAppContext, f: fn(&mut AllLanguageSettingsCcx.update(|cx| {let store = SettingsStore::test(cx);cx.set_global(store);- theme::init(cx);+ theme::init(theme::LoadThemes::JustBase, cx);client::init_settings(cx);language::init(cx);Project::init_settings(cx);diff --git a/crates/editor2/src/inlay_hint_cache.rs b/crates/editor2/src/inlay_hint_cache.rsindex af9febf376b..eba49ccbf74 100644--- a/crates/editor2/src/inlay_hint_cache.rs+++ b/crates/editor2/src/inlay_hint_cache.rs@@ -3179,7 +3179,7 @@ all hints should be invalidated and requeried for all of its visible excerpts"cx.update(|cx| {let settings_store = SettingsStore::test(cx);cx.set_global(settings_store);- theme::init(cx);+ theme::init(theme::LoadThemes::JustBase, cx);client::init_settings(cx);language::init(cx);Project::init_settings(cx);diff --git a/crates/file_finder2/src/file_finder.rs b/crates/file_finder2/src/file_finder.rsindex 236bc152441..b2850761a97 100644--- a/crates/file_finder2/src/file_finder.rs+++ b/crates/file_finder2/src/file_finder.rs@@ -1763,7 +1763,7 @@ mod tests {fn init_test(cx: &mut TestAppContext) -> Arc<AppState> {cx.update(|cx| {let state = AppState::test(cx);- theme::init(cx);+ theme::init(theme::LoadThemes::JustBase, cx);language::init(cx);super::init(cx);editor::init(cx);diff --git a/crates/project_panel2/src/project_panel.rs b/crates/project_panel2/src/project_panel.rsindex f33633afb9b..87edabab521 100644--- a/crates/project_panel2/src/project_panel.rs+++ b/crates/project_panel2/src/project_panel.rs@@ -2785,7 +2785,7 @@ mod tests {let settings_store = SettingsStore::test(cx);cx.set_global(settings_store);init_settings(cx);- theme::init(cx);+ theme::init(theme::LoadThemes::JustBase, cx);language::init(cx);editor::init_settings(cx);crate::init((), cx);@@ -2798,7 +2798,7 @@ mod tests {fn init_test_with_editor(cx: &mut TestAppContext) {cx.update(|cx| {let app_state = AppState::test(cx);- theme::init(cx);+ theme::init(theme::LoadThemes::JustBase, cx);init_settings(cx);language::init(cx);editor::init(cx);diff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rsindex c4c1d75eac2..20adc44c1aa 100644--- a/crates/storybook2/src/storybook2.rs+++ b/crates/storybook2/src/storybook2.rs@@ -60,7 +60,7 @@ fn main() {.unwrap();cx.set_global(store);- theme2::init(cx);+ theme2::init(theme2::LoadThemes::All, cx);let selector =story_selector.unwrap_or(StorySelector::Component(ComponentStory::Workspace));diff --git a/crates/terminal_view2/src/terminal_view.rs b/crates/terminal_view2/src/terminal_view.rsindex 14391ca2b2f..ad337163845 100644--- a/crates/terminal_view2/src/terminal_view.rs+++ b/crates/terminal_view2/src/terminal_view.rs@@ -1126,7 +1126,7 @@ mod tests {pub async fn init_test(cx: &mut TestAppContext) -> (Model<Project>, View<Workspace>) {let params = cx.update(AppState::test);cx.update(|cx| {- theme::init(cx);+ theme::init(theme::LoadThemes::JustBase, cx);Project::init_settings(cx);language::init(cx);});diff --git a/crates/theme2/src/registry.rs b/crates/theme2/src/registry.rsindex 19af0ede51c..919dd1b1099 100644--- a/crates/theme2/src/registry.rs+++ b/crates/theme2/src/registry.rs@@ -100,6 +100,11 @@ impl ThemeRegistry {.ok_or_else(|| anyhow!("theme not found: {}", name)).cloned()}++ pub fn load_user_themes(&mut self) {+ #[cfg(not(feature = "importing-themes"))]+ self.insert_user_theme_familes(crate::all_user_themes());+ }}impl Default for ThemeRegistry {@@ -110,9 +115,6 @@ impl Default for ThemeRegistry {this.insert_theme_families([one_family()]);- #[cfg(not(feature = "importing-themes"))]- this.insert_user_theme_familes(crate::all_user_themes());-this}}diff --git a/crates/theme2/src/settings.rs b/crates/theme2/src/settings.rsindex 5e3329ffa14..071199d3d6a 100644--- a/crates/theme2/src/settings.rs+++ b/crates/theme2/src/settings.rs@@ -117,7 +117,7 @@ impl settings::Settings for ThemeSettings {user_values: &[&Self::FileContent],cx: &mut AppContext,) -> Result<Self> {- let themes = cx.default_global::<Arc<ThemeRegistry>>();+ let themes = cx.default_global::<ThemeRegistry>();let mut this = Self {ui_font_size: defaults.ui_font_size.unwrap_or(16.).into(),diff --git a/crates/theme2/src/theme2.rs b/crates/theme2/src/theme2.rsindex b6790b5a6ff..05e41ba368b 100644--- a/crates/theme2/src/theme2.rs+++ b/crates/theme2/src/theme2.rs@@ -31,8 +31,25 @@ pub enum Appearance {Dark,}-pub fn init(cx: &mut AppContext) {+#[derive(Debug, PartialEq, Eq, Clone, Copy)]+pub enum LoadThemes {+ /// Only load the base theme.+ ///+ /// No user themes will be loaded.+ JustBase,++ /// Load all of the built-in themes.+ All,+}++pub fn init(themes_to_load: LoadThemes, cx: &mut AppContext) {cx.set_global(ThemeRegistry::default());++ match themes_to_load {+ LoadThemes::JustBase => (),+ LoadThemes::All => cx.global_mut::<ThemeRegistry>().load_user_themes(),+ }+ThemeSettings::register(cx);}diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rsindex f28675661de..a146ad1822b 100644--- a/crates/workspace2/src/workspace2.rs+++ b/crates/workspace2/src/workspace2.rs@@ -355,7 +355,7 @@ impl AppState {let user_store = cx.build_model(|cx| UserStore::new(client.clone(), http_client, cx));let workspace_store = cx.build_model(|cx| WorkspaceStore::new(client.clone(), cx));- theme2::init(cx);+ theme2::init(theme2::LoadThemes::JustBase, cx);client2::init(&client, cx);crate::init_settings(cx);diff --git a/crates/zed2/src/main.rs b/crates/zed2/src/main.rsindex ef65d00fc38..700660a9b7e 100644--- a/crates/zed2/src/main.rs+++ b/crates/zed2/src/main.rs@@ -140,7 +140,7 @@ fn main() {cx.set_global(client.clone());- theme::init(cx);+ theme::init(theme::LoadThemes::All, cx);project::Project::init(&client, cx);client::init(&client, cx);command_palette::init(cx);