diff options
Diffstat (limited to 'crates/ra_lsp_server/tests')
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/main.rs | 12 | ||||
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/support.rs | 17 |
2 files changed, 14 insertions, 15 deletions
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" | |||
32 | use std::collections::Spam; | 32 | use 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() {} | |||
108 | fn test_eggs() {} | 108 | fn 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() { | |||
168 | pub use std::collections::HashMap; | 168 | pub 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; | |||
217 | fn main() {} | 217 | fn 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 | } |