configurable lsp request timeout (#2405)

This commit is contained in:
EmmChriss 2022-05-11 03:54:35 +03:00 committed by GitHub
parent 247ab25bc0
commit 807cdc60bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -50,6 +50,10 @@ pub fn deserialize_auto_pairs<'de, D>(deserializer: D) -> Result<Option<AutoPair
Ok(Option::<AutoPairConfig>::deserialize(deserializer)?.and_then(AutoPairConfig::into))
}
fn default_timeout() -> u64 {
20
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Configuration {
pub language: Vec<LanguageConfiguration>,
@ -116,6 +120,8 @@ pub struct LanguageServerConfiguration {
#[serde(default)]
#[serde(skip_serializing_if = "Vec::is_empty")]
pub args: Vec<String>,
#[serde(default = "default_timeout")]
pub timeout: u64,
pub language_id: Option<String>,
}

View File

@ -35,6 +35,7 @@ pub struct Client {
root_path: Option<std::path::PathBuf>,
root_uri: Option<lsp::Url>,
workspace_folders: Vec<lsp::WorkspaceFolder>,
req_timeout: u64,
}
impl Client {
@ -45,6 +46,7 @@ pub fn start(
config: Option<Value>,
root_markers: &[String],
id: usize,
req_timeout: u64,
) -> Result<(Self, UnboundedReceiver<(usize, Call)>, Arc<Notify>)> {
// Resolve path to the binary
let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?;
@ -97,6 +99,7 @@ pub fn start(
capabilities: OnceCell::new(),
offset_encoding: OffsetEncoding::Utf8,
config,
req_timeout,
root_path,
root_uri,
@ -170,6 +173,7 @@ fn call<R: lsp::request::Request>(
{
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 @@ fn call<R: lsp::request::Request>(
})
.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)?

View File

@ -360,6 +360,7 @@ pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result<Arc<Cli
language_config.config.clone(),
&language_config.roots,
id,
config.timeout,
)?;
self.incoming.push(UnboundedReceiverStream::new(incoming));
let client = Arc::new(client);