]> git.lizzy.rs Git - rust.git/commitdiff
Make it clearer when the server expects an initialized notification
authorLukas Wirth <lukastw97@gmail.com>
Mon, 9 Jan 2023 16:03:36 +0000 (17:03 +0100)
committerLukas Wirth <lukastw97@gmail.com>
Mon, 9 Jan 2023 16:03:36 +0000 (17:03 +0100)
lib/lsp-server/src/lib.rs

index b95cec4f013610ca706a7572aea6063eefd26b08..beccde40a89789bd9ebc6253edf512f2f649f8e0 100644 (file)
@@ -114,10 +114,8 @@ pub fn memory() -> (Connection, 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 @@ pub fn initialize_start(&self) -> Result<(RequestId, serde_json::Value), Protoco
                         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 @@ pub fn initialize_finish(
         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