Add the ability for tasks to target the center pane (#22004)

Closes #20060
Closes #20720
Closes #19873
Closes #9445

Release Notes:

- Fixed a bug where tasks would be spawned with their working directory
set to a file in some cases
- Added the ability to spawn tasks in the center pane, when spawning
from a keybinding:

```json5
[
  {
    // Assuming you have a task labeled "echo hello"
    "ctrl--": [
      "task::Spawn",
      { "task_name": "echo hello", "target": "center" }
    ]
  }
]
```
This commit is contained in:
Mikayla Maki 2024-12-13 19:39:46 -08:00 committed by GitHub
parent 85c3aec6e7
commit 4f96706161
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 263 additions and 106 deletions

View file

@ -11,6 +11,7 @@ mod modal;
mod settings;
pub use modal::{Rerun, Spawn};
use zed_actions::TaskSpawnTarget;
pub fn init(cx: &mut AppContext) {
settings::TaskSettings::register(cx);
@ -53,6 +54,7 @@ pub fn init(cx: &mut AppContext) {
task_source_kind,
&original_task,
&task_context,
Default::default(),
false,
cx,
)
@ -89,7 +91,8 @@ pub fn init(cx: &mut AppContext) {
fn spawn_task_or_modal(workspace: &mut Workspace, action: &Spawn, cx: &mut ViewContext<Workspace>) {
match &action.task_name {
Some(name) => spawn_task_with_name(name.clone(), cx).detach_and_log_err(cx),
Some(name) => spawn_task_with_name(name.clone(), action.target.unwrap_or_default(), cx)
.detach_and_log_err(cx),
None => toggle_modal(workspace, cx).detach(),
}
}
@ -119,6 +122,7 @@ fn toggle_modal(workspace: &mut Workspace, cx: &mut ViewContext<'_, Workspace>)
fn spawn_task_with_name(
name: String,
task_target: TaskSpawnTarget,
cx: &mut ViewContext<Workspace>,
) -> AsyncTask<anyhow::Result<()>> {
cx.spawn(|workspace, mut cx| async move {
@ -160,6 +164,7 @@ fn spawn_task_with_name(
task_source_kind,
&target_task,
&task_context,
task_target,
false,
cx,
);

View file

@ -68,7 +68,7 @@ impl TasksModalDelegate {
};
Some((
source_kind,
new_oneshot.resolve_task(&id_base, &self.task_context)?,
new_oneshot.resolve_task(&id_base, Default::default(), &self.task_context)?,
))
}
@ -684,6 +684,7 @@ mod tests {
cx.dispatch_action(Spawn {
task_name: Some("example task".to_string()),
target: None,
});
let tasks_picker = workspace.update(cx, |workspace, cx| {
workspace