@@ -121,6 +121,9 @@ impl ResolvedTask {
}
/// Variables, available for use in [`TaskContext`] when a Zed's [`TaskTemplate`] gets resolved into a [`ResolvedTask`].
+/// Name of the variable must be a valid shell variable identifier, which generally means that it is
+/// a word consisting only of alphanumeric characters and underscores,
+/// and beginning with an alphabetic character or an underscore.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize)]
pub enum VariableName {
/// An absolute path of the currently opened file.
@@ -146,19 +149,14 @@ pub enum VariableName {
/// The symbol selected by the symbol tagging system, specifically the @run capture in a runnables.scm
RunnableSymbol,
/// Custom variable, provided by the plugin or other external source.
- /// Will be printed with `ZED_` prefix to avoid potential conflicts with other variables.
+ /// Will be printed with `CUSTOM_` prefix to avoid potential conflicts with other variables.
Custom(Cow<'static, str>),
}
impl VariableName {
/// Generates a `$VARIABLE`-like string value to be used in templates.
- /// Custom variables are wrapped in `${}` to avoid substitution issues with whitespaces.
pub fn template_value(&self) -> String {
- if matches!(self, Self::Custom(_)) {
- format!("${{{self}}}")
- } else {
- format!("${self}")
- }
+ format!("${self}")
}
}
@@ -469,14 +469,14 @@ mod tests {
(
"env_key_2".to_string(),
format!(
- "env_var_2_{}_{}",
+ "env_var_2 {} {}",
custom_variable_1.template_value(),
custom_variable_2.template_value()
),
),
(
"env_key_3".to_string(),
- format!("env_var_3_{}", VariableName::Symbol.template_value()),
+ format!("env_var_3 {}", VariableName::Symbol.template_value()),
),
]),
..TaskTemplate::default()
@@ -559,11 +559,11 @@ mod tests {
);
assert_eq!(
spawn_in_terminal.env.get("env_key_2").map(|s| s.as_str()),
- Some("env_var_2_test_custom_variable_1_test_custom_variable_2")
+ Some("env_var_2 test_custom_variable_1 test_custom_variable_2")
);
assert_eq!(
spawn_in_terminal.env.get("env_key_3"),
- Some(&format!("env_var_3_{long_value}")),
+ Some(&format!("env_var_3 {long_value}")),
"Env vars should be substituted with variables and those should not be shortened"
);
}