debugger: Add console indicator and resolve debug configs from NewSessionModal (#28489)

The debug console will now show an indicator when it's unopened and
there's unread messages.

`NewSessionModal` attempts to resolve debug configurations before using
the config to start debugging. This allows users to use zed's task
variables in the modal prompt.

I had to invert tasks_ui dependency on debugger_ui so `NewSessionModal`
could get the correct `TaskContexts` by calling tasks_ui functions. A
consequence of this workspace has a new event `ShowAttachModal` that I'm
not a big fan of. @osiewicz if you have time could you please take a
look to see if there's a way around adding the event. I'm open to pair
on it too.

Release Notes:

- N/A
This commit is contained in:
Anthony Eid 2025-04-10 18:29:03 -04:00 committed by GitHub
parent 66dd6726df
commit cf65d9437a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 204 additions and 82 deletions

View file

@ -14,11 +14,9 @@ path = "src/tasks_ui.rs"
[dependencies]
anyhow.workspace = true
collections.workspace = true
debugger_ui.workspace = true
editor.workspace = true
file_icons.workspace = true
fuzzy.workspace = true
feature_flags.workspace = true
itertools.workspace = true
gpui.workspace = true
menu.workspace = true

View file

@ -128,9 +128,9 @@ impl TasksModalDelegate {
}
}
pub(crate) struct TasksModal {
pub struct TasksModal {
picker: Entity<Picker<TasksModalDelegate>>,
_subscription: Subscription,
_subscription: [Subscription; 2],
}
impl TasksModal {
@ -156,9 +156,16 @@ impl TasksModal {
cx,
)
});
let _subscription = cx.subscribe(&picker, |_, _, _, cx| {
cx.emit(DismissEvent);
});
let _subscription = [
cx.subscribe(&picker, |_, _, _: &DismissEvent, cx| {
cx.emit(DismissEvent);
}),
cx.subscribe(&picker, |_, _, event: &ShowAttachModal, cx| {
cx.emit(ShowAttachModal {
debug_config: event.debug_config.clone(),
});
}),
];
Self {
picker,
_subscription,
@ -179,7 +186,13 @@ impl Render for TasksModal {
}
}
pub struct ShowAttachModal {
pub debug_config: DebugTaskDefinition,
}
impl EventEmitter<DismissEvent> for TasksModal {}
impl EventEmitter<ShowAttachModal> for TasksModal {}
impl EventEmitter<ShowAttachModal> for Picker<TasksModalDelegate> {}
impl Focusable for TasksModal {
fn focus_handle(&self, cx: &gpui::App) -> gpui::FocusHandle {
@ -321,7 +334,7 @@ impl PickerDelegate for TasksModalDelegate {
fn confirm(
&mut self,
omit_history_entry: bool,
window: &mut Window,
_: &mut Window,
cx: &mut Context<picker::Picker<Self>>,
) {
let current_match_index = self.selected_index();
@ -346,51 +359,52 @@ impl PickerDelegate for TasksModalDelegate {
}
}
self.workspace
.update(cx, |workspace, cx| {
match task.task_type() {
TaskType::Debug(config) if config.locator.is_none() => {
let Some(config): Option<DebugTaskDefinition> = task
.resolved_debug_adapter_config()
.and_then(|config| config.try_into().ok())
else {
return;
};
let project = workspace.project().clone();
match task.task_type() {
TaskType::Debug(config) if config.locator.is_none() => {
let Some(config): Option<DebugTaskDefinition> = task
.resolved_debug_adapter_config()
.and_then(|config| config.try_into().ok())
else {
return;
};
match &config.request {
DebugRequestType::Attach(attach_config)
if attach_config.process_id.is_none() =>
{
workspace.toggle_modal(window, cx, |window, cx| {
debugger_ui::attach_modal::AttachModal::new(
project,
config.clone(),
true,
window,
cx,
)
});
}
_ => {
project.update(cx, |project, cx| {
match &config.request {
DebugRequestType::Attach(attach_config)
if attach_config.process_id.is_none() =>
{
cx.emit(ShowAttachModal {
debug_config: config.clone(),
});
return;
}
_ => {
self.workspace
.update(cx, |workspace, cx| {
workspace.project().update(cx, |project, cx| {
project
.start_debug_session(config.into(), cx)
.detach_and_log_err(cx);
});
}
}
})
.ok();
}
_ => schedule_resolved_task(
workspace,
task_source_kind,
task,
omit_history_entry,
cx,
),
};
})
.ok();
}
}
_ => {
self.workspace
.update(cx, |workspace, cx| {
schedule_resolved_task(
workspace,
task_source_kind,
task,
omit_history_entry,
cx,
);
})
.ok();
}
};
cx.emit(DismissEvent);
}

View file

@ -1,11 +1,9 @@
use std::path::Path;
use collections::HashMap;
use debugger_ui::Start;
use editor::Editor;
use feature_flags::{Debugger, FeatureFlagViewExt};
use gpui::{App, AppContext as _, Context, Entity, Task, Window};
use modal::{TaskOverrides, TasksModal};
use modal::TaskOverrides;
use project::{Location, TaskContexts, TaskSourceKind, Worktree};
use task::{
RevealTarget, TaskContext, TaskId, TaskModal, TaskTemplate, TaskVariables, VariableName,
@ -15,11 +13,11 @@ use workspace::{Workspace, tasks::schedule_resolved_task};
mod modal;
pub use modal::{Rerun, Spawn};
pub use modal::{Rerun, ShowAttachModal, Spawn, TasksModal};
pub fn init(cx: &mut App) {
cx.observe_new(
|workspace: &mut Workspace, window: Option<&mut Window>, cx: &mut Context<Workspace>| {
|workspace: &mut Workspace, _: Option<&mut Window>, _: &mut Context<Workspace>| {
workspace
.register_action(spawn_task_or_modal)
.register_action(move |workspace, action: &modal::Rerun, window, cx| {
@ -89,17 +87,6 @@ pub fn init(cx: &mut App) {
toggle_modal(workspace, None, TaskModal::ScriptModal, window, cx).detach();
};
});
let Some(window) = window else {
return;
};
cx.when_flag_enabled::<Debugger>(window, |workspace, _, _| {
workspace.register_action(|workspace: &mut Workspace, _: &Start, window, cx| {
crate::toggle_modal(workspace, None, task::TaskModal::DebugModal, window, cx)
.detach();
});
});
},
)
.detach();
@ -277,7 +264,11 @@ where
})
}
fn task_contexts(workspace: &Workspace, window: &mut Window, cx: &mut App) -> Task<TaskContexts> {
pub fn task_contexts(
workspace: &Workspace,
window: &mut Window,
cx: &mut App,
) -> Task<TaskContexts> {
let active_item = workspace.active_item(cx);
let active_worktree = active_item
.as_ref()