diff options
author | Blaž Hrastnik | 2021-02-22 03:42:56 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-02-22 03:44:36 +0000 |
commit | 004a4f37a7aadf794ca746f7d9eee4043634cfe2 (patch) | |
tree | 0ecd10b66fdb1f073c33dfd2c50de99e1e70588a /helix-lsp/src | |
parent | 8b9b02f08b5554a4c17e533937c74c1fb80df5f5 (diff) |
lsp: Handle responses being returned after request timed out.
Diffstat (limited to 'helix-lsp/src')
-rw-r--r-- | helix-lsp/src/client.rs | 5 | ||||
-rw-r--r-- | helix-lsp/src/transport.rs | 32 |
2 files changed, 19 insertions, 18 deletions
diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 52cd85c1..1e20e67d 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -121,11 +121,6 @@ impl Client { let response = serde_json::from_value(response)?; - // TODO: we should pass request to a sender thread via a channel - // so it can't be interleaved - - // TODO: responses can be out of order, we need to register a single shot response channel - Ok(response) } diff --git a/helix-lsp/src/transport.rs b/helix-lsp/src/transport.rs index a14bc1f7..74ecde5e 100644 --- a/helix-lsp/src/transport.rs +++ b/helix-lsp/src/transport.rs @@ -175,24 +175,30 @@ impl Transport { } async fn recv_response(&mut self, output: jsonrpc::Output) -> anyhow::Result<()> { - match output { + let (id, result) = match output { jsonrpc::Output::Success(jsonrpc::Success { id, result, .. }) => { info!("<- {}", result); - - let tx = self - .pending_requests - .remove(&id) - .expect("pending_request with id not found!"); - tx.send(Ok(result)).await?; + (id, Ok(result)) } jsonrpc::Output::Failure(jsonrpc::Failure { id, error, .. }) => { - let tx = self - .pending_requests - .remove(&id) - .expect("pending_request with id not found!"); - tx.send(Err(error.into())).await?; + error!("<- {}", error); + (id, Err(error.into())) } - } + }; + + let tx = self + .pending_requests + .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(()) } |