Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
repl: Filter commands out of command palette when REPL is disabled (#15016)
Marshall Bowersc262c81e5208
diff --git a/Cargo.lock b/Cargo.lockindex 8e7326b5b41..d2000a385ee 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.tomlindex 0d8af819f00..a1f74d27dce 100644--- a/crates/repl/Cargo.toml+++ b/crates/repl/Cargo.toml@@ -13,14 +13,15 @@ path = "src/repl.rs"doctest = false[dependencies]-anyhow.workspace = truealacritty_terminal.workspace = true+anyhow.workspace = trueasync-dispatcher.workspace = truebase64.workspace = truecollections.workspace = true+command_palette_hooks.workspace = trueeditor.workspace = true-gpui.workspace = truefutures.workspace = true+gpui.workspace = trueimage.workspace = truelanguage.workspace = truelog.workspace = true@@ -32,20 +33,20 @@ serde.workspace = trueserde_json.workspace = truesettings.workspace = truesmol.workspace = true-theme.workspace = trueterminal_view.workspace = true+theme.workspace = trueui.workspace = true-uuid.workspace = trueutil.workspace = true+uuid.workspace = trueworkspace.workspace = true[dev-dependencies]editor = { workspace = true, features = ["test-support"] }env_logger.workspace = truegpui = { 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.rsindex 41e90e93f94..9d61d201662 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<dyn Fs>, 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<dyn PlatformDispatcher>,@@ -48,11 +56,3 @@ fn zed_dispatcher(cx: &mut AppContext) -> impl Dispatcher {dispatcher: cx.background_executor().dispatcher.clone(),}}--pub fn init(fs: Arc<dyn Fs>, 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.rsindex 4d02ef5bf23..62d0e6c97e0 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<dyn Fs>, 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<dyn Fs> {@@ -70,10 +75,28 @@ impl ReplStore {}fn set_enabled(&mut self, enabled: bool, cx: &mut ModelContext<Self>) {- 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<Self>) {+ 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<Self>) -> Task<Result<()>> {