Skip to content

Commit

Permalink
toolchains: Run listing tasks on background thread (#21414)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
osiewicz authored Dec 2, 2024
1 parent b88daae commit 59dc6cf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/language/src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/languages/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ fn env_priority(kind: Option<PythonEnvironmentKind>) -> usize {
}
}

#[async_trait(?Send)]
#[async_trait]
impl ToolchainLister for PythonToolchainProvider {
async fn list(
&self,
Expand Down
14 changes: 8 additions & 6 deletions crates/project/src/toolchain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 59dc6cf

Please sign in to comment.