on master help sign in
lsp: Move timeouts into client.request
commit941c34a7fc86e613b41887174c699be52ab202a8 authorBlaž Hrastnik <blaz@mxxn.io> dateWed 6 Jan 2021, 17:48 (6 years ago) parentb280048
4 files changed+14−11
Cargo.lock+1 helix-lsp/Cargo.toml+1 helix-lsp/src/client.rs+8−1 helix-term/src/commands.rs+4−10
Cargo.lock+1
@@ -527,6 +527,7 @@ dependencies = [
527527 "serde_json",
528528 "shellexpand",
529529 "smol",
530+ "smol-timeout",
530531 "thiserror",
531532 "url",
532533]
helix-lsp/Cargo.toml+1
@@ -13,6 +13,7 @@ once_cell = "1.4"
1313
1414lsp-types = { version = "0.86", features = ["proposed"] }
1515smol = "1.2"
16+smol-timeout = "0.6"
1617url = "2"
1718pathdiff = "0.2"
1819shellexpand = "2.0"
helix-lsp/src/client.rs+8−1
@@ -114,7 +114,14 @@ impl Client {
114114 .await
115115 .map_err(|e| Error::Other(e.into()))?;
116116
117− let response = rx.recv().await.map_err(|e| Error::Other(e.into()))??;
117+ use smol_timeout::TimeoutExt;
118+ use std::time::Duration;
119+
120+ let response = match rx.recv().timeout(Duration::from_secs(2)).await {
121+ Some(response) => response,
122+ None => return Err(Error::Timeout),
123+ }
124+ .map_err(|e| Error::Other(e.into()))??;
118125
119126 let response = serde_json::from_value(response)?;
120127
helix-term/src/commands.rs+4−10
@@ -857,21 +857,15 @@ pub fn completion(cx: &mut Context) {
857857 let language_server = cx.language_servers.get("rust", &cx.executor).unwrap();
858858 use log::info;
859859
860− use smol_timeout::TimeoutExt;
861− use std::time::Duration;
862−
863860 // TODO: blocking here is not ideal
864861 let pos = helix_lsp::util::pos_to_lsp_pos(
865862 &cx.view.doc.text().slice(..),
866863 cx.view.doc.selection().cursor(),
867864 );
868− let res = smol::block_on(
869− language_server
870− .completion(cx.view.doc.identifier(), pos)
871− .timeout(Duration::from_secs(2)),
872− )
873− .expect("completion failed!")
874− .unwrap_or_default(); // if timeout, just return
865+
866+ // TODO: handle fails
867+ let res = smol::block_on(language_server.completion(cx.view.doc.identifier(), pos))
868+ .unwrap_or_default();
875869
876870 // TODO: if no completion, show some message or something
877871 if !res.is_empty() {