aboutsummaryrefslogtreecommitdiff
path: root/helix-dap/src
diff options
context:
space:
mode:
authorDmitry Sharshakov2021-08-15 07:08:51 +0000
committerBlaž Hrastnik2021-08-20 04:43:54 +0000
commit279db98d3cb6c7ee41af81c3e8eb6ef69a1662d0 (patch)
tree37a402c64030bd884a705d77fbe09fd5aa72e164 /helix-dap/src
parent36fb8d1b1ab9f5e0c242e2d167bfaa91f41b7466 (diff)
refactor: use tagged enum for handling DAP payloads
Diffstat (limited to 'helix-dap/src')
-rw-r--r--helix-dap/src/client.rs1
-rw-r--r--helix-dap/src/transport.rs10
2 files changed, 2 insertions, 9 deletions
diff --git a/helix-dap/src/client.rs b/helix-dap/src/client.rs
index c2a8dcc0..8339b953 100644
--- a/helix-dap/src/client.rs
+++ b/helix-dap/src/client.rs
@@ -461,7 +461,6 @@ impl Client {
let req = Request {
back_ch: Some(callback_rx),
seq: self.next_request_id(),
- msg_type: "request".to_owned(),
command,
arguments,
};
diff --git a/helix-dap/src/transport.rs b/helix-dap/src/transport.rs
index cb16e45e..e17dc53d 100644
--- a/helix-dap/src/transport.rs
+++ b/helix-dap/src/transport.rs
@@ -18,8 +18,6 @@ pub struct Request {
#[serde(skip)]
pub back_ch: Option<Sender<Result<Response>>>,
pub seq: u64,
- #[serde(rename = "type")]
- pub msg_type: String,
pub command: String,
pub arguments: Option<Value>,
}
@@ -27,8 +25,6 @@ pub struct Request {
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct Response {
// seq is omitted as unused and is not sent by some implementations
- #[serde(rename = "type")]
- pub msg_type: String,
pub request_seq: u64,
pub success: bool,
pub command: String,
@@ -39,14 +35,12 @@ pub struct Response {
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct Event {
// seq is omitted as unused and is not sent by some implementations
- #[serde(rename = "type")]
- pub msg_type: String,
pub event: String,
pub body: Option<Value>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
-#[serde(untagged)]
+#[serde(tag = "type", rename_all = "camelCase")]
pub enum Payload {
// type = "event"
Event(Event),
@@ -135,7 +129,7 @@ impl Transport {
server_stdin: &mut Box<dyn AsyncWrite + Unpin + Send>,
req: Request,
) -> Result<()> {
- let json = serde_json::to_string(&req)?;
+ let json = serde_json::to_string(&Payload::Request(req.clone()))?;
if let Some(back) = req.back_ch {
self.pending_requests.lock().await.insert(req.seq, back);
}