mirror of https://github.com/helix-editor/helix
refactor server message handling
parent
541f7a0514
commit
9678df1c62
|
@ -167,36 +167,51 @@ impl Transport {
|
||||||
client_tx: &UnboundedSender<Payload>,
|
client_tx: &UnboundedSender<Payload>,
|
||||||
msg: Payload,
|
msg: Payload,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let (id, result) = match msg {
|
match msg {
|
||||||
Payload::Response(Response {
|
Payload::Response(Response {
|
||||||
success: true,
|
ref success,
|
||||||
seq,
|
ref seq,
|
||||||
request_seq,
|
request_seq,
|
||||||
|
ref command,
|
||||||
|
ref message,
|
||||||
|
ref body,
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
info!("<- DAP success ({}, in response to {})", seq, request_seq);
|
let result = match success {
|
||||||
if let Payload::Response(val) = msg {
|
true => {
|
||||||
(request_seq, Ok(val))
|
info!("<- DAP success ({}, in response to {})", seq, request_seq);
|
||||||
} else {
|
if let Payload::Response(val) = msg {
|
||||||
unreachable!();
|
Ok(val)
|
||||||
}
|
} else {
|
||||||
}
|
unreachable!();
|
||||||
Payload::Response(Response {
|
}
|
||||||
success: false,
|
}
|
||||||
message,
|
false => {
|
||||||
body,
|
error!(
|
||||||
request_seq,
|
"<- DAP error {:?} ({:?}) for command #{} {}",
|
||||||
command,
|
message, body, request_seq, command
|
||||||
..
|
);
|
||||||
}) => {
|
|
||||||
error!(
|
Err(Error::Other(anyhow::format_err!("{:?}", body)))
|
||||||
"<- DAP error {:?} ({:?}) for command #{} {}",
|
}
|
||||||
message, body, request_seq, command
|
};
|
||||||
);
|
|
||||||
(
|
let tx = self
|
||||||
request_seq,
|
.pending_requests
|
||||||
Err(Error::Other(anyhow::format_err!("{:?}", body))),
|
.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 {
|
Payload::Request(Request {
|
||||||
ref command,
|
ref command,
|
||||||
|
@ -205,33 +220,16 @@ impl Transport {
|
||||||
}) => {
|
}) => {
|
||||||
info!("<- DAP request {} #{}", command, seq);
|
info!("<- DAP request {} #{}", command, seq);
|
||||||
client_tx.send(msg).expect("Failed to send");
|
client_tx.send(msg).expect("Failed to send");
|
||||||
return Ok(());
|
Ok(())
|
||||||
}
|
}
|
||||||
Payload::Event(Event {
|
Payload::Event(Event {
|
||||||
ref event, ref seq, ..
|
ref event, ref seq, ..
|
||||||
}) => {
|
}) => {
|
||||||
info!("<- DAP event {} #{}", event, seq);
|
info!("<- DAP event {} #{}", event, seq);
|
||||||
client_tx.send(msg).expect("Failed to send");
|
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(
|
async fn recv(
|
||||||
|
|
Loading…
Reference in New Issue