Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Lazily initialize kernelspecs (#51026)

John Tur8d083a639cf4
diff --git a/crates/repl/src/components/kernel_options.rs b/crates/repl/src/components/kernel_options.rs
index 45e55f0d5f8..b6d4f39c0cc 100644
--- a/crates/repl/src/components/kernel_options.rs
+++ b/crates/repl/src/components/kernel_options.rs
@@ -448,7 +448,9 @@ where
TT: Fn(&mut Window, &mut App) -> AnyView + 'static,
{
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
- let store = ReplStore::global(cx).read(cx);
+ let store = ReplStore::global(cx);
+ store.update(cx, |store, cx| store.ensure_kernelspecs(cx));
+ let store = store.read(cx);
let all_entries = build_grouped_entries(store, self.worktree_id);
let selected_kernelspec = store.active_kernelspec(self.worktree_id, None, cx);
diff --git a/crates/repl/src/repl_editor.rs b/crates/repl/src/repl_editor.rs
index 56b79e20ffc..cf1493000ed 100644
--- a/crates/repl/src/repl_editor.rs
+++ b/crates/repl/src/repl_editor.rs
@@ -191,6 +191,7 @@ pub fn run(
if !store.read(cx).is_enabled() {
return Ok(());
}
+ store.update(cx, |store, cx| store.ensure_kernelspecs(cx));
let editor = editor.upgrade().context("editor was dropped")?;
let selected_range = editor
diff --git a/crates/repl/src/repl_sessions_ui.rs b/crates/repl/src/repl_sessions_ui.rs
index 1dc2107adde..9781382fc85 100644
--- a/crates/repl/src/repl_sessions_ui.rs
+++ b/crates/repl/src/repl_sessions_ui.rs
@@ -204,7 +204,8 @@ impl Render for ReplSessionsPage {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let store = ReplStore::global(cx);
- let (kernel_specifications, sessions) = store.update(cx, |store, _cx| {
+ let (kernel_specifications, sessions) = store.update(cx, |store, cx| {
+ store.ensure_kernelspecs(cx);
(
store
.pure_jupyter_kernel_specifications()
diff --git a/crates/repl/src/repl_store.rs b/crates/repl/src/repl_store.rs
index ff0a2793617..800bab03014 100644
--- a/crates/repl/src/repl_store.rs
+++ b/crates/repl/src/repl_store.rs
@@ -27,6 +27,7 @@ pub struct ReplStore {
enabled: bool,
sessions: HashMap<EntityId, Entity<Session>>,
kernel_specifications: Vec<KernelSpecification>,
+ kernelspecs_initialized: bool,
selected_kernel_for_worktree: HashMap<WorktreeId, KernelSpecification>,
kernel_specifications_for_worktree: HashMap<WorktreeId, Vec<KernelSpecification>>,
active_python_toolchain_for_worktree: HashMap<WorktreeId, SharedString>,
@@ -39,12 +40,6 @@ impl ReplStore {
pub(crate) fn init(fs: Arc<dyn Fs>, cx: &mut App) {
let store = cx.new(move |cx| Self::new(fs, cx));
-
- #[cfg(not(feature = "test-support"))]
- store
- .update(cx, |store, cx| store.refresh_kernelspecs(cx))
- .detach_and_log_err(cx);
-
cx.set_global(GlobalReplStore(store))
}
@@ -65,6 +60,7 @@ impl ReplStore {
enabled: JupyterSettings::enabled(cx),
sessions: HashMap::default(),
kernel_specifications: Vec::new(),
+ kernelspecs_initialized: false,
_subscriptions: subscriptions,
kernel_specifications_for_worktree: HashMap::default(),
selected_kernel_for_worktree: HashMap::default(),
@@ -216,10 +212,17 @@ impl ReplStore {
}
}
+ pub fn ensure_kernelspecs(&mut self, cx: &mut Context<Self>) {
+ if self.kernelspecs_initialized {
+ return;
+ }
+ self.kernelspecs_initialized = true;
+ self.refresh_kernelspecs(cx).detach_and_log_err(cx);
+ }
+
pub fn refresh_kernelspecs(&mut self, cx: &mut Context<Self>) -> Task<Result<()>> {
let local_kernel_specifications = local_kernel_specifications(self.fs.clone());
let wsl_kernel_specifications = wsl_kernel_specifications(cx.background_executor().clone());
-
let remote_kernel_specifications = self.get_remote_kernel_specifications(cx);
let all_specs = cx.background_spawn(async move {