Skip to content

Make it clearer when the server expects an initialized notification #13915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions lib/lsp-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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}")))
}
};
}
Expand All @@ -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
Expand Down