aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Sharshakov2021-08-13 18:32:39 +0000
committerBlaž Hrastnik2021-08-20 04:43:54 +0000
commit9678df1c62cc3ff7f1efc3800f43f83069d2c6ef (patch)
treef8e29e85e6e05bf65d32cba8bac602931a42072d
parent541f7a051466cd8313b2aad77392c9799c81018b (diff)
refactor server message handling
-rw-r--r--helix-dap/src/transport.rs90
1 files changed, 44 insertions, 46 deletions
diff --git a/helix-dap/src/transport.rs b/helix-dap/src/transport.rs
index 0a40d9fe..5f16df5f 100644
--- a/helix-dap/src/transport.rs
+++ b/helix-dap/src/transport.rs
@@ -167,36 +167,51 @@ impl Transport {
client_tx: &UnboundedSender<Payload>,
msg: Payload,
) -> Result<()> {
- let (id, result) = match msg {
+ match msg {
Payload::Response(Response {
- success: true,
- seq,
- request_seq,
- ..
- }) => {
- info!("<- DAP success ({}, in response to {})", seq, request_seq);
- if let Payload::Response(val) = msg {
- (request_seq, Ok(val))
- } else {
- unreachable!();
- }
- }
- Payload::Response(Response {
- success: false,
- message,
- body,
+ ref success,
+ ref seq,
request_seq,
- command,
+ ref command,
+ ref message,
+ ref body,
..
}) => {
- error!(
- "<- DAP error {:?} ({:?}) for command #{} {}",
- message, body, request_seq, command
- );
- (
- request_seq,
- Err(Error::Other(anyhow::format_err!("{:?}", body))),
- )
+ let result = match success {
+ true => {
+ info!("<- DAP success ({}, in response to {})", seq, request_seq);
+ if let Payload::Response(val) = msg {
+ Ok(val)
+ } else {
+ unreachable!();
+ }
+ }
+ false => {
+ error!(
+ "<- DAP error {:?} ({:?}) for command #{} {}",
+ message, body, request_seq, command
+ );
+
+ Err(Error::Other(anyhow::format_err!("{:?}", body)))
+ }
+ };
+
+ let tx = self
+ .pending_requests
+ .lock()
+ .await
+ .remove(&request_seq)
+ .expect("pending_request with id not found!");
+
+ match tx.send(result).await {
+ Ok(_) => (),
+ Err(_) => error!(
+ "Tried sending response into a closed channel (id={:?}), original request likely timed out",
+ request_seq
+ ),
+ };
+
+ Ok(())
}
Payload::Request(Request {
ref command,
@@ -205,33 +220,16 @@ impl Transport {
}) => {
info!("<- DAP request {} #{}", command, seq);
client_tx.send(msg).expect("Failed to send");
- return Ok(());
+ Ok(())
}
Payload::Event(Event {
ref event, ref seq, ..
}) => {
info!("<- DAP event {} #{}", event, seq);
client_tx.send(msg).expect("Failed to send");
- return Ok(());
+ Ok(())
}
- };
-
- let tx = self
- .pending_requests
- .lock()
- .await
- .remove(&id)
- .expect("pending_request with id not found!");
-
- match tx.send(result).await {
- Ok(_) => (),
- Err(_) => error!(
- "Tried sending response into a closed channel (id={:?}), original request likely timed out",
- id
- ),
- };
-
- Ok(())
+ }
}
async fn recv(