Avoid panic when language server is dropped before being initialized in tests

Co-authored-by: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-05-09 18:05:10 -07:00
parent 45b6a9df36
commit 3dee656490
3 changed files with 16 additions and 7 deletions

View file

@ -647,12 +647,18 @@ impl FakeLanguageServer {
}
pub async fn receive_notification<T: notification::Notification>(&mut self) -> T::Params {
self.try_receive_notification::<T>().await.unwrap()
}
pub async fn try_receive_notification<T: notification::Notification>(
&mut self,
) -> Option<T::Params> {
use futures::StreamExt as _;
loop {
let (method, params) = self.notifications_rx.next().await.unwrap();
let (method, params) = self.notifications_rx.next().await?;
if &method == T::METHOD {
return serde_json::from_str::<T::Params>(&params).unwrap();
return Some(serde_json::from_str::<T::Params>(&params).unwrap());
} else {
log::info!("skipping message in fake language server {:?}", params);
}