Optimize REPL kernel spec refresh (#21844)

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

Release Notes:

- N/A
This commit is contained in:
Kyle Kelley 2024-12-11 06:20:44 -08:00 committed by GitHub
parent ae351298b4
commit f8b6d71670
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 17 deletions

View file

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

View file

@ -173,7 +173,7 @@ impl ReplStore {
let remote_kernel_specifications = self.get_remote_kernel_specifications(cx); 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 let mut all_specs = local_kernel_specifications
.await? .await?
.into_iter() .into_iter()
@ -186,10 +186,21 @@ impl ReplStore {
} }
} }
this.update(&mut cx, |this, cx| { anyhow::Ok(all_specs)
this.kernel_specifications = all_specs; });
cx.notify();
}) 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(())
}) })
} }