From 43c2b1e5093789f193951121ce0f80b2697a7bfc Mon Sep 17 00:00:00 2001 From: max <36980911+pr2502@users.noreply.github.com> Date: Mon, 11 Mar 2024 14:33:29 +0100 Subject: [PATCH] improve logging --- src/client.rs | 4 ++-- src/instance.rs | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/client.rs b/src/client.rs index c804ccf..cae328e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -414,12 +414,12 @@ async fn output_task( // Drop the message } _ => { - debug!(message = ?res, "unexpected client response"); + debug!(?res, "unexpected client response"); } }, Message::ResponseError(res) => { - warn!(message = ?res, "client response error"); + warn!(?res, "client responded with error"); } Message::Notification(notif) => { diff --git a/src/instance.rs b/src/instance.rs index 9d02c62..8afbec0 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -499,25 +499,34 @@ async fn stdout_task(instance: Arc, mut reader: LspReader { + // Forward successful response to the right client based on the + // Request ID tag. if let (Some(Tag::Port(port)), id) = res.id.untag() { res.id = id; if let Some(client) = clients.get(&port) { let _ = client.send_message(res.into()).await; } else { - debug!(?port, "no client"); + debug!(?port, "no matching client"); } - }; + } else { + warn!(?res, "ignoring improperly tagged server response") + } } Message::ResponseError(mut res) => { + // Forward the error response to the right client based on the + // Request ID tag. if let (Some(Tag::Port(port)), id) = res.id.untag() { + warn!(?res, "server responded with error"); res.id = id; if let Some(client) = clients.get(&port) { let _ = client.send_message(res.into()).await; } else { - debug!(?port, "no client"); + debug!(?port, "no matching client"); } - }; + } else { + warn!(?res, "ignoring improperly tagged server response") + } } Message::Request(mut req) if req.method == "window/workDoneProgress/create" => { @@ -605,11 +614,12 @@ async fn stdout_task(instance: Arc, mut reader: LspReader { - debug!(message = ?req, "server request"); + debug!(message = ?req, "ignoring unknown server request"); } Message::Notification(notif) => { - // Send notifications to all clients + // Server notifications don't expect a response. We can forward + // them to all clients. for client in clients.values() { let _ = client.send_message(notif.clone().into()).await; }