debugger: Open debugger panel on session startup (#29186)

Now all debug sessions are routed through the debug panel and are
started synchronously instead of by a task that returns a session once
the initialization process is finished. A session is `Mode::Booting`
while it's starting the debug adapter process and then transitions to
`Mode::Running` once this is completed.

This PR also added new tests for the dap logger, reverse start debugging
request, and debugging over SSH.

Release Notes:

- N/A

---------

Co-authored-by: Anthony Eid <hello@anthonyeid.me>
Co-authored-by: Anthony <anthony@zed.dev>
Co-authored-by: Cole Miller <m@cole-miller.net>
Co-authored-by: Cole Miller <cole@zed.dev>
Co-authored-by: Zed AI <ai@zed.dev>
Co-authored-by: Remco Smits <djsmits12@gmail.com>
This commit is contained in:
Conrad Irwin 2025-04-22 17:35:47 -06:00 committed by GitHub
parent 75ab8ff9a1
commit 6a009b447a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 1261 additions and 1021 deletions

View file

@ -1,68 +1,39 @@
use std::{path::Path, sync::Arc};
use anyhow::Result;
use dap::{DebugRequest, client::DebugAdapterClient};
use gpui::{App, AppContext, Entity, Subscription, Task};
use task::DebugTaskDefinition;
use dap::client::DebugAdapterClient;
use gpui::{App, AppContext, Subscription};
use crate::Project;
use super::session::Session;
use super::session::{Session, SessionStateEvent};
pub fn intercept_debug_sessions<T: Fn(&Arc<DebugAdapterClient>) + 'static>(
cx: &mut gpui::TestAppContext,
configure: T,
) -> Subscription {
cx.update(|cx| {
cx.observe_new::<Session>(move |session, _, cx| {
let client = session.adapter_client().unwrap();
register_default_handlers(session, &client, cx);
configure(&client);
cx.background_spawn(async move {
client
.fake_event(dap::messages::Events::Initialized(Some(Default::default())))
.await
let configure = Arc::new(configure);
cx.observe_new::<Session>(move |_, _, cx| {
let configure = configure.clone();
cx.subscribe_self(move |session, event, cx| {
let configure = configure.clone();
if matches!(event, SessionStateEvent::Running) {
let client = session.adapter_client().unwrap();
register_default_handlers(session, &client, cx);
configure(&client);
cx.background_spawn(async move {
client
.fake_event(dap::messages::Events::Initialized(
Some(Default::default()),
))
.await
})
.detach();
}
})
.detach();
})
})
}
pub fn start_debug_session_with<T: Fn(&Arc<DebugAdapterClient>) + 'static>(
project: &Entity<Project>,
cx: &mut gpui::TestAppContext,
config: DebugTaskDefinition,
configure: T,
) -> Task<Result<Entity<Session>>> {
let subscription = intercept_debug_sessions(cx, configure);
let task = project.update(cx, |project, cx| project.start_debug_session(config, cx));
cx.spawn(async move |_| {
let result = task.await;
drop(subscription);
result
})
}
pub fn start_debug_session<T: Fn(&Arc<DebugAdapterClient>) + 'static>(
project: &Entity<Project>,
cx: &mut gpui::TestAppContext,
configure: T,
) -> Task<Result<Entity<Session>>> {
start_debug_session_with(
project,
cx,
DebugTaskDefinition {
adapter: "fake-adapter".to_string(),
request: DebugRequest::Launch(Default::default()),
label: "test".to_string(),
initialize_args: None,
tcp_connection: None,
stop_on_entry: None,
},
configure,
)
}
fn register_default_handlers(session: &Session, client: &Arc<DebugAdapterClient>, cx: &mut App) {
client.on_request::<dap::requests::Initialize, _>(move |_, _| Ok(Default::default()));
let paths = session