mirror of
https://github.com/helix-editor/helix.git
synced 2025-01-19 13:37:06 +04:00
refactor: use tagged enum for handling DAP payloads
This commit is contained in:
parent
36fb8d1b1a
commit
279db98d3c
@ -461,7 +461,6 @@ async fn request(
|
|||||||
let req = Request {
|
let req = Request {
|
||||||
back_ch: Some(callback_rx),
|
back_ch: Some(callback_rx),
|
||||||
seq: self.next_request_id(),
|
seq: self.next_request_id(),
|
||||||
msg_type: "request".to_owned(),
|
|
||||||
command,
|
command,
|
||||||
arguments,
|
arguments,
|
||||||
};
|
};
|
||||||
|
@ -18,8 +18,6 @@ pub struct Request {
|
|||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub back_ch: Option<Sender<Result<Response>>>,
|
pub back_ch: Option<Sender<Result<Response>>>,
|
||||||
pub seq: u64,
|
pub seq: u64,
|
||||||
#[serde(rename = "type")]
|
|
||||||
pub msg_type: String,
|
|
||||||
pub command: String,
|
pub command: String,
|
||||||
pub arguments: Option<Value>,
|
pub arguments: Option<Value>,
|
||||||
}
|
}
|
||||||
@ -27,8 +25,6 @@ pub struct Request {
|
|||||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
// seq is omitted as unused and is not sent by some implementations
|
// seq is omitted as unused and is not sent by some implementations
|
||||||
#[serde(rename = "type")]
|
|
||||||
pub msg_type: String,
|
|
||||||
pub request_seq: u64,
|
pub request_seq: u64,
|
||||||
pub success: bool,
|
pub success: bool,
|
||||||
pub command: String,
|
pub command: String,
|
||||||
@ -39,14 +35,12 @@ pub struct Response {
|
|||||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||||
pub struct Event {
|
pub struct Event {
|
||||||
// seq is omitted as unused and is not sent by some implementations
|
// seq is omitted as unused and is not sent by some implementations
|
||||||
#[serde(rename = "type")]
|
|
||||||
pub msg_type: String,
|
|
||||||
pub event: String,
|
pub event: String,
|
||||||
pub body: Option<Value>,
|
pub body: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
#[serde(untagged)]
|
#[serde(tag = "type", rename_all = "camelCase")]
|
||||||
pub enum Payload {
|
pub enum Payload {
|
||||||
// type = "event"
|
// type = "event"
|
||||||
Event(Event),
|
Event(Event),
|
||||||
@ -135,7 +129,7 @@ async fn send_payload_to_server(
|
|||||||
server_stdin: &mut Box<dyn AsyncWrite + Unpin + Send>,
|
server_stdin: &mut Box<dyn AsyncWrite + Unpin + Send>,
|
||||||
req: Request,
|
req: Request,
|
||||||
) -> Result<()> {
|
) -> 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 {
|
if let Some(back) = req.back_ch {
|
||||||
self.pending_requests.lock().await.insert(req.seq, back);
|
self.pending_requests.lock().await.insert(req.seq, back);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user