aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-09-02 10:34:06 +0100
committerAleksey Kladov <[email protected]>2018-09-02 10:34:06 +0100
commit7fad13de73ded5b8a332c5f50c18671d612bd1e3 (patch)
tree6179708a92b8fbaa8d5fdfa13b2db1f310836bd9
parentd7524556375f2b37e61fe85f17c0e4940e9e4d40 (diff)
store messages in tests
-rw-r--r--crates/gen_lsp_server/src/msg.rs11
-rw-r--r--crates/server/tests/heavy_tests/support.rs13
2 files changed, 17 insertions, 7 deletions
diff --git a/crates/gen_lsp_server/src/msg.rs b/crates/gen_lsp_server/src/msg.rs
index d2ce20a11..42241194d 100644
--- a/crates/gen_lsp_server/src/msg.rs
+++ b/crates/gen_lsp_server/src/msg.rs
@@ -9,7 +9,7 @@ use languageserver_types::{
9 9
10use Result; 10use Result;
11 11
12#[derive(Debug, Serialize, Deserialize)] 12#[derive(Debug, Serialize, Deserialize, Clone)]
13#[serde(untagged)] 13#[serde(untagged)]
14pub enum RawMessage { 14pub enum RawMessage {
15 Request(RawRequest), 15 Request(RawRequest),
@@ -17,14 +17,14 @@ pub enum RawMessage {
17 Response(RawResponse), 17 Response(RawResponse),
18} 18}
19 19
20#[derive(Debug, Serialize, Deserialize)] 20#[derive(Debug, Serialize, Deserialize, Clone)]
21pub struct RawRequest { 21pub struct RawRequest {
22 pub id: u64, 22 pub id: u64,
23 pub method: String, 23 pub method: String,
24 pub params: Value, 24 pub params: Value,
25} 25}
26 26
27#[derive(Debug, Serialize, Deserialize)] 27#[derive(Debug, Serialize, Deserialize, Clone)]
28pub struct RawResponse { 28pub struct RawResponse {
29 // JSON RPC allows this to be null if it was impossible 29 // JSON RPC allows this to be null if it was impossible
30 // to decode the request's id. Ignore this special case 30 // to decode the request's id. Ignore this special case
@@ -36,7 +36,7 @@ pub struct RawResponse {
36 pub error: Option<RawResponseError>, 36 pub error: Option<RawResponseError>,
37} 37}
38 38
39#[derive(Debug, Serialize, Deserialize)] 39#[derive(Debug, Serialize, Deserialize, Clone)]
40pub struct RawResponseError { 40pub struct RawResponseError {
41 pub code: i32, 41 pub code: i32,
42 pub message: String, 42 pub message: String,
@@ -44,6 +44,7 @@ pub struct RawResponseError {
44 pub data: Option<Value>, 44 pub data: Option<Value>,
45} 45}
46 46
47#[derive(Clone, Copy, Debug)]
47#[allow(unused)] 48#[allow(unused)]
48pub enum ErrorCode { 49pub enum ErrorCode {
49 ParseError = -32700, 50 ParseError = -32700,
@@ -58,7 +59,7 @@ pub enum ErrorCode {
58 RequestCancelled = -32800, 59 RequestCancelled = -32800,
59} 60}
60 61
61#[derive(Debug, Serialize, Deserialize)] 62#[derive(Debug, Serialize, Deserialize, Clone)]
62pub struct RawNotification { 63pub struct RawNotification {
63 pub method: String, 64 pub method: String,
64 pub params: Value, 65 pub params: Value,
diff --git a/crates/server/tests/heavy_tests/support.rs b/crates/server/tests/heavy_tests/support.rs
index 113ef4c54..36ca56af3 100644
--- a/crates/server/tests/heavy_tests/support.rs
+++ b/crates/server/tests/heavy_tests/support.rs
@@ -1,7 +1,7 @@
1use std::{ 1use std::{
2 fs, 2 fs,
3 thread, 3 thread,
4 cell::Cell, 4 cell::{Cell, RefCell},
5 path::PathBuf, 5 path::PathBuf,
6}; 6};
7 7
@@ -56,6 +56,7 @@ pub fn project(fixture: &str) -> Server {
56 56
57pub struct Server { 57pub struct Server {
58 req_id: Cell<u64>, 58 req_id: Cell<u64>,
59 messages: RefCell<Vec<RawMessage>>,
59 dir: TempDir, 60 dir: TempDir,
60 sender: Option<Sender<RawMessage>>, 61 sender: Option<Sender<RawMessage>>,
61 receiver: Receiver<RawMessage>, 62 receiver: Receiver<RawMessage>,
@@ -71,6 +72,7 @@ impl Server {
71 let res = Server { 72 let res = Server {
72 req_id: Cell::new(1), 73 req_id: Cell::new(1),
73 dir, 74 dir,
75 messages: Default::default(),
74 sender: Some(client_sender), 76 sender: Some(client_sender),
75 receiver: client_receiver, 77 receiver: client_receiver,
76 server: Some(server), 78 server: Some(server),
@@ -129,7 +131,7 @@ impl Server {
129 .unwrap() 131 .unwrap()
130 .send(RawMessage::Request(r)); 132 .send(RawMessage::Request(r));
131 133
132 while let Some(msg) = self.receiver.recv() { 134 while let Some(msg) = self.recv() {
133 match msg { 135 match msg {
134 RawMessage::Request(req) => panic!("unexpected request: {:?}", req), 136 RawMessage::Request(req) => panic!("unexpected request: {:?}", req),
135 RawMessage::Notification(_) => (), 137 RawMessage::Notification(_) => (),
@@ -144,6 +146,13 @@ impl Server {
144 } 146 }
145 panic!("no response"); 147 panic!("no response");
146 } 148 }
149 fn recv(&self) -> Option<RawMessage> {
150 self.receiver.recv()
151 .map(|msg| {
152 self.messages.borrow_mut().push(msg.clone());
153 msg
154 })
155 }
147 fn send_notification(&self, not: RawNotification) { 156 fn send_notification(&self, not: RawNotification) {
148 157
149 self.sender.as_ref() 158 self.sender.as_ref()