Fix broken tests

- Properly wait for workspace loading to be done
This commit is contained in:
Steffen Lyngbaek 2020-03-13 22:06:49 -07:00
parent f0b58fd1fa
commit 5a1e531176

View File

@ -12,13 +12,14 @@
notification::{DidOpenTextDocument, Exit},
request::Shutdown,
ClientCapabilities, DidOpenTextDocumentParams, GotoCapability, TextDocumentClientCapabilities,
TextDocumentIdentifier, TextDocumentItem, Url,
TextDocumentIdentifier, TextDocumentItem, Url, WorkDoneProgress,
};
use serde::Serialize;
use serde_json::{to_string_pretty, Value};
use tempfile::TempDir;
use test_utils::{find_mismatch, parse_fixture};
use req::{ProgressParams, ProgressParamsValue};
use rust_analyzer::{main_loop, req, ServerConfig};
pub struct Project<'a> {
@ -201,10 +202,14 @@ fn send_request_(&self, r: Request) -> Value {
}
pub fn wait_until_workspace_is_loaded(&self) {
self.wait_for_message_cond(1, &|msg: &Message| match msg {
Message::Notification(n) if n.method == "window/showMessage" => {
let msg =
n.clone().extract::<req::ShowMessageParams>("window/showMessage").unwrap();
msg.message.starts_with("workspace loaded")
Message::Notification(n) if n.method == "$/progress" => {
match n.clone().extract::<ProgressParams>("$/progress").unwrap() {
ProgressParams {
token: req::ProgressToken::String(ref token),
value: ProgressParamsValue::WorkDone(WorkDoneProgress::End(_)),
} if token == "rustAnalyzer/startup" => true,
_ => false,
}
}
_ => false,
})