Skip to content

Commit

Permalink
improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
pr2502 committed Mar 11, 2024
1 parent 9f88342 commit 43c2b1e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
22 changes: 16 additions & 6 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,25 +499,34 @@ async fn stdout_task(instance: Arc<Instance>, mut reader: LspReader<BufReader<Ch
let clients = instance.clients.lock().await;
match message {
Message::ResponseSuccess(mut res) => {
// 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" => {
Expand Down Expand Up @@ -605,11 +614,12 @@ async fn stdout_task(instance: Arc<Instance>, mut reader: LspReader<BufReader<Ch
}

Message::Request(req) => {
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;
}
Expand Down

0 comments on commit 43c2b1e

Please sign in to comment.