Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

debugger: Fix auto-updates for Delve (#66025)

Piotr Osiewicz2214d0a92e81
diff --git a/crates/dap_adapters/src/go.rs b/crates/dap_adapters/src/go.rs
index 7d9af1d7341..eb37cb04ef5 100644
--- a/crates/dap_adapters/src/go.rs
+++ b/crates/dap_adapters/src/go.rs
@@ -453,35 +453,41 @@ impl DebugAdapter for GoDebugAdapter {
path.to_string_lossy().into_owned()
} else if let Some(path) = delegate.which(OsStr::new("dlv")).await {
path.to_string_lossy().into_owned()
- } else if delegate.fs().is_file(&dlv_path).await {
- dlv_path.to_string_lossy().into_owned()
} else {
- let go = delegate
- .which(OsStr::new("go"))
- .await
- .context("Go not found in path. Please install Go first, then Dlv will be installed automatically.")?;
-
- let adapter_path = paths::debug_adapters_dir().join(&Self::ADAPTER_NAME);
-
- let install_output = util::command::new_command(&go)
- .env("GO111MODULE", "on")
- .env("GOBIN", &adapter_path)
- .args(&["install", "github.com/go-delve/delve/cmd/dlv@latest"])
- .output()
- .await?;
+ // Refresh managed Delve for each debug session so Go upgrades aren't blocked by a stale binary.
+ let install_result = async {
+ let go = delegate
+ .which(OsStr::new("go"))
+ .await
+ .context("Go not found in path. Please install Go first, then Dlv will be installed automatically.")?;
+
+ let install_output = util::command::new_command(&go)
+ .env("GO111MODULE", "on")
+ .env("GOBIN", &adapter_path)
+ .args(&["install", "github.com/go-delve/delve/cmd/dlv@latest"])
+ .output()
+ .await?;
+
+ if !install_output.status.success() {
+ bail!(
+ "failed to install dlv via `go install`. stdout: {:?}, stderr: {:?}\n Please try installing it manually using 'go install github.com/go-delve/delve/cmd/dlv@latest'",
+ String::from_utf8_lossy(&install_output.stdout),
+ String::from_utf8_lossy(&install_output.stderr)
+ );
+ }
+ anyhow::Ok(())
+ }
+ .await;
- if !install_output.status.success() {
- bail!(
- "failed to install dlv via `go install`. stdout: {:?}, stderr: {:?}\n Please try installing it manually using 'go install github.com/go-delve/delve/cmd/dlv@latest'",
- String::from_utf8_lossy(&install_output.stdout),
- String::from_utf8_lossy(&install_output.stderr)
- );
+ if let Err(error) = install_result {
+ if delegate.fs().is_file(&dlv_path).await {
+ warn!("Failed to update Delve, using cached version: {error:#}");
+ } else {
+ return Err(error);
+ }
}
- adapter_path
- .join(&dlv_binary)
- .to_string_lossy()
- .into_owned()
+ dlv_path.to_string_lossy().into_owned()
};
let cwd = Some(