aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/tests/heavy_tests/support.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/tests/heavy_tests/support.rs')
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/support.rs17
1 files changed, 8 insertions, 9 deletions
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 }