Optimize REPL kernel spec refresh (#21844)

Kyle Kelley created

Python kernelspec refresh now only performed on (known) python files. 

Release Notes:

- N/A

Change summary

crates/repl/src/repl_sessions_ui.rs | 30 ++++++++++++++++++------------
crates/repl/src/repl_store.rs       | 21 ++++++++++++++++-----
2 files changed, 34 insertions(+), 17 deletions(-)

Detailed changes

crates/repl/src/repl_sessions_ui.rs 🔗

@@ -73,21 +73,27 @@ pub fn init(cx: &mut AppContext) {
                 return;
             }
 
-            let project_path = editor
-                .buffer()
-                .read(cx)
-                .as_singleton()
-                .and_then(|buffer| buffer.read(cx).project_path(cx));
+            let buffer = editor.buffer().read(cx).as_singleton();
+
+            let language = buffer
+                .as_ref()
+                .and_then(|buffer| buffer.read(cx).language());
+
+            let project_path = buffer.and_then(|buffer| buffer.read(cx).project_path(cx));
 
             let editor_handle = cx.view().downgrade();
 
-            if let (Some(project_path), Some(project)) = (project_path, project) {
-                let store = ReplStore::global(cx);
-                store.update(cx, |store, cx| {
-                    store
-                        .refresh_python_kernelspecs(project_path.worktree_id, &project, cx)
-                        .detach_and_log_err(cx);
-                });
+            if let Some(language) = language {
+                if language.name() == "Python".into() {
+                    if let (Some(project_path), Some(project)) = (project_path, project) {
+                        let store = ReplStore::global(cx);
+                        store.update(cx, |store, cx| {
+                            store
+                                .refresh_python_kernelspecs(project_path.worktree_id, &project, cx)
+                                .detach_and_log_err(cx);
+                        });
+                    }
+                }
             }
 
             editor

crates/repl/src/repl_store.rs 🔗

@@ -173,7 +173,7 @@ impl ReplStore {
 
         let remote_kernel_specifications = self.get_remote_kernel_specifications(cx);
 
-        cx.spawn(|this, mut cx| async move {
+        let all_specs = cx.background_executor().spawn(async move {
             let mut all_specs = local_kernel_specifications
                 .await?
                 .into_iter()
@@ -186,10 +186,21 @@ impl ReplStore {
                 }
             }
 
-            this.update(&mut cx, |this, cx| {
-                this.kernel_specifications = all_specs;
-                cx.notify();
-            })
+            anyhow::Ok(all_specs)
+        });
+
+        cx.spawn(|this, mut cx| async move {
+            let all_specs = all_specs.await;
+
+            if let Ok(specs) = all_specs {
+                this.update(&mut cx, |this, cx| {
+                    this.kernel_specifications = specs;
+                    cx.notify();
+                })
+                .ok();
+            }
+
+            anyhow::Ok(())
         })
     }