parent
b3ef934ccb
commit
25242fe93f
395 changed files with 14569 additions and 5755 deletions
|
|
@ -114,30 +114,21 @@ 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(
|
||||
req.id.clone(),
|
||||
ErrorCode::ServerNotInitialized as i32,
|
||||
format!("expected initialize request, got {:?}", req),
|
||||
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}")))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -152,21 +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
|
||||
|
|
@ -221,11 +205,9 @@ impl Connection {
|
|||
match &self.receiver.recv_timeout(std::time::Duration::from_secs(30)) {
|
||||
Ok(Message::Notification(n)) if n.is_exit() => (),
|
||||
Ok(msg) => {
|
||||
return Err(ProtocolError(format!("unexpected message during shutdown: {:?}", msg)))
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(ProtocolError(format!("unexpected error during shutdown: {}", e)))
|
||||
return Err(ProtocolError(format!("unexpected message during shutdown: {msg:?}")))
|
||||
}
|
||||
Err(e) => return Err(ProtocolError(format!("unexpected error during shutdown: {e}"))),
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue