From fbead09c30ca1b1371ae485958fc685f1bcf2d59 Mon Sep 17 00:00:00 2001 From: Lukas Spiss <35728419+Spissable@users.noreply.github.com> Date: Fri, 11 Jul 2025 19:26:46 +0100 Subject: [PATCH] go: Write `envFile` properties back to `env` config (#34300) Closes https://github.com/zed-industries/zed/issues/32984 Note that while https://github.com/zed-industries/zed/pull/33666 did the reading of the `envFile` just fine, the read values were never passed along. This was mentioned by [this comment](https://github.com/zed-industries/zed/pull/33666#issuecomment-3060785970) and also confirmed by myself. With the changes here, I successfully debugged a project of mine and all the environment variables from my `.env` were present. Release Notes: - Fix Go debugger ignoring env vars from the envFile setting. --- crates/dap_adapters/src/go.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/dap_adapters/src/go.rs b/crates/dap_adapters/src/go.rs index d32f5cbf3426f1b669132e74e389862e7944267b..22d8262b93e36b17e548ae4dcc9bb725da8ca7cb 100644 --- a/crates/dap_adapters/src/go.rs +++ b/crates/dap_adapters/src/go.rs @@ -547,6 +547,7 @@ async fn handle_envs( } }; + let mut env_vars = HashMap::default(); for path in env_files { let Some(path) = path .and_then(|s| PathBuf::from_str(s).ok()) @@ -556,13 +557,33 @@ async fn handle_envs( }; if let Ok(file) = fs.open_sync(&path).await { - envs.extend(dotenvy::from_read_iter(file).filter_map(Result::ok)) + let file_envs: HashMap = dotenvy::from_read_iter(file) + .filter_map(Result::ok) + .collect(); + envs.extend(file_envs.iter().map(|(k, v)| (k.clone(), v.clone()))); + env_vars.extend(file_envs); } else { warn!("While starting Go debug session: failed to read env file {path:?}"); }; } + let mut env_obj: serde_json::Map = serde_json::Map::new(); + + for (k, v) in env_vars { + env_obj.insert(k, Value::String(v)); + } + + if let Some(existing_env) = config.get("env").and_then(|v| v.as_object()) { + for (k, v) in existing_env { + env_obj.insert(k.clone(), v.clone()); + } + } + + if !env_obj.is_empty() { + config.insert("env".to_string(), Value::Object(env_obj)); + } + // remove envFile now that it's been handled - config.remove("entry"); + config.remove("envFile"); Some(()) }