diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-08-30 18:39:19 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-08-30 18:39:19 +0100 |
commit | f90a88630195a1b6b542b5883295d66dd6c59cef (patch) | |
tree | 9bdd597701e1b150492a78b6c85ff856f0fc51bd /crates/ra_lsp_server/tests | |
parent | ffc95759c7b538d8dacc336912b62857d4919cdd (diff) | |
parent | 983de30a567f2cb4d9e28e12702e509ca713da62 (diff) |
Merge #1740
1740: :arrow_up: lsp-server 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, 29 insertions, 28 deletions
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs index 45b4cacf6..89f65cef4 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/support.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs | |||
@@ -8,16 +8,17 @@ 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 lsp_server::{Message, Notification, Request}; | 11 | use lsp_server::{Connection, Message, Notification, Request}; |
12 | use lsp_types::{ | 12 | use lsp_types::{ |
13 | request::Shutdown, ClientCapabilities, DidOpenTextDocumentParams, GotoCapability, | 13 | notification::{DidOpenTextDocument, Exit}, |
14 | TextDocumentClientCapabilities, TextDocumentIdentifier, TextDocumentItem, Url, | 14 | request::Shutdown, |
15 | ClientCapabilities, DidOpenTextDocumentParams, GotoCapability, TextDocumentClientCapabilities, | ||
16 | TextDocumentIdentifier, TextDocumentItem, Url, | ||
15 | }; | 17 | }; |
16 | use serde::Serialize; | 18 | use serde::Serialize; |
17 | use serde_json::{to_string_pretty, Value}; | 19 | use serde_json::{to_string_pretty, Value}; |
18 | use tempfile::TempDir; | 20 | use tempfile::TempDir; |
19 | use test_utils::{find_mismatch, parse_fixture}; | 21 | use test_utils::{find_mismatch, parse_fixture}; |
20 | use thread_worker::Worker; | ||
21 | 22 | ||
22 | use ra_lsp_server::{main_loop, req, ServerConfig}; | 23 | use ra_lsp_server::{main_loop, req, ServerConfig}; |
23 | 24 | ||
@@ -83,7 +84,8 @@ pub struct Server { | |||
83 | req_id: Cell<u64>, | 84 | req_id: Cell<u64>, |
84 | messages: RefCell<Vec<Message>>, | 85 | messages: RefCell<Vec<Message>>, |
85 | dir: TempDir, | 86 | dir: TempDir, |
86 | worker: Worker<Message, Message>, | 87 | _thread: jod_thread::JoinHandle<()>, |
88 | client: Connection, | ||
87 | } | 89 | } |
88 | 90 | ||
89 | impl Server { | 91 | impl Server { |
@@ -96,11 +98,11 @@ impl Server { | |||
96 | let path = dir.path().to_path_buf(); | 98 | let path = dir.path().to_path_buf(); |
97 | 99 | ||
98 | let roots = if roots.is_empty() { vec![path] } else { roots }; | 100 | let roots = if roots.is_empty() { vec![path] } else { roots }; |
101 | let (connection, client) = Connection::memory(); | ||
99 | 102 | ||
100 | let worker = Worker::<Message, Message>::spawn( | 103 | let _thread = jod_thread::Builder::new() |
101 | "test server", | 104 | .name("test server".to_string()) |
102 | 128, | 105 | .spawn(move || { |
103 | move |msg_receiver, msg_sender| { | ||
104 | main_loop( | 106 | main_loop( |
105 | roots, | 107 | roots, |
106 | ClientCapabilities { | 108 | ClientCapabilities { |
@@ -116,26 +118,24 @@ impl Server { | |||
116 | experimental: None, | 118 | experimental: None, |
117 | }, | 119 | }, |
118 | ServerConfig { with_sysroot, ..ServerConfig::default() }, | 120 | ServerConfig { with_sysroot, ..ServerConfig::default() }, |
119 | &msg_receiver, | 121 | &connection, |
120 | &msg_sender, | ||
121 | ) | 122 | ) |
122 | .unwrap() | 123 | .unwrap() |
123 | }, | 124 | }) |
124 | ); | 125 | .expect("failed to spawn a thread"); |
125 | let res = Server { req_id: Cell::new(1), dir, messages: Default::default(), worker }; | 126 | |
127 | let res = | ||
128 | Server { req_id: Cell::new(1), dir, messages: Default::default(), client, _thread }; | ||
126 | 129 | ||
127 | for (path, text) in files { | 130 | for (path, text) in files { |
128 | res.send_notification(Notification::new( | 131 | res.notification::<DidOpenTextDocument>(DidOpenTextDocumentParams { |
129 | "textDocument/didOpen".to_string(), | 132 | text_document: TextDocumentItem { |
130 | &DidOpenTextDocumentParams { | 133 | uri: Url::from_file_path(path).unwrap(), |
131 | text_document: TextDocumentItem { | 134 | language_id: "rust".to_string(), |
132 | uri: Url::from_file_path(path).unwrap(), | 135 | version: 0, |
133 | language_id: "rust".to_string(), | 136 | text, |
134 | version: 0, | ||
135 | text, | ||
136 | }, | ||
137 | }, | 137 | }, |
138 | )) | 138 | }) |
139 | } | 139 | } |
140 | res | 140 | res |
141 | } | 141 | } |
@@ -184,7 +184,7 @@ impl Server { | |||
184 | } | 184 | } |
185 | fn send_request_(&self, r: Request) -> Value { | 185 | fn send_request_(&self, r: Request) -> Value { |
186 | let id = r.id.clone(); | 186 | let id = r.id.clone(); |
187 | self.worker.sender().send(r.into()).unwrap(); | 187 | self.client.sender.send(r.into()).unwrap(); |
188 | while let Some(msg) = self.recv() { | 188 | while let Some(msg) = self.recv() { |
189 | match msg { | 189 | match msg { |
190 | Message::Request(req) => panic!("unexpected request: {:?}", req), | 190 | Message::Request(req) => panic!("unexpected request: {:?}", req), |
@@ -225,13 +225,13 @@ impl Server { | |||
225 | } | 225 | } |
226 | } | 226 | } |
227 | fn recv(&self) -> Option<Message> { | 227 | fn recv(&self) -> Option<Message> { |
228 | recv_timeout(&self.worker.receiver()).map(|msg| { | 228 | recv_timeout(&self.client.receiver).map(|msg| { |
229 | self.messages.borrow_mut().push(msg.clone()); | 229 | self.messages.borrow_mut().push(msg.clone()); |
230 | msg | 230 | msg |
231 | }) | 231 | }) |
232 | } | 232 | } |
233 | fn send_notification(&self, not: Notification) { | 233 | fn send_notification(&self, not: Notification) { |
234 | self.worker.sender().send(Message::Notification(not)).unwrap(); | 234 | self.client.sender.send(Message::Notification(not)).unwrap(); |
235 | } | 235 | } |
236 | 236 | ||
237 | pub fn path(&self) -> &Path { | 237 | pub fn path(&self) -> &Path { |
@@ -241,7 +241,8 @@ impl Server { | |||
241 | 241 | ||
242 | impl Drop for Server { | 242 | impl Drop for Server { |
243 | fn drop(&mut self) { | 243 | fn drop(&mut self) { |
244 | self.send_request::<Shutdown>(()); | 244 | self.request::<Shutdown>((), Value::Null); |
245 | self.notification::<Exit>(()); | ||
245 | } | 246 | } |
246 | } | 247 | } |
247 | 248 | ||