Unify the tasks modal and the new session modal (#31646)

Release Notes:

- Debugger Beta: added a button to the quick action bar to start a debug
session or spawn a task, depending on which of these actions was taken
most recently.
- Debugger Beta: incorporated the tasks modal into the new session modal
as an additional tab.

---------

Co-authored-by: Julia Ryan <juliaryan3.14@gmail.com>
Co-authored-by: Julia Ryan <p1n3appl3@users.noreply.github.com>
Co-authored-by: Anthony Eid <hello@anthonyeid.me>
Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
Cole Miller 2025-05-29 21:33:52 -04:00 committed by GitHub
parent 804de3316e
commit 1445af559b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 434 additions and 224 deletions

View file

@ -23,7 +23,7 @@ use workspace::{ModalView, Workspace};
pub use zed_actions::{Rerun, Spawn};
/// A modal used to spawn new tasks.
pub(crate) struct TasksModalDelegate {
pub struct TasksModalDelegate {
task_store: Entity<TaskStore>,
candidates: Option<Vec<(TaskSourceKind, ResolvedTask)>>,
task_overrides: Option<TaskOverrides>,
@ -33,21 +33,21 @@ pub(crate) struct TasksModalDelegate {
selected_index: usize,
workspace: WeakEntity<Workspace>,
prompt: String,
task_contexts: TaskContexts,
task_contexts: Arc<TaskContexts>,
placeholder_text: Arc<str>,
}
/// Task template amendments to do before resolving the context.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub(crate) struct TaskOverrides {
pub struct TaskOverrides {
/// See [`RevealTarget`].
pub(crate) reveal_target: Option<RevealTarget>,
pub reveal_target: Option<RevealTarget>,
}
impl TasksModalDelegate {
fn new(
task_store: Entity<TaskStore>,
task_contexts: TaskContexts,
task_contexts: Arc<TaskContexts>,
task_overrides: Option<TaskOverrides>,
workspace: WeakEntity<Workspace>,
) -> Self {
@ -123,15 +123,16 @@ impl TasksModalDelegate {
}
pub struct TasksModal {
picker: Entity<Picker<TasksModalDelegate>>,
pub picker: Entity<Picker<TasksModalDelegate>>,
_subscription: [Subscription; 2],
}
impl TasksModal {
pub(crate) fn new(
pub fn new(
task_store: Entity<TaskStore>,
task_contexts: TaskContexts,
task_contexts: Arc<TaskContexts>,
task_overrides: Option<TaskOverrides>,
is_modal: bool,
workspace: WeakEntity<Workspace>,
window: &mut Window,
cx: &mut Context<Self>,
@ -142,6 +143,7 @@ impl TasksModal {
window,
cx,
)
.modal(is_modal)
});
let _subscription = [
cx.subscribe(&picker, |_, _, _: &DismissEvent, cx| {
@ -158,6 +160,20 @@ impl TasksModal {
_subscription,
}
}
pub fn task_contexts_loaded(
&mut self,
task_contexts: Arc<TaskContexts>,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.picker.update(cx, |picker, cx| {
picker.delegate.task_contexts = task_contexts;
picker.delegate.candidates = None;
picker.refresh(window, cx);
cx.notify();
})
}
}
impl Render for TasksModal {
@ -568,6 +584,7 @@ impl PickerDelegate for TasksModalDelegate {
Vec::new()
}
}
fn render_footer(
&self,
window: &mut Window,

View file

@ -1,16 +1,15 @@
use std::path::Path;
use std::{path::Path, sync::Arc};
use collections::HashMap;
use editor::Editor;
use gpui::{App, AppContext as _, Context, Entity, Task, Window};
use modal::TaskOverrides;
use project::{Location, TaskContexts, TaskSourceKind, Worktree};
use task::{RevealTarget, TaskContext, TaskId, TaskTemplate, TaskVariables, VariableName};
use workspace::Workspace;
mod modal;
pub use modal::{Rerun, ShowAttachModal, Spawn, TasksModal};
pub use modal::{Rerun, ShowAttachModal, Spawn, TaskOverrides, TasksModal};
pub fn init(cx: &mut App) {
cx.observe_new(
@ -95,6 +94,11 @@ fn spawn_task_or_modal(
window: &mut Window,
cx: &mut Context<Workspace>,
) {
if let Some(provider) = workspace.debugger_provider() {
provider.spawn_task_or_modal(workspace, action, window, cx);
return;
}
match action {
Spawn::ByName {
task_name,
@ -143,7 +147,7 @@ pub fn toggle_modal(
if can_open_modal {
let task_contexts = task_contexts(workspace, window, cx);
cx.spawn_in(window, async move |workspace, cx| {
let task_contexts = task_contexts.await;
let task_contexts = Arc::new(task_contexts.await);
workspace
.update_in(cx, |workspace, window, cx| {
workspace.toggle_modal(window, cx, |window, cx| {
@ -153,6 +157,7 @@ pub fn toggle_modal(
reveal_target.map(|target| TaskOverrides {
reveal_target: Some(target),
}),
true,
workspace_handle,
window,
cx,
@ -166,7 +171,7 @@ pub fn toggle_modal(
}
}
fn spawn_tasks_filtered<F>(
pub fn spawn_tasks_filtered<F>(
mut predicate: F,
overrides: Option<TaskOverrides>,
window: &mut Window,