From 72a3722470e5297c72dcaccaf2f113e7b758606d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 30 Aug 2019 17:24:11 +0300 Subject: move lsp-server to a separate repository --- crates/ra_lsp_server/tests/heavy_tests/support.rs | 57 +++++++++++------------ 1 file changed, 28 insertions(+), 29 deletions(-) (limited to 'crates/ra_lsp_server/tests/heavy_tests/support.rs') 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::{ use crossbeam_channel::{after, select, Receiver}; use flexi_logger::Logger; -use gen_lsp_server::{RawMessage, RawNotification, RawRequest}; +use lsp_server::{Message, Notification, Request}; use lsp_types::{ - notification::DidOpenTextDocument, - notification::{Notification, ShowMessage}, - request::{Request, Shutdown}, - ClientCapabilities, DidOpenTextDocumentParams, GotoCapability, TextDocumentClientCapabilities, - TextDocumentIdentifier, TextDocumentItem, Url, + request::Shutdown, ClientCapabilities, DidOpenTextDocumentParams, GotoCapability, + TextDocumentClientCapabilities, TextDocumentIdentifier, TextDocumentItem, Url, }; use serde::Serialize; use serde_json::{to_string_pretty, Value}; @@ -84,9 +81,9 @@ pub fn project(fixture: &str) -> Server { pub struct Server { req_id: Cell, - messages: RefCell>, + messages: RefCell>, dir: TempDir, - worker: Worker, + worker: Worker, } impl Server { @@ -100,7 +97,7 @@ impl Server { let roots = if roots.is_empty() { vec![path] } else { roots }; - let worker = Worker::::spawn( + let worker = Worker::::spawn( "test server", 128, move |msg_receiver, msg_sender| { @@ -128,7 +125,8 @@ impl Server { let res = Server { req_id: Cell::new(1), dir, messages: Default::default(), worker }; for (path, text) in files { - res.send_notification(RawNotification::new::( + res.send_notification(Notification::new( + "textDocument/didOpen".to_string(), &DidOpenTextDocumentParams { text_document: TextDocumentItem { uri: Url::from_file_path(path).unwrap(), @@ -149,16 +147,16 @@ impl Server { pub fn notification(&self, params: N::Params) where - N: Notification, + N: lsp_types::notification::Notification, N::Params: Serialize, { - let r = RawNotification::new::(¶ms); + let r = Notification::new(N::METHOD.to_string(), params); self.send_notification(r) } pub fn request(&self, params: R::Params, expected_resp: Value) where - R: Request, + R: lsp_types::request::Request, R::Params: Serialize, { let actual = self.send_request::(params); @@ -175,23 +173,23 @@ impl Server { pub fn send_request(&self, params: R::Params) -> Value where - R: Request, + R: lsp_types::request::Request, R::Params: Serialize, { let id = self.req_id.get(); self.req_id.set(id + 1); - let r = RawRequest::new::(id, ¶ms); + let r = Request::new(id.into(), R::METHOD.to_string(), params); self.send_request_(r) } - fn send_request_(&self, r: RawRequest) -> Value { - let id = r.id; - self.worker.sender().send(RawMessage::Request(r)).unwrap(); + fn send_request_(&self, r: Request) -> Value { + let id = r.id.clone(); + self.worker.sender().send(r.into()).unwrap(); while let Some(msg) = self.recv() { match msg { - RawMessage::Request(req) => panic!("unexpected request: {:?}", req), - RawMessage::Notification(_) => (), - RawMessage::Response(res) => { + Message::Request(req) => panic!("unexpected request: {:?}", req), + Message::Notification(_) => (), + Message::Response(res) => { assert_eq!(res.id, id); if let Some(err) = res.error { panic!("error response: {:#?}", err); @@ -203,15 +201,16 @@ impl Server { panic!("no response"); } pub fn wait_until_workspace_is_loaded(&self) { - self.wait_for_message_cond(1, &|msg: &RawMessage| match msg { - RawMessage::Notification(n) if n.method == ShowMessage::METHOD => { - let msg = n.clone().cast::().unwrap(); + self.wait_for_message_cond(1, &|msg: &Message| match msg { + Message::Notification(n) if n.method == "window/showMessage" => { + let msg = + n.clone().extract::("window/showMessage").unwrap(); msg.message.starts_with("workspace loaded") } _ => false, }) } - fn wait_for_message_cond(&self, n: usize, cond: &dyn Fn(&RawMessage) -> bool) { + fn wait_for_message_cond(&self, n: usize, cond: &dyn Fn(&Message) -> bool) { let mut total = 0; for msg in self.messages.borrow().iter() { if cond(msg) { @@ -225,14 +224,14 @@ impl Server { } } } - fn recv(&self) -> Option { + fn recv(&self) -> Option { recv_timeout(&self.worker.receiver()).map(|msg| { self.messages.borrow_mut().push(msg.clone()); msg }) } - fn send_notification(&self, not: RawNotification) { - self.worker.sender().send(RawMessage::Notification(not)).unwrap(); + fn send_notification(&self, not: Notification) { + self.worker.sender().send(Message::Notification(not)).unwrap(); } pub fn path(&self) -> &Path { @@ -246,7 +245,7 @@ impl Drop for Server { } } -fn recv_timeout(receiver: &Receiver) -> Option { +fn recv_timeout(receiver: &Receiver) -> Option { let timeout = Duration::from_secs(120); select! { recv(receiver) -> msg => msg.ok(), -- cgit v1.2.3