From 807cdc60bf060bdbff95c2ab44c4f2ce0cf66e83 Mon Sep 17 00:00:00 2001 From: EmmChriss Date: Wed, 11 May 2022 03:54:35 +0300 Subject: configurable lsp request timeout (#2405) --- helix-core/src/syntax.rs | 6 ++++++ helix-lsp/src/client.rs | 8 ++++++-- helix-lsp/src/lib.rs | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 9208f0e8..b20d9092 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -50,6 +50,10 @@ where Ok(Option::::deserialize(deserializer)?.and_then(AutoPairConfig::into)) } +fn default_timeout() -> u64 { + 20 +} + #[derive(Debug, Serialize, Deserialize)] pub struct Configuration { pub language: Vec, @@ -116,6 +120,8 @@ pub struct LanguageServerConfiguration { #[serde(default)] #[serde(skip_serializing_if = "Vec::is_empty")] pub args: Vec, + #[serde(default = "default_timeout")] + pub timeout: u64, pub language_id: Option, } diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 4bfa2f64..08201b3f 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -35,6 +35,7 @@ pub struct Client { root_path: Option, root_uri: Option, workspace_folders: Vec, + req_timeout: u64, } impl Client { @@ -45,6 +46,7 @@ impl Client { config: Option, root_markers: &[String], id: usize, + req_timeout: u64, ) -> Result<(Self, UnboundedReceiver<(usize, Call)>, Arc)> { // Resolve path to the binary let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?; @@ -97,6 +99,7 @@ impl Client { capabilities: OnceCell::new(), offset_encoding: OffsetEncoding::Utf8, config, + req_timeout, root_path, root_uri, @@ -170,6 +173,7 @@ impl Client { { let server_tx = self.server_tx.clone(); let id = self.next_request_id(); + let timeout_secs = self.req_timeout; async move { use std::time::Duration; @@ -193,8 +197,8 @@ impl Client { }) .map_err(|e| Error::Other(e.into()))?; - // TODO: specifiable timeout, delay other calls until initialize success - timeout(Duration::from_secs(20), rx.recv()) + // TODO: delay other calls until initialize success + timeout(Duration::from_secs(timeout_secs), rx.recv()) .await .map_err(|_| Error::Timeout)? // return Timeout .ok_or(Error::StreamClosed)? diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index aeda16d0..84fb00fe 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -360,6 +360,7 @@ impl Registry { language_config.config.clone(), &language_config.roots, id, + config.timeout, )?; self.incoming.push(UnboundedReceiverStream::new(incoming)); let client = Arc::new(client); -- cgit v1.2.3-70-g09d2