on master help sign in
lsp: Handle responses being returned after request timed out.
004a4f3Blaž Hrastnik
helix-lsp/src/client.rs−5
@@ -121,11 +121,6 @@ impl Client {
121
121
122 let response = serde_json::from_value(response)?;
122 let response = serde_json::from_value(response)?;
123
123
124− // TODO: we should pass request to a sender thread via a channel
125− // so it can't be interleaved
126−
127− // TODO: responses can be out of order, we need to register a single shot response channel
128−
129 Ok(response)
124 Ok(response)
130 }
125 }
131
126
helix-lsp/src/transport.rs+19−13
@@ -175,24 +175,30 @@ impl Transport {
175 }
175 }
176
176
177 async fn recv_response(&mut self, output: jsonrpc::Output) -> anyhow::Result<()> {
177 async fn recv_response(&mut self, output: jsonrpc::Output) -> anyhow::Result<()> {
178− match output {
178+ let (id, result) = match output {
179 jsonrpc::Output::Success(jsonrpc::Success { id, result, .. }) => {
179 jsonrpc::Output::Success(jsonrpc::Success { id, result, .. }) => {
180 info!("<- {}", result);
180 info!("<- {}", result);
181−
182− let tx = self
183− .pending_requests
184− .remove(&id)
185− .expect("pending_request with id not found!");
186− tx.send(Ok(result)).await?;
181+ (id, Ok(result))
187 }
182 }
188 jsonrpc::Output::Failure(jsonrpc::Failure { id, error, .. }) => {
183 jsonrpc::Output::Failure(jsonrpc::Failure { id, error, .. }) => {
189− let tx = self
184+ error!("<- {}", error);
190− .pending_requests
191− .remove(&id)
192− .expect("pending_request with id not found!");
193− tx.send(Err(error.into())).await?;
185+ (id, Err(error.into()))
194 }
186 }
195− }
187+ };
188+
189+ let tx = self
190+ .pending_requests
191+ .remove(&id)
192+ .expect("pending_request with id not found!");
193+
194+ match tx.send(result).await {
195+ Ok(_) => (),
196+ Err(_) => error!(
197+ "Tried sending response into a closed channel (id={:?}), original request likely timed out",
198+ id
199+ ),
200+ };
201+
196 Ok(())
202 Ok(())
197 }
203 }
198
204