From 59dc6cf523678f7a2ce0883fd2258c4a1af838c1 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 2 Dec 2024 21:03:31 +0100 Subject: [PATCH] toolchains: Run listing tasks on background thread (#21414) Potentially fixes #21404 This is a speculative fix, as while I was trying to repro this issue I've noticed that introducing artificial delays in ToolchainLister::list could impact apps responsiveness. These delays were essentially there to stimulate PET taking a while to find venvs. Release Notes: - Improved app responsiveness in environments with multiple Python virtual environments --- crates/language/src/toolchain.rs | 2 +- crates/languages/src/python.rs | 2 +- crates/project/src/toolchain_store.rs | 14 ++++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/language/src/toolchain.rs b/crates/language/src/toolchain.rs index fe8936db084a6..13703d81a7cd9 100644 --- a/crates/language/src/toolchain.rs +++ b/crates/language/src/toolchain.rs @@ -24,7 +24,7 @@ pub struct Toolchain { pub as_json: serde_json::Value, } -#[async_trait(?Send)] +#[async_trait] pub trait ToolchainLister: Send + Sync { async fn list( &self, diff --git a/crates/languages/src/python.rs b/crates/languages/src/python.rs index 8736a129424ec..ec7ddde61dbad 100644 --- a/crates/languages/src/python.rs +++ b/crates/languages/src/python.rs @@ -536,7 +536,7 @@ fn env_priority(kind: Option) -> usize { } } -#[async_trait(?Send)] +#[async_trait] impl ToolchainLister for PythonToolchainProvider { async fn list( &self, diff --git a/crates/project/src/toolchain_store.rs b/crates/project/src/toolchain_store.rs index 4d4c32d74550c..71228d96a4356 100644 --- a/crates/project/src/toolchain_store.rs +++ b/crates/project/src/toolchain_store.rs @@ -311,12 +311,14 @@ impl LocalToolchainStore { }) .ok()? .await; - let language = registry.language_for_name(&language_name.0).await.ok()?; - let toolchains = language - .toolchain_lister()? - .list(root.to_path_buf(), project_env) - .await; - Some(toolchains) + + cx.background_executor() + .spawn(async move { + let language = registry.language_for_name(&language_name.0).await.ok()?; + let toolchains = language.toolchain_lister()?; + Some(toolchains.list(root.to_path_buf(), project_env).await) + }) + .await }) } pub(crate) fn active_toolchain(