From 23e93919375f07e8f8ee881f2fceb9e556bebeda Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Wed, 15 Feb 2023 17:55:29 -0600 Subject: [PATCH] LSP: Add request ID to request timeout message This improves error logging for requests - without the ID it's hard to know which request is the one that timed out. --- helix-lsp/src/client.rs | 4 ++-- helix-lsp/src/jsonrpc.rs | 10 ++++++++++ helix-lsp/src/lib.rs | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 46772dd22ae0..3f88b3523f80 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -201,7 +201,7 @@ impl Client { let request = jsonrpc::MethodCall { jsonrpc: Some(jsonrpc::Version::V2), - id, + id: id.clone(), method: R::METHOD.to_string(), params: Self::value_into_params(params), }; @@ -218,7 +218,7 @@ impl Client { // TODO: delay other calls until initialize success timeout(Duration::from_secs(timeout_secs), rx.recv()) .await - .map_err(|_| Error::Timeout)? // return Timeout + .map_err(|_| Error::Timeout(id))? // return Timeout .ok_or(Error::StreamClosed)? } } diff --git a/helix-lsp/src/jsonrpc.rs b/helix-lsp/src/jsonrpc.rs index 69d02707e17a..f415dde0be4b 100644 --- a/helix-lsp/src/jsonrpc.rs +++ b/helix-lsp/src/jsonrpc.rs @@ -108,6 +108,16 @@ pub enum Id { Str(String), } +impl std::fmt::Display for Id { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Id::Null => f.write_str("null"), + Id::Num(num) => write!(f, "{}", num), + Id::Str(string) => f.write_str(string), + } + } +} + /// Protocol Version #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] pub enum Version { diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 72456b37571b..341d4a547b35 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -34,8 +34,8 @@ pub enum Error { Parse(#[from] serde_json::Error), #[error("IO Error: {0}")] IO(#[from] std::io::Error), - #[error("request timed out")] - Timeout, + #[error("request {0} timed out")] + Timeout(jsonrpc::Id), #[error("server closed the stream")] StreamClosed, #[error("Unhandled")]