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.

Fix unexpected argument ' ' upon trying to debug while cargo is indexing (#61241)

Pingya5d1afa534aa
diff --git a/crates/task/src/task_template.rs b/crates/task/src/task_template.rs
index dfd44590604..e6cc357bf68 100644
--- a/crates/task/src/task_template.rs
+++ b/crates/task/src/task_template.rs
@@ -452,7 +452,10 @@ fn substitute_all_template_variables_in_vec(
variable_names,
substituted_variables,
)?;
- expanded.push(new_value);
+
+ if !new_value.is_empty() || variable.is_empty() {
+ expanded.push(new_value);
+ }
}
Some(expanded)
@@ -1151,4 +1154,46 @@ mod tests {
],
);
}
+
+ #[test]
+ fn test_args_produced_by_empty_variables_are_omitted() {
+ let features_flag = VariableName::Custom(Cow::Borrowed("features_flag"));
+ let features = VariableName::Custom(Cow::Borrowed("features"));
+ let bin_name = VariableName::Custom(Cow::Borrowed("bin_name"));
+
+ let task = TaskTemplate {
+ label: "cargo run".to_string(),
+ command: "cargo".to_string(),
+ args: vec![
+ "run".to_string(),
+ "--bin".to_string(),
+ bin_name.template_value(),
+ features_flag.template_value(),
+ features.template_value(),
+ String::new(),
+ format!("--config={}", features.template_value()),
+ ],
+ ..TaskTemplate::default()
+ };
+
+ let context = TaskContext {
+ task_variables: TaskVariables::from_iter([
+ (features_flag, String::new()),
+ (features, String::new()),
+ (bin_name, "test_bin".to_string()),
+ ]),
+ ..TaskContext::default()
+ };
+
+ let resolved = task
+ .resolve_task(TEST_ID_BASE, &context)
+ .unwrap_or_else(|| panic!("failed to resolve task {task:?}"))
+ .resolved;
+ assert_eq!(
+ resolved.args,
+ vec!["run", "--bin", "test_bin", "", "--config="],
+ "args that consist entirely of variables resolved to empty strings should be omitted, \
+ while literal empty args and partially substituted args should be preserved"
+ );
+ }
}