diff --git a/crates/dap/src/client.rs b/crates/dap/src/client.rs index 4cf340c2d4..6adb2fd7d4 100644 --- a/crates/dap/src/client.rs +++ b/crates/dap/src/client.rs @@ -48,16 +48,15 @@ pub struct DebugAdapterClient { transport_delegate: TransportDelegate, } +pub type DapMessageHandler = Box; + impl DebugAdapterClient { - pub async fn start( + pub async fn start( id: SessionId, binary: DebugAdapterBinary, - message_handler: F, + message_handler: DapMessageHandler, cx: AsyncApp, - ) -> Result - where - F: FnMut(Message, &mut App) + 'static + Send + Sync + Clone, - { + ) -> Result { let ((server_rx, server_tx), transport_delegate) = TransportDelegate::start(&binary, cx.clone()).await?; let this = Self { @@ -92,16 +91,13 @@ impl DebugAdapterClient { }) } - async fn handle_receive_messages( + async fn handle_receive_messages( client_id: SessionId, server_rx: Receiver, client_tx: Sender, - mut event_handler: F, + mut event_handler: DapMessageHandler, cx: &mut AsyncApp, - ) -> Result<()> - where - F: FnMut(Message, &mut App) + 'static + Send + Sync + Clone, - { + ) -> Result<()> { let result = loop { let message = match server_rx.recv().await { Ok(message) => message, diff --git a/crates/project/src/debugger/breakpoint_store.rs b/crates/project/src/debugger/breakpoint_store.rs index ec7db5e747..d24c1533e0 100644 --- a/crates/project/src/debugger/breakpoint_store.rs +++ b/crates/project/src/debugger/breakpoint_store.rs @@ -504,7 +504,7 @@ impl BreakpointStore { .as_path(), )) } else { - Some(project_path.clone().path) + Some(project_path.path.clone()) } }) else { continue; diff --git a/crates/project/src/debugger/dap_store.rs b/crates/project/src/debugger/dap_store.rs index 24da8c6f38..d039aa0082 100644 --- a/crates/project/src/debugger/dap_store.rs +++ b/crates/project/src/debugger/dap_store.rs @@ -555,9 +555,7 @@ impl DapStore { cx.spawn(|this, mut cx| async move { let adapter = build_adapter(&config.kind).await?; - if !unimplemented!("adapter.supports_attach()") - && matches!(config.request, DebugRequestType::Attach(_)) - { + if !config.supports_attach && matches!(config.request, DebugRequestType::Attach(_)) { bail!("Debug adapter does not support `attach` request"); } @@ -596,7 +594,8 @@ impl DapStore { } }; - let mut client = DebugAdapterClient::start(session_id, binary, |_, _| {}, cx).await?; + let mut client = + DebugAdapterClient::start(session_id, binary, Box::new(|_, _| {}), cx).await?; Ok(Arc::new(client)) }) @@ -607,9 +606,9 @@ impl DapStore { config: DebugAdapterConfig, worktree: &Entity, cx: &mut Context, - ) -> Task>> { + ) -> Task>> { let Some(local_store) = self.as_local() else { - return Task::ready(Err(anyhow!("cannot start session on remote side"))); + unimplemented!("Starting session on remote side"); }; let delegate = DapAdapterDelegate::new( @@ -625,32 +624,13 @@ impl DapStore { }), ); - let start_client_task = self.start_client_internal(delegate, config.clone(), cx); - - cx.spawn(|this, mut cx| async move { - let client = match start_client_task.await { - Ok(client) => client, - Err(error) => { - this.update(&mut cx, |_, cx| { - cx.emit(DapStoreEvent::Notification(error.to_string())); - }) - .log_err(); - - return Err(error); - } - }; - - this.update(&mut cx, |store, cx| { - let session_id = client.id(); - - unimplemented!("store.clients.insert(session_id, client);"); - - cx.emit(DapStoreEvent::DebugClientStarted(session_id)); - cx.notify(); - - client - }) - }) + Session::local( + self.breakpoint_store.clone(), + local_store.next_session_id(), + delegate, + config, + cx, + ) } pub fn configuration_done( diff --git a/crates/project/src/debugger/session.rs b/crates/project/src/debugger/session.rs index b680e20671..4eaaf3d04d 100644 --- a/crates/project/src/debugger/session.rs +++ b/crates/project/src/debugger/session.rs @@ -11,7 +11,7 @@ use super::dap_store::DapAdapterDelegate; use anyhow::{anyhow, Result}; use collections::{HashMap, IndexMap}; use dap::adapters::{DapDelegate, DapStatus, DebugAdapterName}; -use dap::client::{DebugAdapterClient, SessionId}; +use dap::client::{DapMessageHandler, DebugAdapterClient, SessionId}; use dap::{ messages::Message, Capabilities, ContinueArguments, EvaluateArgumentsContext, Module, Source, SteppingGranularity, @@ -160,17 +160,14 @@ struct LocalMode { } impl LocalMode { - fn new( + fn new( session_id: SessionId, breakpoint_store: Entity, disposition: DebugAdapterConfig, delegate: DapAdapterDelegate, - message_handler: F, + message_handler: DapMessageHandler, cx: AsyncApp, - ) -> Task> - where - F: FnMut(Message, &mut App) + 'static + Send + Sync + Clone, - { + ) -> Task> { cx.spawn(move |mut cx| async move { let adapter = build_adapter(&disposition.kind).await?; @@ -221,6 +218,10 @@ impl LocalMode { cx.background_executor().clone(), ) .await?; + let breakpoints = + breakpoint_store.update(&mut cx, |this, cx| this.all_breakpoints(true, cx))?; + + for (path, breakpoints) in breakpoints {} Ok((this, capabilities)) }) } @@ -377,7 +378,7 @@ impl Session { breakpoints, config.clone(), delegate, - |_, _| {}, + Box::new(|_, _| {}), cx.clone(), ) .await?; diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 7211e83d2a..46934203dd 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -50,6 +50,7 @@ use debounced_delay::DebouncedDelay; use debugger::{ breakpoint_store::{BreakpointStore, BreakpointStoreEvent, SerializedBreakpoint}, dap_store::{DapStore, DapStoreEvent}, + session::Session, }; pub use environment::ProjectEnvironment; use futures::{ @@ -1343,7 +1344,7 @@ impl Project { &mut self, config: DebugAdapterConfig, cx: &mut Context, - ) -> Task>> { + ) -> Task>> { let worktree = maybe!({ if let Some(cwd) = &config.cwd { Some(self.find_worktree(cwd.as_path(), cx)?.0)