Properly pass nested script arguments for tasks (#10776)
Closes https://github.com/zed-industries/zed/discussions/10732#discussion-6524347 introduced by https://github.com/zed-industries/zed/pull/10548 while keeping both Python and Bash run selection capabilities. Also replaced redundant `SpawnTask` struct with `SpawnInTerminal` that has identical fields. Release Notes: - Fixed incorrect task escaping of nested script arguments --------- Co-authored-by: Piotr Osiewicz <piotr@zed.dev>
This commit is contained in:
parent
9247da77a3
commit
13c17267b9
10 changed files with 55 additions and 85 deletions
|
@ -31,8 +31,11 @@ pub struct SpawnInTerminal {
|
|||
pub label: String,
|
||||
/// Executable command to spawn.
|
||||
pub command: String,
|
||||
/// Arguments to the command.
|
||||
/// Arguments to the command, potentially unsubstituted,
|
||||
/// to let the shell that spawns the command to do the substitution, if needed.
|
||||
pub args: Vec<String>,
|
||||
/// A human-readable label, containing command and all of its arguments, joined and substituted.
|
||||
pub command_label: String,
|
||||
/// Current working directory to spawn the command into.
|
||||
pub cwd: Option<PathBuf>,
|
||||
/// Env overrides for the command, will be appended to the terminal's environment from the settings.
|
||||
|
@ -76,18 +79,6 @@ impl ResolvedTask {
|
|||
&self.substituted_variables
|
||||
}
|
||||
|
||||
/// If the resolution produced a task with the command, returns a string, combined from its command and arguments.
|
||||
pub fn resolved_command(&self) -> Option<String> {
|
||||
self.resolved.as_ref().map(|resolved| {
|
||||
let mut command = resolved.command.clone();
|
||||
for arg in &resolved.args {
|
||||
command.push(' ');
|
||||
command.push_str(arg);
|
||||
}
|
||||
command
|
||||
})
|
||||
}
|
||||
|
||||
/// A human-readable label to display in the UI.
|
||||
pub fn display_label(&self) -> &str {
|
||||
self.resolved
|
||||
|
|
|
@ -156,7 +156,7 @@ impl TaskTemplate {
|
|||
&variable_names,
|
||||
&mut substituted_variables,
|
||||
)?;
|
||||
let args = substitute_all_template_variables_in_vec(
|
||||
let args_with_substitutions = substitute_all_template_variables_in_vec(
|
||||
&self.args,
|
||||
&task_variables,
|
||||
&variable_names,
|
||||
|
@ -187,8 +187,16 @@ impl TaskTemplate {
|
|||
cwd,
|
||||
full_label,
|
||||
label: human_readable_label,
|
||||
command_label: args_with_substitutions.iter().fold(
|
||||
command.clone(),
|
||||
|mut command_label, arg| {
|
||||
command_label.push(' ');
|
||||
command_label.push_str(arg);
|
||||
command_label
|
||||
},
|
||||
),
|
||||
command,
|
||||
args,
|
||||
args: self.args.clone(),
|
||||
env,
|
||||
use_new_terminal: self.use_new_terminal,
|
||||
allow_concurrent_runs: self.allow_concurrent_runs,
|
||||
|
@ -524,11 +532,16 @@ mod tests {
|
|||
assert_eq!(
|
||||
spawn_in_terminal.args,
|
||||
&[
|
||||
"arg1 test_selected_text",
|
||||
"arg2 5678",
|
||||
&format!("arg3 {long_value}")
|
||||
"arg1 $ZED_SELECTED_TEXT",
|
||||
"arg2 $ZED_COLUMN",
|
||||
"arg3 $ZED_SYMBOL",
|
||||
],
|
||||
"Args should be substituted with variables and those should not be shortened"
|
||||
"Args should not be substituted with variables"
|
||||
);
|
||||
assert_eq!(
|
||||
spawn_in_terminal.command_label,
|
||||
format!("{} arg1 test_selected_text arg2 5678 arg3 {long_value}", spawn_in_terminal.command),
|
||||
"Command label args should be substituted with variables and those should not be shortened"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue