1
Fork 0

Make it clearer when the server expects an initialized notification

This commit is contained in:
Lukas Wirth 2023-01-09 17:03:36 +01:00
parent d33fa38cc9
commit 9eb50d3cde

View file

@ -114,10 +114,8 @@ impl Connection {
/// ``` /// ```
pub fn initialize_start(&self) -> Result<(RequestId, serde_json::Value), ProtocolError> { pub fn initialize_start(&self) -> Result<(RequestId, serde_json::Value), ProtocolError> {
loop { loop {
match self.receiver.recv() { break match self.receiver.recv() {
Ok(Message::Request(req)) if req.is_initialize() => { Ok(Message::Request(req)) if req.is_initialize() => Ok((req.id, req.params)),
return Ok((req.id, req.params))
}
// Respond to non-initialize requests with ServerNotInitialized // Respond to non-initialize requests with ServerNotInitialized
Ok(Message::Request(req)) => { Ok(Message::Request(req)) => {
let resp = Response::new_err( let resp = Response::new_err(
@ -126,14 +124,11 @@ impl Connection {
format!("expected initialize request, got {req:?}"), format!("expected initialize request, got {req:?}"),
); );
self.sender.send(resp.into()).unwrap(); self.sender.send(resp.into()).unwrap();
continue;
} }
Ok(msg) => { Ok(msg) => Err(ProtocolError(format!("expected initialize request, got {msg:?}"))),
return Err(ProtocolError(format!("expected initialize request, got {msg:?}")))
}
Err(e) => { Err(e) => {
return Err(ProtocolError(format!( Err(ProtocolError(format!("expected initialize request, got error: {e}")))
"expected initialize request, got error: {e}"
)))
} }
}; };
} }
@ -148,17 +143,14 @@ impl Connection {
let resp = Response::new_ok(initialize_id, initialize_result); let resp = Response::new_ok(initialize_id, initialize_result);
self.sender.send(resp.into()).unwrap(); self.sender.send(resp.into()).unwrap();
match &self.receiver.recv() { match &self.receiver.recv() {
Ok(Message::Notification(n)) if n.is_initialized() => (), Ok(Message::Notification(n)) if n.is_initialized() => Ok(()),
Ok(msg) => { Ok(msg) => {
return Err(ProtocolError(format!("expected Message::Notification, got: {msg:?}",))) Err(ProtocolError(format!(r#"expected initialized notification, got: {msg:?}"#)))
} }
Err(e) => { Err(e) => {
return Err(ProtocolError(format!( Err(ProtocolError(format!("expected initialized notification, got error: {e}",)))
"expected initialized notification, got error: {e}",
)))
} }
} }
Ok(())
} }
/// Initialize the connection. Sends the server capabilities /// Initialize the connection. Sends the server capabilities