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/src/main_loop.rs | 14 +++++++------- crates/ra_lsp_server/tests/heavy_tests/main.rs | 12 ++++++------ crates/ra_lsp_server/tests/heavy_tests/support.rs | 17 ++++++++--------- 3 files changed, 21 insertions(+), 22 deletions(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index d0c2a95ef..eecf278a8 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -248,8 +248,10 @@ fn main_loop_inner( && pending_libraries.is_empty() && in_flight_libraries == 0 { + let n_packages: usize = state.workspaces.iter().map(|it| it.count()).sum(); if options.show_workspace_loaded { - show_message(req::MessageType::Info, "workspace loaded", msg_sender); + let msg = format!("workspace loaded, {} rust packages", n_packages); + show_message(req::MessageType::Info, msg, msg_sender); } // Only send the notification first time send_workspace_notification = false; @@ -508,12 +510,10 @@ fn update_file_notifications_on_threadpool( }); } -fn show_message>(typ: req::MessageType, msg: M, sender: &Sender) { - let not = RawNotification::new::(&req::ShowMessageParams { - typ, - message: msg.into(), - }); - +fn show_message(typ: req::MessageType, message: impl Into, sender: &Sender) { + let message = message.into(); + let params = req::ShowMessageParams { typ, message }; + let not = RawNotification::new::(¶ms); sender.send(not.into()).unwrap(); } 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