Skip to content

Commit aab7620

Browse files
authored
debugger beta: Fix bug where debug Rust main running action failed (#31291)
@osiewicz @SomeoneToIgnore If you guys have time to look this over it would be greatly appreciated. I wanted to move the bug fix into the task resolution code but wasn't sure if there was a reason that we didn't already. The bug is caused by an env variable being empty when we send it as a terminal command. When the shell resolves all the env variables there's an extra space that gets added due to the empty env variable being placed between two other variables. Closes #31240 Release Notes: - debugger beta: Fix a bug where debug main Rust runner action wouldn't work
1 parent f3f0766 commit aab7620

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

crates/debugger_ui/src/session/running.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ impl RunningState {
874874
args,
875875
..task.resolved.clone()
876876
};
877+
877878
let terminal = project
878879
.update_in(cx, |project, window, cx| {
879880
project.create_terminal(
@@ -918,12 +919,6 @@ impl RunningState {
918919
};
919920

920921
if config_is_valid {
921-
// Ok(DebugTaskDefinition {
922-
// label,
923-
// adapter: DebugAdapterName(adapter),
924-
// config,
925-
// tcp_connection,
926-
// })
927922
} else if let Some((task, locator_name)) = build_output {
928923
let locator_name =
929924
locator_name.context("Could not find a valid locator for a build task")?;
@@ -942,7 +937,7 @@ impl RunningState {
942937

943938
let scenario = dap_registry
944939
.adapter(&adapter)
945-
.ok_or_else(|| anyhow!("{}: is not a valid adapter name", &adapter))
940+
.context(format!("{}: is not a valid adapter name", &adapter))
946941
.map(|adapter| adapter.config_from_zed_format(zed_config))??;
947942
config = scenario.config;
948943
Self::substitute_variables_in_config(&mut config, &task_context);

crates/task/src/task_template.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,18 @@ impl TaskTemplate {
237237
env
238238
};
239239

240+
// We filter out env variables here that aren't set so we don't have extra white space in args
241+
let args = self
242+
.args
243+
.iter()
244+
.filter(|arg| {
245+
arg.starts_with('$')
246+
.then(|| env.get(&arg[1..]).is_some_and(|arg| !arg.trim().is_empty()))
247+
.unwrap_or(true)
248+
})
249+
.cloned()
250+
.collect();
251+
240252
Some(ResolvedTask {
241253
id: id.clone(),
242254
substituted_variables,
@@ -256,7 +268,7 @@ impl TaskTemplate {
256268
},
257269
),
258270
command,
259-
args: self.args.clone(),
271+
args,
260272
env,
261273
use_new_terminal: self.use_new_terminal,
262274
allow_concurrent_runs: self.allow_concurrent_runs,
@@ -703,6 +715,7 @@ mod tests {
703715
label: "My task".into(),
704716
command: "echo".into(),
705717
args: vec!["$PATH".into()],
718+
env: HashMap::from_iter([("PATH".to_owned(), "non-empty".to_owned())]),
706719
..TaskTemplate::default()
707720
};
708721
let resolved_task = task
@@ -715,6 +728,32 @@ mod tests {
715728
assert_eq!(resolved.args, task.args);
716729
}
717730

731+
#[test]
732+
fn test_empty_env_variables_excluded_from_args() {
733+
let task = TaskTemplate {
734+
label: "My task".into(),
735+
command: "echo".into(),
736+
args: vec![
737+
"$EMPTY_VAR".into(),
738+
"hello".into(),
739+
"$WHITESPACE_VAR".into(),
740+
"$UNDEFINED_VAR".into(),
741+
"$WORLD".into(),
742+
],
743+
env: HashMap::from_iter([
744+
("EMPTY_VAR".to_owned(), "".to_owned()),
745+
("WHITESPACE_VAR".to_owned(), " ".to_owned()),
746+
("WORLD".to_owned(), "non-empty".to_owned()),
747+
]),
748+
..TaskTemplate::default()
749+
};
750+
let resolved_task = task
751+
.resolve_task(TEST_ID_BASE, &TaskContext::default())
752+
.unwrap();
753+
let resolved = resolved_task.resolved;
754+
assert_eq!(resolved.args, vec!["hello", "$WORLD"]);
755+
}
756+
718757
#[test]
719758
fn test_errors_on_missing_zed_variable() {
720759
let task = TaskTemplate {

0 commit comments

Comments
 (0)