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

View file

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