on master help sign in
lsp: Move timeouts into client.request
941c34aBlaž Hrastnik
Cargo.lock+1
@@ -527,6 +527,7 @@ dependencies = [
527 "serde_json",
527 "serde_json",
528 "shellexpand",
528 "shellexpand",
529 "smol",
529 "smol",
530+ "smol-timeout",
530 "thiserror",
531 "thiserror",
531 "url",
532 "url",
532]
533]
helix-lsp/Cargo.toml+1
@@ -13,6 +13,7 @@ once_cell = "1.4"
13
13
14lsp-types = { version = "0.86", features = ["proposed"] }
14lsp-types = { version = "0.86", features = ["proposed"] }
15smol = "1.2"
15smol = "1.2"
16+smol-timeout = "0.6"
16url = "2"
17url = "2"
17pathdiff = "0.2"
18pathdiff = "0.2"
18shellexpand = "2.0"
19shellexpand = "2.0"
helix-lsp/src/client.rs+8−1
@@ -114,7 +114,14 @@ impl Client {
114 .await
114 .await
115 .map_err(|e| Error::Other(e.into()))?;
115 .map_err(|e| Error::Other(e.into()))?;
116
116
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+ }
117− let response = rx.recv().await.map_err(|e| Error::Other(e.into()))??;
124+ .map_err(|e| Error::Other(e.into()))??;
118
125
119 let response = serde_json::from_value(response)?;
126 let response = serde_json::from_value(response)?;
120
127
helix-term/src/commands.rs+4−10
@@ -857,21 +857,15 @@ pub fn completion(cx: &mut Context) {
857 let language_server = cx.language_servers.get("rust", &cx.executor).unwrap();
857 let language_server = cx.language_servers.get("rust", &cx.executor).unwrap();
858 use log::info;
858 use log::info;
859
859
860− use smol_timeout::TimeoutExt;
861− use std::time::Duration;
862−
863 // TODO: blocking here is not ideal
860 // TODO: blocking here is not ideal
864 let pos = helix_lsp::util::pos_to_lsp_pos(
861 let pos = helix_lsp::util::pos_to_lsp_pos(
865 &cx.view.doc.text().slice(..),
862 &cx.view.doc.text().slice(..),
866 cx.view.doc.selection().cursor(),
863 cx.view.doc.selection().cursor(),
867 );
864 );
868− let res = smol::block_on(
865+
869− language_server
866+ // TODO: handle fails
870− .completion(cx.view.doc.identifier(), pos)
867+ let res = smol::block_on(language_server.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
868+ .unwrap_or_default();
875
869
876 // TODO: if no completion, show some message or something
870 // TODO: if no completion, show some message or something
877 if !res.is_empty() {
871 if !res.is_empty() {