diff options
Diffstat (limited to 'crates/gen_lsp_server')
-rw-r--r-- | crates/gen_lsp_server/src/lib.rs | 15 | ||||
-rw-r--r-- | crates/gen_lsp_server/src/msg.rs | 16 |
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; | |||
15 | use crossbeam_channel::{Sender, Receiver}; | 15 | use crossbeam_channel::{Sender, Receiver}; |
16 | use languageserver_types::{ | 16 | use 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 | ||
51 | pub 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 | |||
51 | fn initialize( | 62 | fn 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 | ||
89 | impl RawRequest { | 89 | impl 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(¶ms).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 | ||
104 | impl RawResponse { | 115 | impl 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()), |