repl: Filter commands out of command palette when REPL is disabled (#15016)

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
This commit is contained in:
Marshall Bowers 2024-07-23 11:49:56 -04:00 committed by GitHub
parent a5cb66f0e1
commit c262c81e52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 18 deletions

1
Cargo.lock generated
View file

@ -8808,6 +8808,7 @@ dependencies = [
"async-dispatcher", "async-dispatcher",
"base64 0.13.1", "base64 0.13.1",
"collections", "collections",
"command_palette_hooks",
"editor", "editor",
"env_logger", "env_logger",
"futures 0.3.28", "futures 0.3.28",

View file

@ -13,14 +13,15 @@ path = "src/repl.rs"
doctest = false doctest = false
[dependencies] [dependencies]
anyhow.workspace = true
alacritty_terminal.workspace = true alacritty_terminal.workspace = true
anyhow.workspace = true
async-dispatcher.workspace = true async-dispatcher.workspace = true
base64.workspace = true base64.workspace = true
collections.workspace = true collections.workspace = true
command_palette_hooks.workspace = true
editor.workspace = true editor.workspace = true
gpui.workspace = true
futures.workspace = true futures.workspace = true
gpui.workspace = true
image.workspace = true image.workspace = true
language.workspace = true language.workspace = true
log.workspace = true log.workspace = true
@ -32,20 +33,20 @@ serde.workspace = true
serde_json.workspace = true serde_json.workspace = true
settings.workspace = true settings.workspace = true
smol.workspace = true smol.workspace = true
theme.workspace = true
terminal_view.workspace = true terminal_view.workspace = true
theme.workspace = true
ui.workspace = true ui.workspace = true
uuid.workspace = true
util.workspace = true util.workspace = true
uuid.workspace = true
workspace.workspace = true workspace.workspace = true
[dev-dependencies] [dev-dependencies]
editor = { workspace = true, features = ["test-support"] } editor = { workspace = true, features = ["test-support"] }
env_logger.workspace = true env_logger.workspace = true
gpui = { workspace = true, features = ["test-support"] } gpui = { workspace = true, features = ["test-support"] }
http = { workspace = true, features = ["test-support"] }
language = { workspace = true, features = ["test-support"] } language = { workspace = true, features = ["test-support"] }
project = { workspace = true, features = ["test-support"] } project = { workspace = true, features = ["test-support"] }
settings = { workspace = true, features = ["test-support"] } settings = { workspace = true, features = ["test-support"] }
theme = { workspace = true, features = ["test-support"] } theme = { workspace = true, features = ["test-support"] }
util = { workspace = true, features = ["test-support"] } util = { workspace = true, features = ["test-support"] }
http = { workspace = true, features = ["test-support"] }

View file

@ -25,6 +25,14 @@ pub use crate::repl_sessions_ui::{
use crate::repl_store::ReplStore; use crate::repl_store::ReplStore;
pub use crate::session::Session; 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 { fn zed_dispatcher(cx: &mut AppContext) -> impl Dispatcher {
struct ZedDispatcher { struct ZedDispatcher {
dispatcher: Arc<dyn PlatformDispatcher>, dispatcher: Arc<dyn PlatformDispatcher>,
@ -48,11 +56,3 @@ fn zed_dispatcher(cx: &mut AppContext) -> impl Dispatcher {
dispatcher: cx.background_executor().dispatcher.clone(), 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);
}

View file

@ -2,6 +2,7 @@ use std::sync::Arc;
use anyhow::Result; use anyhow::Result;
use collections::HashMap; use collections::HashMap;
use command_palette_hooks::CommandPaletteFilter;
use gpui::{ use gpui::{
prelude::*, AppContext, EntityId, Global, Model, ModelContext, Subscription, Task, View, prelude::*, AppContext, EntityId, Global, Model, ModelContext, Subscription, Task, View,
}; };
@ -25,6 +26,8 @@ pub struct ReplStore {
} }
impl ReplStore { impl ReplStore {
const NAMESPACE: &'static str = "repl";
pub(crate) fn init(fs: Arc<dyn Fs>, cx: &mut AppContext) { pub(crate) fn init(fs: Arc<dyn Fs>, cx: &mut AppContext) {
let store = cx.new_model(move |cx| Self::new(fs, cx)); let store = cx.new_model(move |cx| Self::new(fs, cx));
@ -44,13 +47,15 @@ impl ReplStore {
this.set_enabled(JupyterSettings::enabled(cx), cx); this.set_enabled(JupyterSettings::enabled(cx), cx);
})]; })];
Self { let this = Self {
fs, fs,
enabled: JupyterSettings::enabled(cx), enabled: JupyterSettings::enabled(cx),
sessions: HashMap::default(), sessions: HashMap::default(),
kernel_specifications: Vec::new(), kernel_specifications: Vec::new(),
_subscriptions: subscriptions, _subscriptions: subscriptions,
} };
this.on_enabled_changed(cx);
this
} }
pub fn fs(&self) -> &Arc<dyn Fs> { pub fn fs(&self) -> &Arc<dyn Fs> {
@ -70,10 +75,28 @@ impl ReplStore {
} }
fn set_enabled(&mut self, enabled: bool, cx: &mut ModelContext<Self>) { fn set_enabled(&mut self, enabled: bool, cx: &mut ModelContext<Self>) {
if self.enabled != enabled { if self.enabled == enabled {
self.enabled = enabled; return;
cx.notify();
} }
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<()>> { pub fn refresh_kernelspecs(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {