debugger: Fix debug scenario's defined in debug.json not using passed in build task (#29973)

There were two bugs that caused user-defined debug scenarios from being
able to run a build task.

1. DebugRequest would be deserialized to `Attach` even when `process_id`
wasn't defined in a user's configuration file. This has been fixed by
adding our own deserializer that defaults to None if there are no fields
present instead of `Attach`, and I added tests to prevent regressions.
2. Debug scenario resolve phase never got the active buffer when
spawning a debug session from the new session modal. This has been
worked around by passing in the worktree_id of a debug scenario in the
scenario picker and the active worktree_id otherwise.

Release Notes:

- N/A
This commit is contained in:
Anthony Eid 2025-05-06 08:54:57 +02:00 committed by GitHub
parent 52ea501f4f
commit a0bfe4d293
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 97 additions and 12 deletions

View file

@ -237,7 +237,7 @@ impl PickerDelegate for AttachModalDelegate {
.flatten();
if let Some(panel) = panel {
panel.update(cx, |panel, cx| {
panel.start_session(scenario, Default::default(), None, window, cx);
panel.start_session(scenario, Default::default(), None, None, window, cx);
});
}

View file

@ -22,8 +22,8 @@ use gpui::{
};
use language::Buffer;
use project::Fs;
use project::debugger::session::{Session, SessionStateEvent};
use project::{Fs, WorktreeId};
use project::{Project, debugger::session::ThreadStatus};
use rpc::proto::{self};
use settings::Settings;
@ -208,6 +208,7 @@ impl DebugPanel {
scenario: DebugScenario,
task_context: TaskContext,
active_buffer: Option<Entity<Buffer>>,
worktree_id: Option<WorktreeId>,
window: &mut Window,
cx: &mut Context<Self>,
) {
@ -233,6 +234,7 @@ impl DebugPanel {
scenario,
task_context,
active_buffer,
worktree_id,
window,
cx,
)
@ -1283,7 +1285,7 @@ impl workspace::DebuggerProvider for DebuggerProvider {
) {
self.0.update(cx, |_, cx| {
cx.defer_in(window, |this, window, cx| {
this.start_session(definition, context, buffer, window, cx);
this.start_session(definition, context, buffer, None, window, cx);
})
})
}

View file

@ -150,6 +150,7 @@ impl NewSessionModal {
let task_contexts = workspace
.update_in(cx, |this, window, cx| task_contexts(this, window, cx))?
.await;
let worktree_id = task_contexts.worktree();
let task_context = task_contexts
.active_item_context
.map(|(_, _, context)| context)
@ -159,8 +160,9 @@ impl NewSessionModal {
.map(|(_, context)| context)
})
.unwrap_or_default();
debug_panel.update_in(cx, |debug_panel, window, cx| {
debug_panel.start_session(config, task_context, None, window, cx)
debug_panel.start_session(config, task_context, None, worktree_id, window, cx)
})?;
this.update(cx, |_, cx| {
cx.emit(DismissEvent);
@ -937,19 +939,27 @@ impl PickerDelegate for DebugScenarioDelegate {
.await
.task_context_for_worktree_id(worktree_id)
.cloned()
.map(|context| (context, Some(worktree_id)))
})
} else {
gpui::Task::ready(None)
};
cx.spawn_in(window, async move |this, cx| {
let task_context = task_context.await.unwrap_or_default();
let (task_context, worktree_id) = task_context.await.unwrap_or_default();
this.update_in(cx, |this, window, cx| {
this.delegate
.debug_panel
.update(cx, |panel, cx| {
panel.start_session(debug_scenario, task_context, None, window, cx);
panel.start_session(
debug_scenario,
task_context,
None,
worktree_id,
window,
cx,
);
})
.ok();

View file

@ -29,7 +29,7 @@ use language::Buffer;
use loaded_source_list::LoadedSourceList;
use module_list::ModuleList;
use project::{
Project,
Project, WorktreeId,
debugger::session::{Session, SessionEvent, ThreadId, ThreadStatus},
terminals::TerminalKind,
};
@ -684,6 +684,7 @@ impl RunningState {
scenario: DebugScenario,
task_context: TaskContext,
buffer: Option<Entity<Buffer>>,
worktree_id: Option<WorktreeId>,
window: &Window,
cx: &mut Context<Self>,
) -> Task<Result<DebugTaskDefinition>> {
@ -712,7 +713,7 @@ impl RunningState {
this.task_inventory().and_then(|inventory| {
inventory
.read(cx)
.task_template_by_label(buffer, &build, cx)
.task_template_by_label(buffer, worktree_id, &build, cx)
})
})?
else {