Allow rerunning tasks with unknown termination status (#16374)

Kirill Bulatov created

Change summary

crates/terminal_view/src/terminal_view.rs | 35 ++++++++++++++----------
1 file changed, 20 insertions(+), 15 deletions(-)

Detailed changes

crates/terminal_view/src/terminal_view.rs 🔗

@@ -943,26 +943,31 @@ impl Item for TerminalView {
     fn tab_content(&self, params: TabContentParams, cx: &WindowContext) -> AnyElement {
         let terminal = self.terminal().read(cx);
         let title = terminal.title(true);
+        let rerun_button = |task_id: task::TaskId| {
+            IconButton::new("rerun-icon", IconName::Rerun)
+                .icon_size(IconSize::Small)
+                .size(ButtonSize::Compact)
+                .icon_color(Color::Default)
+                .shape(ui::IconButtonShape::Square)
+                .tooltip(|cx| Tooltip::text("Rerun task", cx))
+                .on_click(move |_, cx| {
+                    cx.dispatch_action(Box::new(tasks_ui::Rerun {
+                        task_id: Some(task_id.clone()),
+                        ..tasks_ui::Rerun::default()
+                    }));
+                })
+        };
 
         let (icon, icon_color, rerun_button) = match terminal.task() {
             Some(terminal_task) => match &terminal_task.status {
-                TaskStatus::Unknown => (IconName::ExclamationTriangle, Color::Warning, None),
                 TaskStatus::Running => (IconName::Play, Color::Disabled, None),
+                TaskStatus::Unknown => (
+                    IconName::ExclamationTriangle,
+                    Color::Warning,
+                    Some(rerun_button(terminal_task.id.clone())),
+                ),
                 TaskStatus::Completed { success } => {
-                    let task_id = terminal_task.id.clone();
-                    let rerun_button = IconButton::new("rerun-icon", IconName::Rerun)
-                        .icon_size(IconSize::Small)
-                        .size(ButtonSize::Compact)
-                        .icon_color(Color::Default)
-                        .shape(ui::IconButtonShape::Square)
-                        .tooltip(|cx| Tooltip::text("Rerun task", cx))
-                        .on_click(move |_, cx| {
-                            cx.dispatch_action(Box::new(tasks_ui::Rerun {
-                                task_id: Some(task_id.clone()),
-                                ..Default::default()
-                            }));
-                        });
-
+                    let rerun_button = rerun_button(terminal_task.id.clone());
                     if *success {
                         (IconName::Check, Color::Success, Some(rerun_button))
                     } else {