task: Do not wrap custom task variables in braces (#12322)
Fixes #10998 Release Notes: - N/A
This commit is contained in:
parent
71451b59cd
commit
a0f91299dd
2 changed files with 9 additions and 11 deletions
|
@ -121,6 +121,9 @@ impl ResolvedTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Variables, available for use in [`TaskContext`] when a Zed's [`TaskTemplate`] gets resolved into a [`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)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize)]
|
||||||
pub enum VariableName {
|
pub enum VariableName {
|
||||||
/// An absolute path of the currently opened file.
|
/// 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
|
/// The symbol selected by the symbol tagging system, specifically the @run capture in a runnables.scm
|
||||||
RunnableSymbol,
|
RunnableSymbol,
|
||||||
/// Custom variable, provided by the plugin or other external source.
|
/// 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>),
|
Custom(Cow<'static, str>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VariableName {
|
impl VariableName {
|
||||||
/// Generates a `$VARIABLE`-like string value to be used in templates.
|
/// 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 {
|
pub fn template_value(&self) -> String {
|
||||||
if matches!(self, Self::Custom(_)) {
|
format!("${self}")
|
||||||
format!("${{{self}}}")
|
|
||||||
} else {
|
|
||||||
format!("${self}")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -469,14 +469,14 @@ mod tests {
|
||||||
(
|
(
|
||||||
"env_key_2".to_string(),
|
"env_key_2".to_string(),
|
||||||
format!(
|
format!(
|
||||||
"env_var_2_{}_{}",
|
"env_var_2 {} {}",
|
||||||
custom_variable_1.template_value(),
|
custom_variable_1.template_value(),
|
||||||
custom_variable_2.template_value()
|
custom_variable_2.template_value()
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"env_key_3".to_string(),
|
"env_key_3".to_string(),
|
||||||
format!("env_var_3_{}", VariableName::Symbol.template_value()),
|
format!("env_var_3 {}", VariableName::Symbol.template_value()),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
..TaskTemplate::default()
|
..TaskTemplate::default()
|
||||||
|
@ -559,11 +559,11 @@ mod tests {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
spawn_in_terminal.env.get("env_key_2").map(|s| s.as_str()),
|
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!(
|
assert_eq!(
|
||||||
spawn_in_terminal.env.get("env_key_3"),
|
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"
|
"Env vars should be substituted with variables and those should not be shortened"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue