Move task centering code closer to user input (#22082)

Follow-up of https://github.com/zed-industries/zed/pull/22004 

* Reuse center terminals for tasks, when requested
* Extend task templates with `RevealTarget`, moving it from
`TaskSpawnTarget` into the core library
* Use `reveal_target` instead of `target` to avoid misinterpretations in
the task template context
* Do not expose `SpawnInTerminal` to user interface, avoid it
implementing `Serialize` and `Deserialize`
* Remove `NewCenterTask` action, extending `task::Spawn` interface
instead
* Do not require any extra unrelated parameters during task resolution,
instead, use task overrides on the resolved tasks on the modal side
* Add keybindings for opening the task modal in the
`RevealTarget::Center` mode

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2024-12-16 16:15:58 +02:00 committed by GitHub
parent ea012075fc
commit bc113e4b51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 356 additions and 285 deletions

View file

@ -61,7 +61,6 @@ ui.workspace = true
util.workspace = true
uuid.workspace = true
strum.workspace = true
zed_actions.workspace = true
[dev-dependencies]
call = { workspace = true, features = ["test-support"] }

View file

@ -1,8 +1,7 @@
use project::TaskSourceKind;
use remote::ConnectionState;
use task::{NewCenterTask, ResolvedTask, TaskContext, TaskTemplate};
use task::{ResolvedTask, TaskContext, TaskTemplate};
use ui::ViewContext;
use zed_actions::TaskSpawnTarget;
use crate::Workspace;
@ -11,7 +10,6 @@ pub fn schedule_task(
task_source_kind: TaskSourceKind,
task_to_resolve: &TaskTemplate,
task_cx: &TaskContext,
task_target: zed_actions::TaskSpawnTarget,
omit_history: bool,
cx: &mut ViewContext<'_, Workspace>,
) {
@ -29,7 +27,7 @@ pub fn schedule_task(
}
if let Some(spawn_in_terminal) =
task_to_resolve.resolve_task(&task_source_kind.to_id_base(), task_target, task_cx)
task_to_resolve.resolve_task(&task_source_kind.to_id_base(), task_cx)
{
schedule_resolved_task(
workspace,
@ -48,7 +46,6 @@ pub fn schedule_resolved_task(
omit_history: bool,
cx: &mut ViewContext<'_, Workspace>,
) {
let target = resolved_task.target;
if let Some(spawn_in_terminal) = resolved_task.resolved.take() {
if !omit_history {
resolved_task.resolved = Some(spawn_in_terminal.clone());
@ -63,17 +60,8 @@ pub fn schedule_resolved_task(
});
}
match target {
TaskSpawnTarget::Center => {
cx.dispatch_action(Box::new(NewCenterTask {
action: spawn_in_terminal,
}));
}
TaskSpawnTarget::Dock => {
cx.emit(crate::Event::SpawnTask {
action: Box::new(spawn_in_terminal),
});
}
}
cx.emit(crate::Event::SpawnTask {
action: Box::new(spawn_in_terminal),
});
}
}