Skip to content

Commit

Permalink
Move DebugAdapter member out of ClientDebugAdapter struct
Browse files Browse the repository at this point in the history
This change was done to make dap::client more in line with zed's lsp::client, it might be reverted depending
on if this solution is cleaner or not.
  • Loading branch information
Anthony-Eid committed Sep 27, 2024
1 parent a3d9cf7 commit 01ffebd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
27 changes: 11 additions & 16 deletions crates/dap/src/client.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -37,7 +36,8 @@ pub struct DebugAdapterClientId(pub usize);

pub struct DebugAdapterClient {
id: DebugAdapterClientId,
adapter: Arc<Box<dyn DebugAdapter>>,
adapter_id: String,
request_args: Value,
transport: Arc<Transport>,
_process: Arc<Mutex<Option<Child>>>,
sequence_count: AtomicU64,
Expand Down Expand Up @@ -70,33 +70,28 @@ impl TransportParams {
impl DebugAdapterClient {
pub async fn new<F>(
id: DebugAdapterClientId,
adapter_id: String,
request_args: Value,
config: DebugAdapterConfig,
adapter: Arc<Box<dyn DebugAdapter>>,
delegate: Box<dyn DapDelegate>,
transport_params: TransportParams,
event_handler: F,
cx: &mut AsyncAppContext,
) -> Result<Arc<Self>>
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,
transport_params.err,
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)),
Expand Down Expand Up @@ -193,12 +188,12 @@ impl DebugAdapterClient {
self.config.clone()
}

pub fn adapter(&self) -> Arc<Box<dyn DebugAdapter>> {
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 {
Expand Down
16 changes: 13 additions & 3 deletions crates/project/src/dap_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down Expand Up @@ -282,7 +292,7 @@ impl DapStore {
.request::<Initialize>(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),
Expand Down

0 comments on commit 01ffebd

Please sign in to comment.