on master help sign in
configurable lsp request timeout (#2405)
commit807cdc60bf060bdbff95c2ab44c4f2ce0cf66e83 authorEmmChriss <42001129+EmmChriss@users.noreply.github.com> dateWed 11 May 2022, 03:54 (4 years ago) parent247ab25
3 files changed+13−2
helix-core/src/syntax.rs+6 helix-lsp/src/client.rs+6−2 helix-lsp/src/lib.rs+1
helix-core/src/syntax.rs+6
@@ -50,6 +50,10 @@ where
5050 Ok(Option::<AutoPairConfig>::deserialize(deserializer)?.and_then(AutoPairConfig::into))
5151}
5252
53+fn default_timeout() -> u64 {
54+ 20
55+}
56+
5357#[derive(Debug, Serialize, Deserialize)]
5458pub struct Configuration {
5559 pub language: Vec<LanguageConfiguration>,
@@ -116,6 +120,8 @@ pub struct LanguageServerConfiguration {
116120 #[serde(default)]
117121 #[serde(skip_serializing_if = "Vec::is_empty")]
118122 pub args: Vec<String>,
123+ #[serde(default = "default_timeout")]
124+ pub timeout: u64,
119125 pub language_id: Option<String>,
120126}
121127
helix-lsp/src/client.rs+6−2
@@ -35,6 +35,7 @@ pub struct Client {
3535 root_path: Option<std::path::PathBuf>,
3636 root_uri: Option<lsp::Url>,
3737 workspace_folders: Vec<lsp::WorkspaceFolder>,
38+ req_timeout: u64,
3839}
3940
4041impl Client {
@@ -45,6 +46,7 @@ impl Client {
4546 config: Option<Value>,
4647 root_markers: &[String],
4748 id: usize,
49+ req_timeout: u64,
4850 ) -> Result<(Self, UnboundedReceiver<(usize, Call)>, Arc<Notify>)> {
4951 // Resolve path to the binary
5052 let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?;
@@ -97,6 +99,7 @@ impl Client {
9799 capabilities: OnceCell::new(),
98100 offset_encoding: OffsetEncoding::Utf8,
99101 config,
102+ req_timeout,
100103
101104 root_path,
102105 root_uri,
@@ -170,6 +173,7 @@ impl Client {
170173 {
171174 let server_tx = self.server_tx.clone();
172175 let id = self.next_request_id();
176+ let timeout_secs = self.req_timeout;
173177
174178 async move {
175179 use std::time::Duration;
@@ -193,8 +197,8 @@ impl Client {
193197 })
194198 .map_err(|e| Error::Other(e.into()))?;
195199
196− // TODO: specifiable timeout, delay other calls until initialize success
197− timeout(Duration::from_secs(20), rx.recv())
200+ // TODO: delay other calls until initialize success
201+ timeout(Duration::from_secs(timeout_secs), rx.recv())
198202 .await
199203 .map_err(|_| Error::Timeout)? // return Timeout
200204 .ok_or(Error::StreamClosed)?
helix-lsp/src/lib.rs+1
@@ -360,6 +360,7 @@ impl Registry {
360360 language_config.config.clone(),
361361 &language_config.roots,
362362 id,
363+ config.timeout,
363364 )?;
364365 self.incoming.push(UnboundedReceiverStream::new(incoming));
365366 let client = Arc::new(client);