on master help sign in
LSP: Add request ID to request timeout message (#6010)

This improves error logging for requests - without the ID it's hard to know which request is the one that timed out.

commit0f64f31d8b89c24910208bc50baa8ce03c00fbf3 authorMichael Davis <mcarsondavis@gmail.com> dateWed 15 Feb 2023, 19:16 (4 years ago) parentd8526a7
3 files changed+14−4
helix-lsp/src/client.rs+2−2 helix-lsp/src/jsonrpc.rs+10 helix-lsp/src/lib.rs+2−2
helix-lsp/src/client.rs+2−2
@@ -201,7 +201,7 @@ impl Client {
201201
202202 let request = jsonrpc::MethodCall {
203203 jsonrpc: Some(jsonrpc::Version::V2),
204− id,
204+ id: id.clone(),
205205 method: R::METHOD.to_string(),
206206 params: Self::value_into_params(params),
207207 };
@@ -218,7 +218,7 @@ impl Client {
218218 // TODO: delay other calls until initialize success
219219 timeout(Duration::from_secs(timeout_secs), rx.recv())
220220 .await
221− .map_err(|_| Error::Timeout)? // return Timeout
221+ .map_err(|_| Error::Timeout(id))? // return Timeout
222222 .ok_or(Error::StreamClosed)?
223223 }
224224 }
helix-lsp/src/jsonrpc.rs+10
@@ -108,6 +108,16 @@ pub enum Id {
108108 Str(String),
109109}
110110
111+impl std::fmt::Display for Id {
112+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
113+ match self {
114+ Id::Null => f.write_str("null"),
115+ Id::Num(num) => write!(f, "{}", num),
116+ Id::Str(string) => f.write_str(string),
117+ }
118+ }
119+}
120+
111121/// Protocol Version
112122#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
113123pub enum Version {
helix-lsp/src/lib.rs+2−2
@@ -34,8 +34,8 @@ pub enum Error {
3434 Parse(#[from] serde_json::Error),
3535 #[error("IO Error: {0}")]
3636 IO(#[from] std::io::Error),
37− #[error("request timed out")]
38− Timeout,
37+ #[error("request {0} timed out")]
38+ Timeout(jsonrpc::Id),
3939 #[error("server closed the stream")]
4040 StreamClosed,
4141 #[error("Unhandled")]