Adjust DAP store to return session from start methods

This commit is contained in:
Piotr Osiewicz
2025-02-18 15:46:16 +01:00
parent 27bda501a1
commit 2ca2942ffa
5 changed files with 32 additions and 54 deletions

View File

@@ -48,16 +48,15 @@ pub struct DebugAdapterClient {
transport_delegate: TransportDelegate,
}
pub type DapMessageHandler = Box<dyn FnMut(Message, &mut App) + 'static + Send + Sync>;
impl DebugAdapterClient {
pub async fn start<F>(
pub async fn start(
id: SessionId,
binary: DebugAdapterBinary,
message_handler: F,
message_handler: DapMessageHandler,
cx: AsyncApp,
) -> Result<Self>
where
F: FnMut(Message, &mut App) + 'static + Send + Sync + Clone,
{
) -> Result<Self> {
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<F>(
async fn handle_receive_messages(
client_id: SessionId,
server_rx: Receiver<Message>,
client_tx: Sender<Message>,
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,

View File

@@ -504,7 +504,7 @@ impl BreakpointStore {
.as_path(),
))
} else {
Some(project_path.clone().path)
Some(project_path.path.clone())
}
}) else {
continue;

View File

@@ -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<Worktree>,
cx: &mut Context<Self>,
) -> Task<Result<Arc<DebugAdapterClient>>> {
) -> Task<Result<Entity<Session>>> {
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(

View File

@@ -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<F>(
fn new(
session_id: SessionId,
breakpoint_store: Entity<BreakpointStore>,
disposition: DebugAdapterConfig,
delegate: DapAdapterDelegate,
message_handler: F,
message_handler: DapMessageHandler,
cx: AsyncApp,
) -> Task<Result<(Self, Capabilities)>>
where
F: FnMut(Message, &mut App) + 'static + Send + Sync + Clone,
{
) -> Task<Result<(Self, Capabilities)>> {
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?;

View File

@@ -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<Self>,
) -> Task<Result<Arc<DebugAdapterClient>>> {
) -> Task<Result<Entity<Session>>> {
let worktree = maybe!({
if let Some(cwd) = &config.cwd {
Some(self.find_worktree(cwd.as_path(), cx)?.0)