diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-08-30 15:24:39 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-08-30 15:24:39 +0100 |
commit | ffc95759c7b538d8dacc336912b62857d4919cdd (patch) | |
tree | 3f0e4056ba2e4b3799b72d71d709783aa6dffc49 /crates/ra_lsp_server/tests | |
parent | 7d72ca80003b7915ed7fc64907b5b6dc5c88dacd (diff) | |
parent | 72a3722470e5297c72dcaccaf2f113e7b758606d (diff) |
Merge #1739
1739: move lsp-server to a separate repository r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/tests')
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/support.rs | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs index 055c8fff2..45b4cacf6 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/support.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs | |||
@@ -8,13 +8,10 @@ use std::{ | |||
8 | 8 | ||
9 | use crossbeam_channel::{after, select, Receiver}; | 9 | use crossbeam_channel::{after, select, Receiver}; |
10 | use flexi_logger::Logger; | 10 | use flexi_logger::Logger; |
11 | use gen_lsp_server::{RawMessage, RawNotification, RawRequest}; | 11 | use lsp_server::{Message, Notification, Request}; |
12 | use lsp_types::{ | 12 | use lsp_types::{ |
13 | notification::DidOpenTextDocument, | 13 | request::Shutdown, ClientCapabilities, DidOpenTextDocumentParams, GotoCapability, |
14 | notification::{Notification, ShowMessage}, | 14 | TextDocumentClientCapabilities, TextDocumentIdentifier, TextDocumentItem, Url, |
15 | request::{Request, Shutdown}, | ||
16 | ClientCapabilities, DidOpenTextDocumentParams, GotoCapability, TextDocumentClientCapabilities, | ||
17 | TextDocumentIdentifier, TextDocumentItem, Url, | ||
18 | }; | 15 | }; |
19 | use serde::Serialize; | 16 | use serde::Serialize; |
20 | use serde_json::{to_string_pretty, Value}; | 17 | use serde_json::{to_string_pretty, Value}; |
@@ -84,9 +81,9 @@ pub fn project(fixture: &str) -> Server { | |||
84 | 81 | ||
85 | pub struct Server { | 82 | pub struct Server { |
86 | req_id: Cell<u64>, | 83 | req_id: Cell<u64>, |
87 | messages: RefCell<Vec<RawMessage>>, | 84 | messages: RefCell<Vec<Message>>, |
88 | dir: TempDir, | 85 | dir: TempDir, |
89 | worker: Worker<RawMessage, RawMessage>, | 86 | worker: Worker<Message, Message>, |
90 | } | 87 | } |
91 | 88 | ||
92 | impl Server { | 89 | impl Server { |
@@ -100,7 +97,7 @@ impl Server { | |||
100 | 97 | ||
101 | let roots = if roots.is_empty() { vec![path] } else { roots }; | 98 | let roots = if roots.is_empty() { vec![path] } else { roots }; |
102 | 99 | ||
103 | let worker = Worker::<RawMessage, RawMessage>::spawn( | 100 | let worker = Worker::<Message, Message>::spawn( |
104 | "test server", | 101 | "test server", |
105 | 128, | 102 | 128, |
106 | move |msg_receiver, msg_sender| { | 103 | move |msg_receiver, msg_sender| { |
@@ -128,7 +125,8 @@ impl Server { | |||
128 | let res = Server { req_id: Cell::new(1), dir, messages: Default::default(), worker }; | 125 | let res = Server { req_id: Cell::new(1), dir, messages: Default::default(), worker }; |
129 | 126 | ||
130 | for (path, text) in files { | 127 | for (path, text) in files { |
131 | res.send_notification(RawNotification::new::<DidOpenTextDocument>( | 128 | res.send_notification(Notification::new( |
129 | "textDocument/didOpen".to_string(), | ||
132 | &DidOpenTextDocumentParams { | 130 | &DidOpenTextDocumentParams { |
133 | text_document: TextDocumentItem { | 131 | text_document: TextDocumentItem { |
134 | uri: Url::from_file_path(path).unwrap(), | 132 | uri: Url::from_file_path(path).unwrap(), |
@@ -149,16 +147,16 @@ impl Server { | |||
149 | 147 | ||
150 | pub fn notification<N>(&self, params: N::Params) | 148 | pub fn notification<N>(&self, params: N::Params) |
151 | where | 149 | where |
152 | N: Notification, | 150 | N: lsp_types::notification::Notification, |
153 | N::Params: Serialize, | 151 | N::Params: Serialize, |
154 | { | 152 | { |
155 | let r = RawNotification::new::<N>(¶ms); | 153 | let r = Notification::new(N::METHOD.to_string(), params); |
156 | self.send_notification(r) | 154 | self.send_notification(r) |
157 | } | 155 | } |
158 | 156 | ||
159 | pub fn request<R>(&self, params: R::Params, expected_resp: Value) | 157 | pub fn request<R>(&self, params: R::Params, expected_resp: Value) |
160 | where | 158 | where |
161 | R: Request, | 159 | R: lsp_types::request::Request, |
162 | R::Params: Serialize, | 160 | R::Params: Serialize, |
163 | { | 161 | { |
164 | let actual = self.send_request::<R>(params); | 162 | let actual = self.send_request::<R>(params); |
@@ -175,23 +173,23 @@ impl Server { | |||
175 | 173 | ||
176 | pub fn send_request<R>(&self, params: R::Params) -> Value | 174 | pub fn send_request<R>(&self, params: R::Params) -> Value |
177 | where | 175 | where |
178 | R: Request, | 176 | R: lsp_types::request::Request, |
179 | R::Params: Serialize, | 177 | R::Params: Serialize, |
180 | { | 178 | { |
181 | let id = self.req_id.get(); | 179 | let id = self.req_id.get(); |
182 | self.req_id.set(id + 1); | 180 | self.req_id.set(id + 1); |
183 | 181 | ||
184 | let r = RawRequest::new::<R>(id, ¶ms); | 182 | let r = Request::new(id.into(), R::METHOD.to_string(), params); |
185 | self.send_request_(r) | 183 | self.send_request_(r) |
186 | } | 184 | } |
187 | fn send_request_(&self, r: RawRequest) -> Value { | 185 | fn send_request_(&self, r: Request) -> Value { |
188 | let id = r.id; | 186 | let id = r.id.clone(); |
189 | self.worker.sender().send(RawMessage::Request(r)).unwrap(); | 187 | self.worker.sender().send(r.into()).unwrap(); |
190 | while let Some(msg) = self.recv() { | 188 | while let Some(msg) = self.recv() { |
191 | match msg { | 189 | match msg { |
192 | RawMessage::Request(req) => panic!("unexpected request: {:?}", req), | 190 | Message::Request(req) => panic!("unexpected request: {:?}", req), |
193 | RawMessage::Notification(_) => (), | 191 | Message::Notification(_) => (), |
194 | RawMessage::Response(res) => { | 192 | Message::Response(res) => { |
195 | assert_eq!(res.id, id); | 193 | assert_eq!(res.id, id); |
196 | if let Some(err) = res.error { | 194 | if let Some(err) = res.error { |
197 | panic!("error response: {:#?}", err); | 195 | panic!("error response: {:#?}", err); |
@@ -203,15 +201,16 @@ impl Server { | |||
203 | panic!("no response"); | 201 | panic!("no response"); |
204 | } | 202 | } |
205 | pub fn wait_until_workspace_is_loaded(&self) { | 203 | pub fn wait_until_workspace_is_loaded(&self) { |
206 | self.wait_for_message_cond(1, &|msg: &RawMessage| match msg { | 204 | self.wait_for_message_cond(1, &|msg: &Message| match msg { |
207 | RawMessage::Notification(n) if n.method == ShowMessage::METHOD => { | 205 | Message::Notification(n) if n.method == "window/showMessage" => { |
208 | let msg = n.clone().cast::<req::ShowMessage>().unwrap(); | 206 | let msg = |
207 | n.clone().extract::<req::ShowMessageParams>("window/showMessage").unwrap(); | ||
209 | msg.message.starts_with("workspace loaded") | 208 | msg.message.starts_with("workspace loaded") |
210 | } | 209 | } |
211 | _ => false, | 210 | _ => false, |
212 | }) | 211 | }) |
213 | } | 212 | } |
214 | fn wait_for_message_cond(&self, n: usize, cond: &dyn Fn(&RawMessage) -> bool) { | 213 | fn wait_for_message_cond(&self, n: usize, cond: &dyn Fn(&Message) -> bool) { |
215 | let mut total = 0; | 214 | let mut total = 0; |
216 | for msg in self.messages.borrow().iter() { | 215 | for msg in self.messages.borrow().iter() { |
217 | if cond(msg) { | 216 | if cond(msg) { |
@@ -225,14 +224,14 @@ impl Server { | |||
225 | } | 224 | } |
226 | } | 225 | } |
227 | } | 226 | } |
228 | fn recv(&self) -> Option<RawMessage> { | 227 | fn recv(&self) -> Option<Message> { |
229 | recv_timeout(&self.worker.receiver()).map(|msg| { | 228 | recv_timeout(&self.worker.receiver()).map(|msg| { |
230 | self.messages.borrow_mut().push(msg.clone()); | 229 | self.messages.borrow_mut().push(msg.clone()); |
231 | msg | 230 | msg |
232 | }) | 231 | }) |
233 | } | 232 | } |
234 | fn send_notification(&self, not: RawNotification) { | 233 | fn send_notification(&self, not: Notification) { |
235 | self.worker.sender().send(RawMessage::Notification(not)).unwrap(); | 234 | self.worker.sender().send(Message::Notification(not)).unwrap(); |
236 | } | 235 | } |
237 | 236 | ||
238 | pub fn path(&self) -> &Path { | 237 | pub fn path(&self) -> &Path { |
@@ -246,7 +245,7 @@ impl Drop for Server { | |||
246 | } | 245 | } |
247 | } | 246 | } |
248 | 247 | ||
249 | fn recv_timeout(receiver: &Receiver<RawMessage>) -> Option<RawMessage> { | 248 | fn recv_timeout(receiver: &Receiver<Message>) -> Option<Message> { |
250 | let timeout = Duration::from_secs(120); | 249 | let timeout = Duration::from_secs(120); |
251 | select! { | 250 | select! { |
252 | recv(receiver) -> msg => msg.ok(), | 251 | recv(receiver) -> msg => msg.ok(), |