diff --git a/crates/dap/src/client.rs b/crates/dap/src/client.rs index d46450d221431..ddf987c02dcfb 100644 --- a/crates/dap/src/client.rs +++ b/crates/dap/src/client.rs @@ -1,6 +1,5 @@ use crate::transport::Transport; -use anyhow::{anyhow, Context, Result}; -use crate::adapters::{DapDelegate, DebugAdapter}; +use anyhow::{anyhow, Result}; use dap_types::{ messages::{Message, Response}, requests::Request, @@ -37,7 +36,8 @@ pub struct DebugAdapterClientId(pub usize); pub struct DebugAdapterClient { id: DebugAdapterClientId, - adapter: Arc>, + adapter_id: String, + request_args: Value, transport: Arc, _process: Arc>>, sequence_count: AtomicU64, @@ -70,21 +70,16 @@ impl TransportParams { impl DebugAdapterClient { pub async fn new( id: DebugAdapterClientId, + adapter_id: String, + request_args: Value, config: DebugAdapterConfig, - adapter: Arc>, - delegate: Box, + transport_params: TransportParams, event_handler: F, cx: &mut AsyncAppContext, ) -> Result> where F: FnMut(Message, &mut AppContext) + 'static + Send + Sync + Clone, { - let binary = adapter - .install_or_fetch_binary(delegate) - .await - .context("Failed to get debug adapter binary")?; - let transport_params = adapter.connect(binary, cx).await?; - let transport = Self::handle_transport( transport_params.rx, transport_params.tx, @@ -92,11 +87,11 @@ impl DebugAdapterClient { event_handler, cx, ); - Ok(Arc::new(Self { id, + adapter_id, + request_args, config, - adapter, transport, sequence_count: AtomicU64::new(1), _process: Arc::new(Mutex::new(transport_params.process)), @@ -193,12 +188,12 @@ impl DebugAdapterClient { self.config.clone() } - pub fn adapter(&self) -> Arc> { - self.adapter.clone() + pub fn adapter_id(&self) -> String { + self.adapter_id.clone() } pub fn request_args(&self) -> Value { - self.adapter.request_args() + self.request_args.clone() } pub fn request_type(&self) -> DebugRequestType { diff --git a/crates/project/src/dap_store.rs b/crates/project/src/dap_store.rs index f015d6653092f..c9e66a6f17c53 100644 --- a/crates/project/src/dap_store.rs +++ b/crates/project/src/dap_store.rs @@ -228,11 +228,21 @@ impl DapStore { .context("Creating debug adapter") .log_err()?, ); + let binary = adapter + .install_or_fetch_binary(adapter_delegate) + .await + .context("Failed to get debug adapter binary") + .log_err()?; + let transport_params = adapter.connect(binary, &mut cx).await.log_err()?; + let request_args = adapter.request_args(); + let adapter_id = adapter.id(); + let client = DebugAdapterClient::new( client_id, + adapter_id, + request_args, config, - adapter, - adapter_delegate, + transport_params, move |message, cx| { dap_store .update(cx, |_, cx| { @@ -282,7 +292,7 @@ impl DapStore { .request::(InitializeRequestArguments { client_id: Some("zed".to_owned()), client_name: Some("Zed".to_owned()), - adapter_id: client.adapter().id(), + adapter_id: client.adapter_id(), locale: Some("en-US".to_owned()), path_format: Some(InitializeRequestArgumentsPathFormat::Path), supports_variable_type: Some(true),