Skip to content

Commit

Permalink
More WIP with Dap Command trait
Browse files Browse the repository at this point in the history
Co-authored-by: Remco Smits <djsmits12@gmail.com>
  • Loading branch information
Anthony-Eid committed Jan 8, 2025
1 parent 448ffa0 commit d7ce1c3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 25 deletions.
63 changes: 54 additions & 9 deletions crates/project/src/dap_command.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,78 @@
use async_trait::async_trait;
use dap::{requests::Next, NextArguments};
use anyhow::Result;
use dap::{client::DebugAdapterClientId, requests::Next, NextArguments};
use rpc::proto;

pub trait DapCommand: 'static + Sized + Send + std::fmt::Debug {
type Response: 'static + Send + std::fmt::Debug;
type DapRequest: 'static + Send + dap::requests::Request;
type ProtoRequest: 'static + Send + proto::RequestMessage;

fn to_proto(
&self,
debug_client_id: &DebugAdapterClientId,
upstream_project_id: u64,
) -> Self::ProtoRequest;

fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments;

fn response_from_dap(
self,
message: <Self::DapRequest as dap::requests::Request>::Response,
) -> Self::Response;
) -> Result<Self::Response>;

fn response_from_proto(
self,
message: <Self::ProtoRequest as proto::RequestMessage>::Response,
) -> Result<Self::Response>;
}

impl DapCommand for NextArguments {
#[derive(Debug)]
pub(crate) struct NextCommand {
args: NextArguments,
}

impl DapCommand for NextCommand {
type Response = <Next as dap::requests::Request>::Response;
type DapRequest = Next;
type ProtoRequest = proto::PrepareRename;
type ProtoRequest = proto::DapNextRequest;

fn to_proto(
&self,
debug_client_id: &DebugAdapterClientId,
upstream_project_id: u64,
) -> proto::DapNextRequest {
proto::DapNextRequest {
project_id: upstream_project_id,
client_id: debug_client_id.to_proto(),
thread_id: self.args.thread_id,
single_thread: self.args.single_thread,
granularity: Some(match self.args.granularity {
Some(dap::SteppingGranularity::Line) => proto::SteppingGranularity::Line.into(),
Some(dap::SteppingGranularity::Instruction) => {
proto::SteppingGranularity::Instruction.into()
}
Some(dap::SteppingGranularity::Statement) | None => {
proto::SteppingGranularity::Statement.into()
}
}),
}
}

fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments {
todo!()
self.args.clone()
}

fn response_from_dap(
self,
_message: <Self::DapRequest as dap::requests::Request>::Response,
) -> Self::Response {
todo!()
message: <Self::DapRequest as dap::requests::Request>::Response,
) -> Result<Self::Response> {
todo!("")
}

fn response_from_proto(
self,
message: <Self::ProtoRequest as proto::RequestMessage>::Response,
) -> Result<Self::Response> {
todo!("")
}
}
25 changes: 14 additions & 11 deletions crates/project/src/dap_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ impl DapStore {
<R::DapRequest as dap::requests::Request>::Arguments: 'static,
{
if let Some((upstream_client, upstream_project_id)) = self.upstream_client() {
return self._send_proto_client_request::<R>(
return self.send_proto_client_request::<R>(
upstream_client,
upstream_project_id,
client_id,
Expand All @@ -1083,27 +1083,30 @@ impl DapStore {
);
}

let Some(client) = self.client_by_id(client_id, cx) else {
let Some((_, client)) = self.client_by_id(client_id, cx) else {
return Task::ready(Err(anyhow!("Could not find client: {:?}", client_id)));
};

cx.background_executor().spawn(async move {
let args = request.to_dap();
// Ok(request.response_from_dap(client.1.request::<R::DapRequest>(args).await?))
todo!()
request.response_from_dap(client.request::<R::DapRequest>(args).await?)
})
}

// TODO Debugger Collab
fn _send_proto_client_request<R: DapCommand>(
fn send_proto_client_request<R: DapCommand>(
&self,
_upstream_client: AnyProtoClient,
_upstream_project_id: u64,
_client_id: &DebugAdapterClientId,
_request: R,
_cx: &mut ModelContext<Self>,
upstream_client: AnyProtoClient,
upstream_project_id: u64,
client_id: &DebugAdapterClientId,
request: R,
cx: &mut ModelContext<Self>,
) -> Task<Result<R::Response>> {
todo!()
let message = request.to_proto(client_id, upstream_project_id);
cx.background_executor().spawn(async move {
let response = upstream_client.request(message).await?;
request.response_from_proto(response)
})
}

pub fn step_over(
Expand Down
14 changes: 9 additions & 5 deletions crates/proto/proto/zed.proto
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ message Envelope {
SetDebuggerPanelItem set_debugger_panel_item = 294;
UpdateDebugAdapter update_debug_adapter = 295;
ShutdownDebugClient shutdown_debug_client = 296;
SetDebugClientCapabilities set_debug_client_capabilities = 297; // current max
SetDebugClientCapabilities set_debug_client_capabilities = 297;
DapNextRequest dap_next_request = 298; // current max

}

reserved 87 to 88;
Expand Down Expand Up @@ -2596,10 +2598,12 @@ enum SteppingGranularity {
Instruction = 2;
}

message DapNext {
uint64 thread_id = 1;
optional bool single_thread = 2;
optional SteppingGranularity granularity = 3;
message DapNextRequest {
uint64 project_id = 1;
uint64 client_id = 2;
uint64 thread_id = 3;
optional bool single_thread = 4;
optional SteppingGranularity granularity = 5;
}

message DapStackFrame {
Expand Down
3 changes: 3 additions & 0 deletions crates/proto/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ messages!(
(SetDebuggerPanelItem, Background),
(ShutdownDebugClient, Background),
(SetDebugClientCapabilities, Background),
(DapNextRequest, Background),
);

request_messages!(
Expand Down Expand Up @@ -508,6 +509,7 @@ request_messages!(
(SyncExtensions, SyncExtensionsResponse),
(InstallExtension, Ack),
(RegisterBufferWithLanguageServers, Ack),
(DapNextRequest, Ack),
);

entity_messages!(
Expand Down Expand Up @@ -601,6 +603,7 @@ entity_messages!(
SetDebuggerPanelItem,
ShutdownDebugClient,
SetDebugClientCapabilities,
DapNextRequest,
);

entity_messages!(
Expand Down

0 comments on commit d7ce1c3

Please sign in to comment.