From 87c9f6a52e247c8468e84d54e0ec7d2a92561e3a Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Fri, 1 Aug 2025 11:23:30 -0400 Subject: [PATCH] debugger: Send initialized event from fake server at a more realistic time (cherry-pick #35446) (#35447) Cherry-picked debugger: Send initialized event from fake server at a more realistic time (#35446) The spec says: > :arrow_left: Initialized Event > This event indicates that the debug adapter is ready to accept configuration requests (e.g. setBreakpoints, setExceptionBreakpoints). > > A debug adapter is expected to send this event when it is ready to accept configuration requests (but not before the initialize request has finished). Previously in tests, `intercept_debug_sessions` was just spawning off a background task to send the event after setting up the client, so the event wasn't actually synchronized with the flow of messages in the way the spec says it should be. This PR makes it so that the `FakeTransport` injects the event right after a successful response to the initialize request, and doesn't send it otherwise. Release Notes: - N/A Co-authored-by: Cole Miller --- crates/dap/src/client.rs | 2 +- crates/dap/src/transport.rs | 20 ++++++++++++++++++++ crates/project/src/debugger/test.rs | 10 +--------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/crates/dap/src/client.rs b/crates/dap/src/client.rs index 86a15b2d8a..7b791450ec 100644 --- a/crates/dap/src/client.rs +++ b/crates/dap/src/client.rs @@ -295,7 +295,7 @@ mod tests { request: dap_types::StartDebuggingRequestArgumentsRequest::Launch, }, }, - Box::new(|_| panic!("Did not expect to hit this code path")), + Box::new(|_| {}), &mut cx.to_async(), ) .await diff --git a/crates/dap/src/transport.rs b/crates/dap/src/transport.rs index 6dadf1cf35..f9fbbfc842 100644 --- a/crates/dap/src/transport.rs +++ b/crates/dap/src/transport.rs @@ -883,6 +883,7 @@ impl FakeTransport { break Err(anyhow!("exit in response to request")); } }; + let success = response.success; let message = serde_json::to_string(&Message::Response(response)).unwrap(); @@ -893,6 +894,25 @@ impl FakeTransport { ) .await .unwrap(); + + if request.command == dap_types::requests::Initialize::COMMAND + && success + { + let message = serde_json::to_string(&Message::Event(Box::new( + dap_types::messages::Events::Initialized(Some( + Default::default(), + )), + ))) + .unwrap(); + writer + .write_all( + TransportDelegate::build_rpc_message(message) + .as_bytes(), + ) + .await + .unwrap(); + } + writer.flush().await.unwrap(); } } diff --git a/crates/project/src/debugger/test.rs b/crates/project/src/debugger/test.rs index 3b9425e369..53b88323e6 100644 --- a/crates/project/src/debugger/test.rs +++ b/crates/project/src/debugger/test.rs @@ -1,7 +1,7 @@ use std::{path::Path, sync::Arc}; use dap::client::DebugAdapterClient; -use gpui::{App, AppContext, Subscription}; +use gpui::{App, Subscription}; use super::session::{Session, SessionStateEvent}; @@ -19,14 +19,6 @@ pub fn intercept_debug_sessions) + 'static>( 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();