Cargo.lock 🔗
@@ -8808,6 +8808,7 @@ dependencies = [
"async-dispatcher",
"base64 0.13.1",
"collections",
+ "command_palette_hooks",
"editor",
"env_logger",
"futures 0.3.28",
Marshall Bowers created
This PR makes it so the `repl: ` commands don't appear in the command
palette when the REPL feature is disabled.
Release Notes:
- N/A
Cargo.lock | 1 +
crates/repl/Cargo.toml | 11 ++++++-----
crates/repl/src/repl.rs | 16 ++++++++--------
crates/repl/src/repl_store.rs | 33 ++++++++++++++++++++++++++++-----
4 files changed, 43 insertions(+), 18 deletions(-)
@@ -8808,6 +8808,7 @@ dependencies = [
"async-dispatcher",
"base64 0.13.1",
"collections",
+ "command_palette_hooks",
"editor",
"env_logger",
"futures 0.3.28",
@@ -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"] }
@@ -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);
-}
@@ -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<()>> {