Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'lib/lsp-server/src/lib.rs')
| -rw-r--r-- | lib/lsp-server/src/lib.rs | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/lib/lsp-server/src/lib.rs b/lib/lsp-server/src/lib.rs index 2797a6b60d..6b732d4702 100644 --- a/lib/lsp-server/src/lib.rs +++ b/lib/lsp-server/src/lib.rs @@ -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 ))), |