Don't spawn for will_fetch_server as it is being immediately awaited anyways

This commit is contained in:
Lukas Wirth 2025-08-06 12:46:59 +02:00
parent aae59a2842
commit 9733d34c94
2 changed files with 17 additions and 22 deletions

View file

@ -29,7 +29,7 @@ use async_trait::async_trait;
use collections::{HashMap, HashSet, IndexSet};
use fs::Fs;
use futures::Future;
use gpui::{App, AsyncApp, Entity, SharedString, Task};
use gpui::{App, AsyncApp, Entity, SharedString};
pub use highlight_map::HighlightMap;
use http_client::HttpClient;
pub use language_registry::{
@ -491,8 +491,8 @@ pub trait LspInstaller {
&self,
_: &Arc<dyn LspAdapterDelegate>,
_: &mut AsyncApp,
) -> Option<Task<Result<()>>> {
None
) -> impl Future<Output = Result<()>> {
async { Ok(()) }
}
fn check_if_version_installed(
@ -545,9 +545,7 @@ where
container_dir: PathBuf,
cx: &mut AsyncApp,
) -> Result<LanguageServerBinary> {
if let Some(task) = self.will_fetch_server(delegate, cx) {
task.await?;
}
self.will_fetch_server(delegate, cx).await?;
let name = self.name();

View file

@ -83,31 +83,28 @@ impl LspInstaller for GoLspAdapter {
})
}
fn will_fetch_server(
async fn will_fetch_server(
&self,
delegate: &Arc<dyn LspAdapterDelegate>,
cx: &mut AsyncApp,
) -> Option<Task<Result<()>>> {
) -> Result<()> {
static DID_SHOW_NOTIFICATION: AtomicBool = AtomicBool::new(false);
const NOTIFICATION_MESSAGE: &str =
"Could not install the Go language server `gopls`, because `go` was not found.";
let delegate = delegate.clone();
Some(cx.spawn(async move |cx| {
if delegate.which("go".as_ref()).await.is_none() {
if DID_SHOW_NOTIFICATION
.compare_exchange(false, true, SeqCst, SeqCst)
.is_ok()
{
cx.update(|cx| {
delegate.show_notification(NOTIFICATION_MESSAGE, cx);
})?
}
anyhow::bail!("cannot install gopls");
if delegate.which("go".as_ref()).await.is_none() {
if DID_SHOW_NOTIFICATION
.compare_exchange(false, true, SeqCst, SeqCst)
.is_ok()
{
cx.update(|cx| {
delegate.show_notification(NOTIFICATION_MESSAGE, cx);
})?
}
Ok(())
}))
anyhow::bail!("cannot install gopls");
}
Ok(())
}
async fn fetch_server_binary(