From 088fc8509ff4ffd1077ec1c6a3d09652be8784bd Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 21:27:50 +0100 Subject: [PATCH] toolchains: Run listing tasks on background thread (cherry-pick #21414) (#21421) Cherry-picked 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 Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> --- 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 cd9a3bc4032b0de915ccf06f132b5850150dcd52..3fc1ac4514834cf155db359942e064c30c3299b0 100644 --- a/crates/language/src/toolchain.rs +++ b/crates/language/src/toolchain.rs @@ -22,7 +22,7 @@ pub struct Toolchain { pub language_name: LanguageName, } -#[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 de4bf2f2c2ec2cca5f4c9b458dba583bed049fea..abc56946786dec0add1bf724ec60d4c2f591f01d 100644 --- a/crates/languages/src/python.rs +++ b/crates/languages/src/python.rs @@ -526,7 +526,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 c601ff8f12c86ed6f8f1faff9a4d8f7c565c4f7b..cd5f10617839cb8bd1a8d35ce49b56fb7dd0f5aa 100644 --- a/crates/project/src/toolchain_store.rs +++ b/crates/project/src/toolchain_store.rs @@ -308,12 +308,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(