Skip to content

Commit

Permalink
LSP: Add request ID to request timeout message (#6010)
Browse files Browse the repository at this point in the history
This improves error logging for requests - without the ID it's hard to
know which request is the one that timed out.
  • Loading branch information
the-mikedavis authored Feb 16, 2023
1 parent d8526a7 commit 0f64f31
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions helix-lsp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
Expand All @@ -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)?
}
}
Expand Down
10 changes: 10 additions & 0 deletions helix-lsp/src/jsonrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions helix-lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit 0f64f31

Please sign in to comment.