about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2023-01-09 17:03:36 +0100
committerLukas Wirth <lukastw97@gmail.com>2023-01-09 17:03:36 +0100
commit9eb50d3cde97690f8149f560b70f56f6dafa4da3 (patch)
tree9c760e60bbe55dbbc8ca59e51046fd81144d6a49
parentd33fa38cc912c3b184f63290aaf6ebbd3d0a863e (diff)
downloadrust-9eb50d3cde97690f8149f560b70f56f6dafa4da3.tar.gz
rust-9eb50d3cde97690f8149f560b70f56f6dafa4da3.zip
Make it clearer when the server expects an initialized notification
-rw-r--r--lib/lsp-server/src/lib.rs24
1 files changed, 8 insertions, 16 deletions
diff --git a/lib/lsp-server/src/lib.rs b/lib/lsp-server/src/lib.rs
index b95cec4f013..beccde40a89 100644
--- a/lib/lsp-server/src/lib.rs
+++ b/lib/lsp-server/src/lib.rs
@@ -114,10 +114,8 @@ impl Connection {
     /// ```
     pub fn initialize_start(&self) -> Result<(RequestId, serde_json::Value), ProtocolError> {
         loop {
-            match self.receiver.recv() {
-                Ok(Message::Request(req)) if req.is_initialize() => {
-                    return Ok((req.id, req.params))
-                }
+            break match self.receiver.recv() {
+                Ok(Message::Request(req)) if req.is_initialize() => Ok((req.id, req.params)),
                 // Respond to non-initialize requests with ServerNotInitialized
                 Ok(Message::Request(req)) => {
                     let resp = Response::new_err(
@@ -126,14 +124,11 @@ impl Connection {
                         format!("expected initialize request, got {req:?}"),
                     );
                     self.sender.send(resp.into()).unwrap();
+                    continue;
                 }
-                Ok(msg) => {
-                    return Err(ProtocolError(format!("expected initialize request, got {msg:?}")))
-                }
+                Ok(msg) => Err(ProtocolError(format!("expected initialize request, got {msg:?}"))),
                 Err(e) => {
-                    return Err(ProtocolError(format!(
-                        "expected initialize request, got error: {e}"
-                    )))
+                    Err(ProtocolError(format!("expected initialize request, got error: {e}")))
                 }
             };
         }
@@ -148,17 +143,14 @@ impl Connection {
         let resp = Response::new_ok(initialize_id, initialize_result);
         self.sender.send(resp.into()).unwrap();
         match &self.receiver.recv() {
-            Ok(Message::Notification(n)) if n.is_initialized() => (),
+            Ok(Message::Notification(n)) if n.is_initialized() => Ok(()),
             Ok(msg) => {
-                return Err(ProtocolError(format!("expected Message::Notification, got: {msg:?}",)))
+                Err(ProtocolError(format!(r#"expected initialized notification, got: {msg:?}"#)))
             }
             Err(e) => {
-                return Err(ProtocolError(format!(
-                    "expected initialized notification, got error: {e}",
-                )))
+                Err(ProtocolError(format!("expected initialized notification, got error: {e}",)))
             }
         }
-        Ok(())
     }
 
     /// Initialize the connection. Sends the server capabilities