task: Always use untruncated label if it is short (#23611)

Also changed rust tasks to be less mouthful.

Release Notes:

- Shortened Rust task labels.
- Task modal will now use full task label when it does not require
truncation.
This commit is contained in:
Piotr Osiewicz 2025-01-24 17:46:48 +01:00 committed by GitHub
parent 7c2b17540b
commit 77e9d01b39
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 22 deletions

View file

@ -523,7 +523,7 @@ impl ContextProvider for RustContextProvider {
Some(TaskTemplates(vec![ Some(TaskTemplates(vec![
TaskTemplate { TaskTemplate {
label: format!( label: format!(
"cargo check -p {}", "Check (package: {})",
RUST_PACKAGE_TASK_VARIABLE.template_value(), RUST_PACKAGE_TASK_VARIABLE.template_value(),
), ),
command: "cargo".into(), command: "cargo".into(),
@ -536,7 +536,7 @@ impl ContextProvider for RustContextProvider {
..TaskTemplate::default() ..TaskTemplate::default()
}, },
TaskTemplate { TaskTemplate {
label: "cargo check --workspace --all-targets".into(), label: "Check all targets (workspace)".into(),
command: "cargo".into(), command: "cargo".into(),
args: vec!["check".into(), "--workspace".into(), "--all-targets".into()], args: vec!["check".into(), "--workspace".into(), "--all-targets".into()],
cwd: Some("$ZED_DIRNAME".to_owned()), cwd: Some("$ZED_DIRNAME".to_owned()),
@ -544,9 +544,9 @@ impl ContextProvider for RustContextProvider {
}, },
TaskTemplate { TaskTemplate {
label: format!( label: format!(
"cargo test -p {} {} -- --nocapture", "Test '{}' (package: {})",
RUST_PACKAGE_TASK_VARIABLE.template_value(),
VariableName::Symbol.template_value(), VariableName::Symbol.template_value(),
RUST_PACKAGE_TASK_VARIABLE.template_value(),
), ),
command: "cargo".into(), command: "cargo".into(),
args: vec![ args: vec![
@ -563,9 +563,9 @@ impl ContextProvider for RustContextProvider {
}, },
TaskTemplate { TaskTemplate {
label: format!( label: format!(
"cargo test -p {} {}", "Test '{}' (package: {})",
RUST_PACKAGE_TASK_VARIABLE.template_value(),
VariableName::Stem.template_value(), VariableName::Stem.template_value(),
RUST_PACKAGE_TASK_VARIABLE.template_value(),
), ),
command: "cargo".into(), command: "cargo".into(),
args: vec![ args: vec![
@ -580,10 +580,10 @@ impl ContextProvider for RustContextProvider {
}, },
TaskTemplate { TaskTemplate {
label: format!( label: format!(
"cargo run -p {} --{} {}", "Run {} {} (package: {})",
RUST_PACKAGE_TASK_VARIABLE.template_value(),
RUST_BIN_KIND_TASK_VARIABLE.template_value(), RUST_BIN_KIND_TASK_VARIABLE.template_value(),
RUST_BIN_NAME_TASK_VARIABLE.template_value(), RUST_BIN_NAME_TASK_VARIABLE.template_value(),
RUST_PACKAGE_TASK_VARIABLE.template_value(),
), ),
command: "cargo".into(), command: "cargo".into(),
args: vec![ args: vec![
@ -599,7 +599,7 @@ impl ContextProvider for RustContextProvider {
}, },
TaskTemplate { TaskTemplate {
label: format!( label: format!(
"cargo test -p {}", "Test (package: {})",
RUST_PACKAGE_TASK_VARIABLE.template_value() RUST_PACKAGE_TASK_VARIABLE.template_value()
), ),
command: "cargo".into(), command: "cargo".into(),
@ -612,14 +612,14 @@ impl ContextProvider for RustContextProvider {
..TaskTemplate::default() ..TaskTemplate::default()
}, },
TaskTemplate { TaskTemplate {
label: "cargo run".into(), label: "Run".into(),
command: "cargo".into(), command: "cargo".into(),
args: run_task_args, args: run_task_args,
cwd: Some("$ZED_DIRNAME".to_owned()), cwd: Some("$ZED_DIRNAME".to_owned()),
..TaskTemplate::default() ..TaskTemplate::default()
}, },
TaskTemplate { TaskTemplate {
label: "cargo clean".into(), label: "Clean".into(),
command: "cargo".into(), command: "cargo".into(),
args: vec!["clean".into()], args: vec!["clean".into()],
cwd: Some("$ZED_DIRNAME".to_owned()), cwd: Some("$ZED_DIRNAME".to_owned()),

View file

@ -154,12 +154,26 @@ impl TaskTemplate {
None => None, None => None,
} }
.or(cx.cwd.clone()); .or(cx.cwd.clone());
let human_readable_label = substitute_all_template_variables_in_str( let full_label = substitute_all_template_variables_in_str(
&self.label, &self.label,
&truncated_variables, &task_variables,
&variable_names, &variable_names,
&mut substituted_variables, &mut substituted_variables,
)? )?;
// Arbitrarily picked threshold below which we don't truncate any variables.
const TRUNCATION_THRESHOLD: usize = 64;
let human_readable_label = if full_label.len() > TRUNCATION_THRESHOLD {
substitute_all_template_variables_in_str(
&self.label,
&truncated_variables,
&variable_names,
&mut substituted_variables,
)?
} else {
full_label.clone()
}
.lines() .lines()
.fold(String::new(), |mut string, line| { .fold(String::new(), |mut string, line| {
if string.is_empty() { if string.is_empty() {
@ -170,12 +184,7 @@ impl TaskTemplate {
} }
string string
}); });
let full_label = substitute_all_template_variables_in_str(
&self.label,
&task_variables,
&variable_names,
&mut substituted_variables,
)?;
let command = substitute_all_template_variables_in_str( let command = substitute_all_template_variables_in_str(
&self.command, &self.command,
&task_variables, &task_variables,

View file

@ -791,7 +791,7 @@ mod tests {
assert_eq!( assert_eq!(
task_names(&tasks_picker, cx), task_names(&tasks_picker, cx),
vec![ vec![
"hello from h.odd_extension:1:1".to_string(), "hello from /dir/file_with.odd_extension:1:1".to_string(),
"opened now: /dir".to_string() "opened now: /dir".to_string()
], ],
"Second opened buffer should fill the context, labels should be trimmed if long enough" "Second opened buffer should fill the context, labels should be trimmed if long enough"
@ -820,7 +820,7 @@ mod tests {
assert_eq!( assert_eq!(
task_names(&tasks_picker, cx), task_names(&tasks_picker, cx),
vec![ vec![
"hello from thout_extension:2:3".to_string(), "hello from /dir/file_without_extension:2:3".to_string(),
"opened now: /dir".to_string() "opened now: /dir".to_string()
], ],
"Opened buffer should fill the context, labels should be trimmed if long enough" "Opened buffer should fill the context, labels should be trimmed if long enough"