aboutsummaryrefslogtreecommitdiff
path: root/crates/server/tests/heavy_tests/support.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/server/tests/heavy_tests/support.rs')
-rw-r--r--crates/server/tests/heavy_tests/support.rs45
1 files changed, 12 insertions, 33 deletions
diff --git a/crates/server/tests/heavy_tests/support.rs b/crates/server/tests/heavy_tests/support.rs
index 38a9e6c76..99a784e8d 100644
--- a/crates/server/tests/heavy_tests/support.rs
+++ b/crates/server/tests/heavy_tests/support.rs
@@ -14,7 +14,7 @@ use languageserver_types::{
14 Url, 14 Url,
15 TextDocumentIdentifier, 15 TextDocumentIdentifier,
16 request::{Request, Shutdown}, 16 request::{Request, Shutdown},
17 notification::{Notification, DidOpenTextDocument}, 17 notification::DidOpenTextDocument,
18 DidOpenTextDocumentParams, 18 DidOpenTextDocumentParams,
19 TextDocumentItem, 19 TextDocumentItem,
20}; 20};
@@ -22,7 +22,7 @@ use serde::Serialize;
22use serde_json::{Value, from_str, to_string_pretty}; 22use serde_json::{Value, from_str, to_string_pretty};
23use gen_lsp_server::{RawMessage, RawRequest, RawNotification}; 23use gen_lsp_server::{RawMessage, RawRequest, RawNotification};
24 24
25use m::{Result, main_loop}; 25use m::{Result, main_loop, req};
26 26
27pub fn project(fixture: &str) -> Server { 27pub fn project(fixture: &str) -> Server {
28 static INIT: Once = Once::new(); 28 static INIT: Once = Once::new();
@@ -72,7 +72,7 @@ impl Server {
72 let path = dir.path().to_path_buf(); 72 let path = dir.path().to_path_buf();
73 let (client_sender, mut server_receiver) = bounded(1); 73 let (client_sender, mut server_receiver) = bounded(1);
74 let (mut server_sender, client_receiver) = bounded(1); 74 let (mut server_sender, client_receiver) = bounded(1);
75 let server = thread::spawn(move || main_loop(path, &mut server_receiver, &mut server_sender)); 75 let server = thread::spawn(move || main_loop(true, path, &mut server_receiver, &mut server_sender));
76 let res = Server { 76 let res = Server {
77 req_id: Cell::new(1), 77 req_id: Cell::new(1),
78 dir, 78 dir,
@@ -125,25 +125,6 @@ impl Server {
125 ); 125 );
126 } 126 }
127 127
128 pub fn notification<N>(
129 &self,
130 expected: &str,
131 )
132 where
133 N: Notification,
134 {
135 let expected = expected.replace("$PROJECT_ROOT$", &self.dir.path().display().to_string());
136 let expected: Value = from_str(&expected).unwrap();
137 let actual = self.wait_for_notification::<N>();
138 assert_eq!(
139 expected, actual,
140 "Expected:\n{}\n\
141 Actual:\n{}\n",
142 to_string_pretty(&expected).unwrap(),
143 to_string_pretty(&actual).unwrap(),
144 );
145 }
146
147 fn send_request<R>(&self, id: u64, params: R::Params) -> Value 128 fn send_request<R>(&self, id: u64, params: R::Params) -> Value
148 where 129 where
149 R: Request, 130 R: Request,
@@ -173,25 +154,23 @@ impl Server {
173 } 154 }
174 panic!("no response"); 155 panic!("no response");
175 } 156 }
176 pub fn wait_for_notification<N: Notification>(&self) -> Value { 157 pub fn wait_for_feedback(&self, feedback: &str) {
177 self.wait_for_notification_(N::METHOD)
178 }
179 fn wait_for_notification_(&self, method: &str) -> Value {
180 let f = |msg: &RawMessage| match msg { 158 let f = |msg: &RawMessage| match msg {
181 RawMessage::Notification(n) if n.method == method => { 159 RawMessage::Notification(n) if n.method == "internalFeedback" => {
182 Some(n.params.clone()) 160 return n.clone().cast::<req::InternalFeedback>()
161 .unwrap() == feedback
183 } 162 }
184 _ => None, 163 _ => false,
185 }; 164 };
186 165
187 for msg in self.messages.borrow().iter() { 166 for msg in self.messages.borrow().iter() {
188 if let Some(res) = f(msg) { 167 if f(msg) {
189 return res; 168 return;
190 } 169 }
191 } 170 }
192 while let Some(msg) = self.recv() { 171 while let Some(msg) = self.recv() {
193 if let Some(res) = f(&msg) { 172 if f(&msg) {
194 return res; 173 return;
195 } 174 }
196 } 175 }
197 panic!("no response") 176 panic!("no response")