diff --git a/crates/gen_lsp_server/src/msg.rs b/crates/gen_lsp_server/src/msg.rs index d2ce20a114..42241194da 100644 --- a/crates/gen_lsp_server/src/msg.rs +++ b/crates/gen_lsp_server/src/msg.rs @@ -9,7 +9,7 @@ use languageserver_types::{ use Result; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] #[serde(untagged)] pub enum RawMessage { Request(RawRequest), @@ -17,14 +17,14 @@ pub enum RawMessage { Response(RawResponse), } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct RawRequest { pub id: u64, pub method: String, pub params: Value, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct RawResponse { // JSON RPC allows this to be null if it was impossible // to decode the request's id. Ignore this special case @@ -36,7 +36,7 @@ pub struct RawResponse { pub error: Option, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct RawResponseError { pub code: i32, pub message: String, @@ -44,6 +44,7 @@ pub struct RawResponseError { pub data: Option, } +#[derive(Clone, Copy, Debug)] #[allow(unused)] pub enum ErrorCode { ParseError = -32700, @@ -58,7 +59,7 @@ pub enum ErrorCode { RequestCancelled = -32800, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct RawNotification { pub method: String, pub params: Value, diff --git a/crates/server/tests/heavy_tests/support.rs b/crates/server/tests/heavy_tests/support.rs index 113ef4c542..36ca56af33 100644 --- a/crates/server/tests/heavy_tests/support.rs +++ b/crates/server/tests/heavy_tests/support.rs @@ -1,7 +1,7 @@ use std::{ fs, thread, - cell::Cell, + cell::{Cell, RefCell}, path::PathBuf, }; @@ -56,6 +56,7 @@ pub fn project(fixture: &str) -> Server { pub struct Server { req_id: Cell, + messages: RefCell>, dir: TempDir, sender: Option>, receiver: Receiver, @@ -71,6 +72,7 @@ impl Server { let res = Server { req_id: Cell::new(1), dir, + messages: Default::default(), sender: Some(client_sender), receiver: client_receiver, server: Some(server), @@ -129,7 +131,7 @@ impl Server { .unwrap() .send(RawMessage::Request(r)); - while let Some(msg) = self.receiver.recv() { + while let Some(msg) = self.recv() { match msg { RawMessage::Request(req) => panic!("unexpected request: {:?}", req), RawMessage::Notification(_) => (), @@ -144,6 +146,13 @@ impl Server { } panic!("no response"); } + fn recv(&self) -> Option { + self.receiver.recv() + .map(|msg| { + self.messages.borrow_mut().push(msg.clone()); + msg + }) + } fn send_notification(&self, not: RawNotification) { self.sender.as_ref()