aboutsummaryrefslogtreecommitdiff
path: root/crates/gen_lsp_server
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-09-01 18:21:11 +0100
committerAleksey Kladov <[email protected]>2018-09-01 18:21:11 +0100
commit541170420bb6f9a5c0e8d6f56865567fd8ae0f93 (patch)
treea58366d1c9412d3192fc636c7912dcb8514baab3 /crates/gen_lsp_server
parente8515fecd7a42870f2979c7900c94b59d935901c (diff)
Add an integration test
Diffstat (limited to 'crates/gen_lsp_server')
-rw-r--r--crates/gen_lsp_server/src/lib.rs15
-rw-r--r--crates/gen_lsp_server/src/msg.rs16
2 files changed, 28 insertions, 3 deletions
diff --git a/crates/gen_lsp_server/src/lib.rs b/crates/gen_lsp_server/src/lib.rs
index 476c12cc1..0dc24ffc1 100644
--- a/crates/gen_lsp_server/src/lib.rs
+++ b/crates/gen_lsp_server/src/lib.rs
@@ -15,7 +15,7 @@ mod stdio;
15use crossbeam_channel::{Sender, Receiver}; 15use crossbeam_channel::{Sender, Receiver};
16use languageserver_types::{ 16use languageserver_types::{
17 ServerCapabilities, InitializeResult, 17 ServerCapabilities, InitializeResult,
18 request::{Initialize}, 18 request::{Initialize, Shutdown},
19 notification::{Initialized, Exit}, 19 notification::{Initialized, Exit},
20}; 20};
21 21
@@ -48,6 +48,17 @@ pub fn run_server(
48 Ok(()) 48 Ok(())
49} 49}
50 50
51pub fn handle_shutdown(req: RawRequest, sender: &Sender<RawMessage>) -> Option<RawRequest> {
52 match req.cast::<Shutdown>() {
53 Ok((id, ())) => {
54 let resp = RawResponse::ok::<Shutdown>(id, ());
55 sender.send(RawMessage::Response(resp));
56 None
57 }
58 Err(req) => Some(req),
59 }
60}
61
51fn initialize( 62fn initialize(
52 receiver: &mut Receiver<RawMessage>, 63 receiver: &mut Receiver<RawMessage>,
53 sender: &mut Sender<RawMessage>, 64 sender: &mut Sender<RawMessage>,
@@ -61,7 +72,7 @@ fn initialize(
61 msg => 72 msg =>
62 bail!("expected initialize request, got {:?}", msg), 73 bail!("expected initialize request, got {:?}", msg),
63 }; 74 };
64 let resp = RawResponse::ok(id, InitializeResult { capabilities: caps }); 75 let resp = RawResponse::ok::<Initialize>(id, InitializeResult { capabilities: caps });
65 sender.send(RawMessage::Response(resp)); 76 sender.send(RawMessage::Response(resp));
66 match receiver.recv() { 77 match receiver.recv() {
67 Some(RawMessage::Notification(n)) => { 78 Some(RawMessage::Notification(n)) => {
diff --git a/crates/gen_lsp_server/src/msg.rs b/crates/gen_lsp_server/src/msg.rs
index 533d7da3e..d2ce20a11 100644
--- a/crates/gen_lsp_server/src/msg.rs
+++ b/crates/gen_lsp_server/src/msg.rs
@@ -87,6 +87,17 @@ impl RawMessage {
87} 87}
88 88
89impl RawRequest { 89impl RawRequest {
90 pub fn new<R>(id: u64, params: R::Params) -> RawRequest
91 where
92 R: Request,
93 R::Params: Serialize,
94 {
95 RawRequest {
96 id: id,
97 method: R::METHOD.to_string(),
98 params: to_value(&params).unwrap(),
99 }
100 }
90 pub fn cast<R>(self) -> ::std::result::Result<(u64, R::Params), RawRequest> 101 pub fn cast<R>(self) -> ::std::result::Result<(u64, R::Params), RawRequest>
91 where 102 where
92 R: Request, 103 R: Request,
@@ -102,7 +113,10 @@ impl RawRequest {
102} 113}
103 114
104impl RawResponse { 115impl RawResponse {
105 pub fn ok(id: u64, result: impl Serialize) -> RawResponse { 116 pub fn ok<R>(id: u64, result: R::Result) -> RawResponse
117 where R: Request,
118 R::Result: Serialize,
119 {
106 RawResponse { 120 RawResponse {
107 id, 121 id,
108 result: Some(to_value(&result).unwrap()), 122 result: Some(to_value(&result).unwrap()),