mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Expose whether a channel has been dropped in lsp-server errors
This commit is contained in:
parent
06be1b1f34
commit
3c8dd9e89e
9 changed files with 79 additions and 41 deletions
|
@ -17,7 +17,7 @@ use std::{
|
|||
net::{TcpListener, TcpStream, ToSocketAddrs},
|
||||
};
|
||||
|
||||
use crossbeam_channel::{Receiver, RecvTimeoutError, Sender};
|
||||
use crossbeam_channel::{Receiver, RecvError, RecvTimeoutError, Sender};
|
||||
|
||||
pub use crate::{
|
||||
error::{ExtractError, ProtocolError},
|
||||
|
@ -158,11 +158,7 @@ impl Connection {
|
|||
Err(RecvTimeoutError::Timeout) => {
|
||||
continue;
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(ProtocolError(format!(
|
||||
"expected initialize request, got error: {e}"
|
||||
)))
|
||||
}
|
||||
Err(RecvTimeoutError::Disconnected) => return Err(ProtocolError::disconnected()),
|
||||
};
|
||||
|
||||
match msg {
|
||||
|
@ -181,12 +177,14 @@ impl Connection {
|
|||
continue;
|
||||
}
|
||||
msg => {
|
||||
return Err(ProtocolError(format!("expected initialize request, got {msg:?}")));
|
||||
return Err(ProtocolError::new(format!(
|
||||
"expected initialize request, got {msg:?}"
|
||||
)));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return Err(ProtocolError(String::from(
|
||||
return Err(ProtocolError::new(String::from(
|
||||
"Initialization has been aborted during initialization",
|
||||
)));
|
||||
}
|
||||
|
@ -201,12 +199,10 @@ impl Connection {
|
|||
self.sender.send(resp.into()).unwrap();
|
||||
match &self.receiver.recv() {
|
||||
Ok(Message::Notification(n)) if n.is_initialized() => Ok(()),
|
||||
Ok(msg) => {
|
||||
Err(ProtocolError(format!(r#"expected initialized notification, got: {msg:?}"#)))
|
||||
}
|
||||
Err(e) => {
|
||||
Err(ProtocolError(format!("expected initialized notification, got error: {e}",)))
|
||||
}
|
||||
Ok(msg) => Err(ProtocolError::new(format!(
|
||||
r#"expected initialized notification, got: {msg:?}"#
|
||||
))),
|
||||
Err(RecvError) => Err(ProtocolError::disconnected()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,10 +227,8 @@ impl Connection {
|
|||
Err(RecvTimeoutError::Timeout) => {
|
||||
continue;
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(ProtocolError(format!(
|
||||
"expected initialized notification, got error: {e}",
|
||||
)));
|
||||
Err(RecvTimeoutError::Disconnected) => {
|
||||
return Err(ProtocolError::disconnected());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -243,14 +237,14 @@ impl Connection {
|
|||
return Ok(());
|
||||
}
|
||||
msg => {
|
||||
return Err(ProtocolError(format!(
|
||||
return Err(ProtocolError::new(format!(
|
||||
r#"expected initialized notification, got: {msg:?}"#
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Err(ProtocolError(String::from(
|
||||
return Err(ProtocolError::new(String::from(
|
||||
"Initialization has been aborted during initialization",
|
||||
)));
|
||||
}
|
||||
|
@ -359,9 +353,18 @@ impl Connection {
|
|||
match &self.receiver.recv_timeout(std::time::Duration::from_secs(30)) {
|
||||
Ok(Message::Notification(n)) if n.is_exit() => (),
|
||||
Ok(msg) => {
|
||||
return Err(ProtocolError(format!("unexpected message during shutdown: {msg:?}")))
|
||||
return Err(ProtocolError::new(format!(
|
||||
"unexpected message during shutdown: {msg:?}"
|
||||
)))
|
||||
}
|
||||
Err(RecvTimeoutError::Timeout) => {
|
||||
return Err(ProtocolError::new(format!("timed out waiting for exit notification")))
|
||||
}
|
||||
Err(RecvTimeoutError::Disconnected) => {
|
||||
return Err(ProtocolError::new(format!(
|
||||
"channel disconnected waiting for exit notification"
|
||||
)))
|
||||
}
|
||||
Err(e) => return Err(ProtocolError(format!("unexpected error during shutdown: {e}"))),
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
|
@ -426,7 +429,7 @@ mod tests {
|
|||
|
||||
initialize_start_test(TestCase {
|
||||
test_messages: vec![notification_msg.clone()],
|
||||
expected_resp: Err(ProtocolError(format!(
|
||||
expected_resp: Err(ProtocolError::new(format!(
|
||||
"expected initialize request, got {:?}",
|
||||
notification_msg
|
||||
))),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue