Skip to content

Commit f32e20e

Browse files
committed
Auto merge of #13915 - Veykril:lsp-server-msg, r=Veykril
Make it clearer when the server expects an initialized notification
2 parents fd300ee + 9eb50d3 commit f32e20e

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

lib/lsp-server/src/lib.rs

+8-16
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,8 @@ impl Connection {
114114
/// ```
115115
pub fn initialize_start(&self) -> Result<(RequestId, serde_json::Value), ProtocolError> {
116116
loop {
117-
match self.receiver.recv() {
118-
Ok(Message::Request(req)) if req.is_initialize() => {
119-
return Ok((req.id, req.params))
120-
}
117+
break match self.receiver.recv() {
118+
Ok(Message::Request(req)) if req.is_initialize() => Ok((req.id, req.params)),
121119
// Respond to non-initialize requests with ServerNotInitialized
122120
Ok(Message::Request(req)) => {
123121
let resp = Response::new_err(
@@ -126,14 +124,11 @@ impl Connection {
126124
format!("expected initialize request, got {req:?}"),
127125
);
128126
self.sender.send(resp.into()).unwrap();
127+
continue;
129128
}
130-
Ok(msg) => {
131-
return Err(ProtocolError(format!("expected initialize request, got {msg:?}")))
132-
}
129+
Ok(msg) => Err(ProtocolError(format!("expected initialize request, got {msg:?}"))),
133130
Err(e) => {
134-
return Err(ProtocolError(format!(
135-
"expected initialize request, got error: {e}"
136-
)))
131+
Err(ProtocolError(format!("expected initialize request, got error: {e}")))
137132
}
138133
};
139134
}
@@ -148,17 +143,14 @@ impl Connection {
148143
let resp = Response::new_ok(initialize_id, initialize_result);
149144
self.sender.send(resp.into()).unwrap();
150145
match &self.receiver.recv() {
151-
Ok(Message::Notification(n)) if n.is_initialized() => (),
146+
Ok(Message::Notification(n)) if n.is_initialized() => Ok(()),
152147
Ok(msg) => {
153-
return Err(ProtocolError(format!("expected Message::Notification, got: {msg:?}",)))
148+
Err(ProtocolError(format!(r#"expected initialized notification, got: {msg:?}"#)))
154149
}
155150
Err(e) => {
156-
return Err(ProtocolError(format!(
157-
"expected initialized notification, got error: {e}",
158-
)))
151+
Err(ProtocolError(format!("expected initialized notification, got error: {e}",)))
159152
}
160153
}
161-
Ok(())
162154
}
163155

164156
/// Initialize the connection. Sends the server capabilities

0 commit comments

Comments
 (0)