Compare commits

...

3 Commits

Author SHA1 Message Date
Piotr Osiewicz
06ee8deacb Update crates/task/src/lib.rs
Co-authored-by: Kirill Bulatov <kirill@zed.dev>
2024-06-05 11:42:57 +02:00
Piotr Osiewicz
857c2c7fbd Make clippy happy 2024-06-05 11:35:50 +02:00
Piotr Osiewicz
abb13f3abd task: Do not substitute Zed variables in command and env 2024-06-05 11:27:41 +02:00
6 changed files with 31 additions and 26 deletions

View File

@@ -128,7 +128,7 @@ impl Project {
id: spawn_task.id,
full_label: spawn_task.full_label,
label: spawn_task.label,
command_label: spawn_task.command_label,
command_label: spawn_task.command_flattened,
status: TaskStatus::Running,
completion_rx,
}),
@@ -152,7 +152,7 @@ impl Project {
id: spawn_task.id,
full_label: spawn_task.full_label,
label: spawn_task.label,
command_label: spawn_task.command_label,
command_label: spawn_task.command_flattened,
status: TaskStatus::Running,
completion_rx,
}),

View File

@@ -1107,7 +1107,7 @@ pub async fn spawn_ssh_task(
label: "Install zed over ssh".into(),
command,
args,
command_label: ssh_connection_string.clone(),
command_flattened: ssh_connection_string.clone(),
cwd: Some(TerminalWorkDir::Ssh {
ssh_command: ssh_connection_string,
path: None,

View File

@@ -66,8 +66,8 @@ pub struct SpawnInTerminal {
/// 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,
/// A command with all of its arguments appended.
pub command_flattened: String,
/// Current working directory to spawn the command into.
pub cwd: Option<TerminalWorkDir>,
/// Env overrides for the command, will be appended to the terminal's environment from the settings.

View File

@@ -143,13 +143,13 @@ impl TaskTemplate {
&variable_names,
&mut substituted_variables,
)?;
let command = substitute_all_template_variables_in_str(
let _command = substitute_all_template_variables_in_str(
&self.command,
&task_variables,
&variable_names,
&mut substituted_variables,
)?;
let args_with_substitutions = substitute_all_template_variables_in_vec(
let _args_with_substitutions = substitute_all_template_variables_in_vec(
&self.args,
&task_variables,
&variable_names,
@@ -163,12 +163,14 @@ impl TaskTemplate {
.context("hashing task variables")
.log_err()?;
let id = TaskId(format!("{id_base}_{task_hash}_{variables_hash}"));
let mut env = substitute_all_template_variables_in_map(
let mut _env = substitute_all_template_variables_in_map(
&self.env,
&task_variables,
&variable_names,
&mut substituted_variables,
)?;
let mut env = self.env.clone();
env.extend(task_variables.into_iter().map(|(k, v)| (k, v.to_owned())));
Some(ResolvedTask {
id: id.clone(),
@@ -180,15 +182,15 @@ impl TaskTemplate {
cwd,
full_label,
label: human_readable_label,
command_label: args_with_substitutions.iter().fold(
command.clone(),
command_flattened: self.args.iter().fold(
self.command.clone(),
|mut command_label, arg| {
command_label.push(' ');
command_label.push_str(arg);
command_label
},
),
command,
command: self.command.clone(),
args: self.args.clone(),
env,
use_new_terminal: self.use_new_terminal,
@@ -528,8 +530,8 @@ mod tests {
);
assert_eq!(
spawn_in_terminal.command,
format!("echo test_file {long_value}"),
"Command should be substituted with variables and those should not be shortened"
format!("echo $ZED_FILE $ZED_SYMBOL"),
"Command should not be substituted with variables"
);
assert_eq!(
spawn_in_terminal.args,
@@ -541,9 +543,12 @@ mod tests {
"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"
spawn_in_terminal.command_flattened,
format!(
"{} arg1 $ZED_SELECTED_TEXT arg2 $ZED_COLUMN arg3 $ZED_SYMBOL",
spawn_in_terminal.command
),
"Command label args should not be substituted with variables"
);
assert_eq!(
@@ -555,16 +560,16 @@ mod tests {
);
assert_eq!(
spawn_in_terminal.env.get("env_key_1").map(|s| s.as_str()),
Some("/test_root/")
Some("$ZED_WORKTREE_ROOT")
);
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 $ZED_CUSTOM_custom_variable_1 $ZED_CUSTOM_custom_variable_2")
);
assert_eq!(
spawn_in_terminal.env.get("env_key_3"),
Some(&format!("env_var_3 {long_value}")),
"Env vars should be substituted with variables and those should not be shortened"
spawn_in_terminal.env.get("env_key_3").map(|s| s.as_str()),
Some("env_var_3 $ZED_SYMBOL"),
"Env vars should not be substituted with variables and those should not be shortened"
);
}

View File

@@ -362,13 +362,13 @@ impl PickerDelegate for TasksModalDelegate {
String::new()
};
if let Some(resolved) = resolved_task.resolved.as_ref() {
if resolved.command_label != display_label
&& resolved.command_label != resolved_task.resolved_label
if resolved.command_flattened != display_label
&& resolved.command_flattened != resolved_task.resolved_label
{
if !tooltip_label_text.trim().is_empty() {
tooltip_label_text.push('\n');
}
tooltip_label_text.push_str(&resolved.command_label);
tooltip_label_text.push_str(&resolved.command_flattened);
}
}
let tooltip_label = if tooltip_label_text.trim().is_empty() {
@@ -466,7 +466,7 @@ impl PickerDelegate for TasksModalDelegate {
let task_index = self.matches.get(self.selected_index())?.candidate_id;
let tasks = self.candidates.as_ref()?;
let (_, task) = tasks.get(task_index)?;
Some(task.resolved.as_ref()?.command_label.clone())
Some(task.resolved.as_ref()?.command_flattened.clone())
}
fn confirm_input(&mut self, omit_history_entry: bool, cx: &mut ViewContext<Picker<Self>>) {

View File

@@ -357,7 +357,7 @@ impl TerminalPanel {
return;
};
spawn_task.command_label = format!("{shell} -i -c `{}`", spawn_task.command_label);
spawn_task.command_flattened = format!("{shell} -i -c `{}`", spawn_task.command_flattened);
let task_command = std::mem::replace(&mut spawn_task.command, shell);
let task_args = std::mem::take(&mut spawn_task.args);
let combined_command = task_args