Skip to content

Commit 577d0f9

Browse files
improve error handling
1 parent f011c25 commit 577d0f9

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

crates/pg_lsp/src/server.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,23 @@ fn get_client_receiver(
5959
let (message_tx, message_rx) = mpsc::unbounded_channel();
6060

6161
tokio::task::spawn(async move {
62-
// TODO: improve Result handling
6362
loop {
64-
let msg = connection.receiver.recv().unwrap();
63+
let msg = match connection.receiver.recv() {
64+
Ok(msg) => msg,
65+
Err(e) => {
66+
eprint!("Connection was closed by LSP client: {}", e);
67+
cancel_token.cancel();
68+
return;
69+
}
70+
};
6571

6672
match msg {
6773
Message::Request(r) if connection.handle_shutdown(&r).unwrap() => {
6874
cancel_token.cancel();
6975
return;
7076
}
7177

78+
// any non-shutdown request is forwarded to the server
7279
_ => message_tx.send(msg).unwrap(),
7380
};
7481
}

0 commit comments

Comments
 (0)