aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-03-07 14:48:37 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-03-07 14:48:37 +0000
commita41d8e140ca65cb87bf6e69a35c3e86410aba374 (patch)
treee349e903732fe18a78a02f9bc98342c540fbec14 /crates/ra_lsp_server
parent5232099977d07492c1b6d5e6163c70d4f6eb07df (diff)
parent1aa11eb7e9a579abd2f47b6be61f983ef2bf2f38 (diff)
Merge #946
946: when loading workspace, say how many packages were loaded r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs14
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/main.rs12
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/support.rs17
3 files changed, 21 insertions, 22 deletions
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(
248 && pending_libraries.is_empty() 248 && pending_libraries.is_empty()
249 && in_flight_libraries == 0 249 && in_flight_libraries == 0
250 { 250 {
251 let n_packages: usize = state.workspaces.iter().map(|it| it.count()).sum();
251 if options.show_workspace_loaded { 252 if options.show_workspace_loaded {
252 show_message(req::MessageType::Info, "workspace loaded", msg_sender); 253 let msg = format!("workspace loaded, {} rust packages", n_packages);
254 show_message(req::MessageType::Info, msg, msg_sender);
253 } 255 }
254 // Only send the notification first time 256 // Only send the notification first time
255 send_workspace_notification = false; 257 send_workspace_notification = false;
@@ -508,12 +510,10 @@ fn update_file_notifications_on_threadpool(
508 }); 510 });
509} 511}
510 512
511fn show_message<M: Into<String>>(typ: req::MessageType, msg: M, sender: &Sender<RawMessage>) { 513fn show_message(typ: req::MessageType, message: impl Into<String>, sender: &Sender<RawMessage>) {
512 let not = RawNotification::new::<req::ShowMessage>(&req::ShowMessageParams { 514 let message = message.into();
513 typ, 515 let params = req::ShowMessageParams { typ, message };
514 message: msg.into(), 516 let not = RawNotification::new::<req::ShowMessage>(&params);
515 });
516
517 sender.send(not.into()).unwrap(); 517 sender.send(not.into()).unwrap();
518} 518}
519 519
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"
32use std::collections::Spam; 32use std::collections::Spam;
33"#, 33"#,
34 ); 34 );
35 server.wait_for_message("workspace loaded"); 35 server.wait_until_workspace_is_loaded();
36 eprintln!("loading took {:?}", project_start.elapsed()); 36 eprintln!("loading took {:?}", project_start.elapsed());
37 let completion_start = Instant::now(); 37 let completion_start = Instant::now();
38 let res = server.send_request::<Completion>(CompletionParams { 38 let res = server.send_request::<Completion>(CompletionParams {
@@ -54,7 +54,7 @@ fn foo() {
54} 54}
55", 55",
56 ); 56 );
57 server.wait_for_message("workspace loaded"); 57 server.wait_until_workspace_is_loaded();
58 server.request::<Runnables>( 58 server.request::<Runnables>(
59 RunnablesParams { text_document: server.doc_id("lib.rs"), position: None }, 59 RunnablesParams { text_document: server.doc_id("lib.rs"), position: None },
60 json!([ 60 json!([
@@ -108,7 +108,7 @@ pub fn foo() {}
108fn test_eggs() {} 108fn test_eggs() {}
109"#, 109"#,
110 ); 110 );
111 server.wait_for_message("workspace loaded"); 111 server.wait_until_workspace_is_loaded();
112 server.request::<Runnables>( 112 server.request::<Runnables>(
113 RunnablesParams { 113 RunnablesParams {
114 text_document: server.doc_id("tests/spam.rs"), 114 text_document: server.doc_id("tests/spam.rs"),
@@ -168,7 +168,7 @@ fn main() {
168pub use std::collections::HashMap; 168pub use std::collections::HashMap;
169"#, 169"#,
170 ); 170 );
171 server.wait_for_message("workspace loaded"); 171 server.wait_until_workspace_is_loaded();
172 172
173 server.request::<Formatting>( 173 server.request::<Formatting>(
174 DocumentFormattingParams { 174 DocumentFormattingParams {
@@ -217,7 +217,7 @@ mod bar;
217fn main() {} 217fn main() {}
218"#, 218"#,
219 ); 219 );
220 server.wait_for_message("workspace loaded"); 220 server.wait_until_workspace_is_loaded();
221 let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None }; 221 let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None };
222 server.request::<CodeActionRequest>( 222 server.request::<CodeActionRequest>(
223 CodeActionParams { 223 CodeActionParams {
@@ -279,7 +279,7 @@ fn main() {}
279 PATH = tmp_dir.path().display() 279 PATH = tmp_dir.path().display()
280 ); 280 );
281 let server = project_with_tmpdir(tmp_dir, &code); 281 let server = project_with_tmpdir(tmp_dir, &code);
282 server.wait_for_message("workspace loaded"); 282 server.wait_until_workspace_is_loaded();
283 let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None }; 283 let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None };
284 server.request::<CodeActionRequest>( 284 server.request::<CodeActionRequest>(
285 CodeActionParams { 285 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 {
145 } 145 }
146 panic!("no response"); 146 panic!("no response");
147 } 147 }
148 pub fn wait_for_message(&self, message: &str) { 148 pub fn wait_until_workspace_is_loaded(&self) {
149 self.wait_for_message_n(message, 1) 149 self.wait_for_message_cond(1, &|msg: &RawMessage| match msg {
150 }
151 pub fn wait_for_message_n(&self, message: &str, n: usize) {
152 let f = |msg: &RawMessage| match msg {
153 RawMessage::Notification(n) if n.method == ShowMessage::METHOD => { 150 RawMessage::Notification(n) if n.method == ShowMessage::METHOD => {
154 let msg = n.clone().cast::<req::ShowMessage>().unwrap(); 151 let msg = n.clone().cast::<req::ShowMessage>().unwrap();
155 msg.message == message 152 msg.message.starts_with("workspace loaded")
156 } 153 }
157 _ => false, 154 _ => false,
158 }; 155 })
156 }
157 fn wait_for_message_cond(&self, n: usize, cond: &dyn Fn(&RawMessage) -> bool) {
159 let mut total = 0; 158 let mut total = 0;
160 for msg in self.messages.borrow().iter() { 159 for msg in self.messages.borrow().iter() {
161 if f(msg) { 160 if cond(msg) {
162 total += 1 161 total += 1
163 } 162 }
164 } 163 }
165 while total < n { 164 while total < n {
166 let msg = self.recv().expect("no response"); 165 let msg = self.recv().expect("no response");
167 if f(&msg) { 166 if cond(&msg) {
168 total += 1; 167 total += 1;
169 } 168 }
170 } 169 }