From 541170420bb6f9a5c0e8d6f56865567fd8ae0f93 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 1 Sep 2018 20:21:11 +0300 Subject: Add an integration test --- crates/gen_lsp_server/src/lib.rs | 15 +++++++++++++-- crates/gen_lsp_server/src/msg.rs | 16 +++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'crates/gen_lsp_server') 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; use crossbeam_channel::{Sender, Receiver}; use languageserver_types::{ ServerCapabilities, InitializeResult, - request::{Initialize}, + request::{Initialize, Shutdown}, notification::{Initialized, Exit}, }; @@ -48,6 +48,17 @@ pub fn run_server( Ok(()) } +pub fn handle_shutdown(req: RawRequest, sender: &Sender) -> Option { + match req.cast::() { + Ok((id, ())) => { + let resp = RawResponse::ok::(id, ()); + sender.send(RawMessage::Response(resp)); + None + } + Err(req) => Some(req), + } +} + fn initialize( receiver: &mut Receiver, sender: &mut Sender, @@ -61,7 +72,7 @@ fn initialize( msg => bail!("expected initialize request, got {:?}", msg), }; - let resp = RawResponse::ok(id, InitializeResult { capabilities: caps }); + let resp = RawResponse::ok::(id, InitializeResult { capabilities: caps }); sender.send(RawMessage::Response(resp)); match receiver.recv() { 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 { } impl RawRequest { + pub fn new(id: u64, params: R::Params) -> RawRequest + where + R: Request, + R::Params: Serialize, + { + RawRequest { + id: id, + method: R::METHOD.to_string(), + params: to_value(¶ms).unwrap(), + } + } pub fn cast(self) -> ::std::result::Result<(u64, R::Params), RawRequest> where R: Request, @@ -102,7 +113,10 @@ impl RawRequest { } impl RawResponse { - pub fn ok(id: u64, result: impl Serialize) -> RawResponse { + pub fn ok(id: u64, result: R::Result) -> RawResponse + where R: Request, + R::Result: Serialize, + { RawResponse { id, result: Some(to_value(&result).unwrap()), -- cgit v1.2.3