use super::*;
#[test]
fn preinit_close_cancels_queued_requests_with_terminal_notes() {
run(async {
let (client, rx, wire) = Wire::new();
let mut docs = Documents::default();
let document = docs.try_insert(()).unwrap();
let path = Path::new("/workspace/a.rs");
assert!(client.did_open(
document,
BufferRevision::new(0),
path,
"rust",
Rope::from_str("x")
));
let wanted = ask(&client, document, 0);
client.did_close(document, path);
let LspEvent::Note { context, .. } = event(&rx).await else {
panic!("note")
};
assert_eq!(context.stamp, wanted);
initialize(&client);
assert!(matches!(rx.try_recv(), Err(TryRecvError::Empty)));
wire.stop().await;
});
}
#[test]
fn preinit_request_backlog_is_bounded_with_terminal_notes() {
run(async {
let (client, rx, wire) = Wire::new();
let mut docs = Documents::default();
let document = docs.try_insert(()).unwrap();
let path = Path::new("/workspace/a.rs");
assert!(client.did_open(
document,
BufferRevision::new(0),
path,
"rust",
Rope::from_str("x")
));
for _ in 0..super::super::sync::MAX_PENDING_REQUESTS {
ask(&client, document, 0);
}
assert!(matches!(rx.try_recv(), Err(TryRecvError::Empty)));
let overflow = ask(&client, document, 0);
let LspEvent::Note { context, text } = event(&rx).await else {
panic!("overflow request gets a terminal note")
};
assert_eq!(context.stamp, overflow);
assert!(
text.contains("too many requests pending server startup"),
"{text}"
);
wire.stop().await;
});
}
#[test]
fn startup_notifications_do_not_kill_the_client() {
run(async {
let (client, rx, mut wire) = Wire::production();
wire.notify(
"window/logMessage",
json!({ "type": 3, "message": "Pyright language server 1.1.411 starting" }),
)
.await;
wire.notify("custom/serverSpecific", json!({ "payload": 1 }))
.await;
wire.notify(
"window/showMessage",
json!({ "type": 2, "message": "a user-facing notice" }),
)
.await;
let LspEvent::ServerMessage { text, .. } = event(&rx).await else {
panic!("showMessage reaches the user")
};
assert_eq!(text, "a user-facing notice");
let mut docs = Documents::default();
let document = docs.try_insert(()).unwrap();
let path = Path::new("/workspace/a.rs");
assert!(client.did_open(
document,
BufferRevision::new(0),
path,
"rust",
Rope::from_str("a😀z")
));
let wanted = ask(&client, document, 0);
initialize(&client);
let _open = wire.next().await;
let request = wire.next().await;
wire.answer(&request, "alive").await;
let LspEvent::HoverText { context, text } = event(&rx).await else {
panic!("hover after startup notifications")
};
assert_eq!(text, "alive");
assert_eq!(context.stamp, wanted);
wire.stop().await;
});
}