From 1aa11eb7e9a579abd2f47b6be61f983ef2bf2f38 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 7 Mar 2019 17:46:17 +0300 Subject: when loading workspace, say how many packages were loaded this should help to debug configuration issues, when you see `0 packages loaded` or something like that. --- crates/ra_lsp_server/tests/heavy_tests/main.rs | 12 ++++++------ crates/ra_lsp_server/tests/heavy_tests/support.rs | 17 ++++++++--------- 2 files changed, 14 insertions(+), 15 deletions(-) (limited to 'crates/ra_lsp_server/tests') diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index 41c240139..6ae541ec6 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs @@ -32,7 +32,7 @@ version = "0.0.0" use std::collections::Spam; "#, ); - server.wait_for_message("workspace loaded"); + server.wait_until_workspace_is_loaded(); eprintln!("loading took {:?}", project_start.elapsed()); let completion_start = Instant::now(); let res = server.send_request::(CompletionParams { @@ -54,7 +54,7 @@ fn foo() { } ", ); - server.wait_for_message("workspace loaded"); + server.wait_until_workspace_is_loaded(); server.request::( RunnablesParams { text_document: server.doc_id("lib.rs"), position: None }, json!([ @@ -108,7 +108,7 @@ pub fn foo() {} fn test_eggs() {} "#, ); - server.wait_for_message("workspace loaded"); + server.wait_until_workspace_is_loaded(); server.request::( RunnablesParams { text_document: server.doc_id("tests/spam.rs"), @@ -168,7 +168,7 @@ fn main() { pub use std::collections::HashMap; "#, ); - server.wait_for_message("workspace loaded"); + server.wait_until_workspace_is_loaded(); server.request::( DocumentFormattingParams { @@ -217,7 +217,7 @@ mod bar; fn main() {} "#, ); - server.wait_for_message("workspace loaded"); + server.wait_until_workspace_is_loaded(); let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None }; server.request::( CodeActionParams { @@ -279,7 +279,7 @@ fn main() {} PATH = tmp_dir.path().display() ); let server = project_with_tmpdir(tmp_dir, &code); - server.wait_for_message("workspace loaded"); + server.wait_until_workspace_is_loaded(); let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None }; server.request::( CodeActionParams { diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs index e02d7858e..ab9db3dd4 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/support.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs @@ -145,26 +145,25 @@ impl Server { } panic!("no response"); } - pub fn wait_for_message(&self, message: &str) { - self.wait_for_message_n(message, 1) - } - pub fn wait_for_message_n(&self, message: &str, n: usize) { - let f = |msg: &RawMessage| match msg { + pub fn wait_until_workspace_is_loaded(&self) { + self.wait_for_message_cond(1, &|msg: &RawMessage| match msg { RawMessage::Notification(n) if n.method == ShowMessage::METHOD => { let msg = n.clone().cast::().unwrap(); - msg.message == message + msg.message.starts_with("workspace loaded") } _ => false, - }; + }) + } + fn wait_for_message_cond(&self, n: usize, cond: &dyn Fn(&RawMessage) -> bool) { let mut total = 0; for msg in self.messages.borrow().iter() { - if f(msg) { + if cond(msg) { total += 1 } } while total < n { let msg = self.recv().expect("no response"); - if f(&msg) { + if cond(&msg) { total += 1; } } -- cgit v1.2.3