task: Do not wrap custom task variables in braces (#12322)

Fixes #10998

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-05-27 00:15:53 +02:00 committed by GitHub
parent 71451b59cd
commit a0f91299dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 11 deletions

View file

@ -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}")
}
}