diff --git a/Cargo.lock b/Cargo.lock index 8e7326b5b4..d2000a385e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8808,6 +8808,7 @@ dependencies = [ "async-dispatcher", "base64 0.13.1", "collections", + "command_palette_hooks", "editor", "env_logger", "futures 0.3.28", diff --git a/crates/repl/Cargo.toml b/crates/repl/Cargo.toml index 0d8af819f0..a1f74d27dc 100644 --- a/crates/repl/Cargo.toml +++ b/crates/repl/Cargo.toml @@ -13,14 +13,15 @@ path = "src/repl.rs" doctest = false [dependencies] -anyhow.workspace = true alacritty_terminal.workspace = true +anyhow.workspace = true async-dispatcher.workspace = true base64.workspace = true collections.workspace = true +command_palette_hooks.workspace = true editor.workspace = true -gpui.workspace = true futures.workspace = true +gpui.workspace = true image.workspace = true language.workspace = true log.workspace = true @@ -32,20 +33,20 @@ serde.workspace = true serde_json.workspace = true settings.workspace = true smol.workspace = true -theme.workspace = true terminal_view.workspace = true +theme.workspace = true ui.workspace = true -uuid.workspace = true util.workspace = true +uuid.workspace = true workspace.workspace = true [dev-dependencies] editor = { workspace = true, features = ["test-support"] } env_logger.workspace = true gpui = { workspace = true, features = ["test-support"] } +http = { workspace = true, features = ["test-support"] } language = { workspace = true, features = ["test-support"] } project = { workspace = true, features = ["test-support"] } settings = { workspace = true, features = ["test-support"] } theme = { workspace = true, features = ["test-support"] } util = { workspace = true, features = ["test-support"] } -http = { workspace = true, features = ["test-support"] } diff --git a/crates/repl/src/repl.rs b/crates/repl/src/repl.rs index 41e90e93f9..9d61d20166 100644 --- a/crates/repl/src/repl.rs +++ b/crates/repl/src/repl.rs @@ -25,6 +25,14 @@ pub use crate::repl_sessions_ui::{ use crate::repl_store::ReplStore; pub use crate::session::Session; +pub fn init(fs: Arc, cx: &mut AppContext) { + set_dispatcher(zed_dispatcher(cx)); + JupyterSettings::register(cx); + ::editor::init_settings(cx); + repl_sessions_ui::init(cx); + ReplStore::init(fs, cx); +} + fn zed_dispatcher(cx: &mut AppContext) -> impl Dispatcher { struct ZedDispatcher { dispatcher: Arc, @@ -48,11 +56,3 @@ fn zed_dispatcher(cx: &mut AppContext) -> impl Dispatcher { dispatcher: cx.background_executor().dispatcher.clone(), } } - -pub fn init(fs: Arc, cx: &mut AppContext) { - set_dispatcher(zed_dispatcher(cx)); - JupyterSettings::register(cx); - ::editor::init_settings(cx); - repl_sessions_ui::init(cx); - ReplStore::init(fs, cx); -} diff --git a/crates/repl/src/repl_store.rs b/crates/repl/src/repl_store.rs index 4d02ef5bf2..62d0e6c97e 100644 --- a/crates/repl/src/repl_store.rs +++ b/crates/repl/src/repl_store.rs @@ -2,6 +2,7 @@ use std::sync::Arc; use anyhow::Result; use collections::HashMap; +use command_palette_hooks::CommandPaletteFilter; use gpui::{ prelude::*, AppContext, EntityId, Global, Model, ModelContext, Subscription, Task, View, }; @@ -25,6 +26,8 @@ pub struct ReplStore { } impl ReplStore { + const NAMESPACE: &'static str = "repl"; + pub(crate) fn init(fs: Arc, cx: &mut AppContext) { let store = cx.new_model(move |cx| Self::new(fs, cx)); @@ -44,13 +47,15 @@ impl ReplStore { this.set_enabled(JupyterSettings::enabled(cx), cx); })]; - Self { + let this = Self { fs, enabled: JupyterSettings::enabled(cx), sessions: HashMap::default(), kernel_specifications: Vec::new(), _subscriptions: subscriptions, - } + }; + this.on_enabled_changed(cx); + this } pub fn fs(&self) -> &Arc { @@ -70,10 +75,28 @@ impl ReplStore { } fn set_enabled(&mut self, enabled: bool, cx: &mut ModelContext) { - if self.enabled != enabled { - self.enabled = enabled; - cx.notify(); + if self.enabled == enabled { + return; } + + self.enabled = enabled; + self.on_enabled_changed(cx); + } + + fn on_enabled_changed(&self, cx: &mut ModelContext) { + if !self.enabled { + CommandPaletteFilter::update_global(cx, |filter, _cx| { + filter.hide_namespace(Self::NAMESPACE); + }); + + return; + } + + CommandPaletteFilter::update_global(cx, |filter, _cx| { + filter.show_namespace(Self::NAMESPACE); + }); + + cx.notify(); } pub fn refresh_kernelspecs(&mut self, cx: &mut ModelContext) -> Task> {