diff options
author | Dylan Moonfire <[email protected]> | 2019-05-22 20:45:47 +0100 |
---|---|---|
committer | Dylan R. E. Moonfire <[email protected]> | 2019-05-23 02:35:12 +0100 |
commit | cbd131acbe497795028844a592a438b70a30ba32 (patch) | |
tree | 24719bb7205e95c1b2130238c6927dbfaa8db3e5 /crates/gen_lsp_server/examples/01_gen_lsp_server.rs | |
parent | a25e103e4542637047fe388a926aebddca07b3b7 (diff) |
updated gen_lsp_server examples
- updated the documentation with an example that has no errors with current compiler
- added two example code to test compilation and show in use
Diffstat (limited to 'crates/gen_lsp_server/examples/01_gen_lsp_server.rs')
-rw-r--r-- | crates/gen_lsp_server/examples/01_gen_lsp_server.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/crates/gen_lsp_server/examples/01_gen_lsp_server.rs b/crates/gen_lsp_server/examples/01_gen_lsp_server.rs new file mode 100644 index 000000000..60c581075 --- /dev/null +++ b/crates/gen_lsp_server/examples/01_gen_lsp_server.rs | |||
@@ -0,0 +1,45 @@ | |||
1 | use crossbeam_channel::{Sender, Receiver}; | ||
2 | use lsp_types::{ | ||
3 | ServerCapabilities, InitializeParams, | ||
4 | request::{GotoDefinition, GotoDefinitionResponse}, | ||
5 | }; | ||
6 | use gen_lsp_server::{run_server, stdio_transport, handle_shutdown, RawMessage, RawResponse}; | ||
7 | |||
8 | fn main() -> Result<(), failure::Error> { | ||
9 | let (receiver, sender, io_threads) = stdio_transport(); | ||
10 | run_server(ServerCapabilities::default(), receiver, sender, main_loop)?; | ||
11 | io_threads.join()?; | ||
12 | Ok(()) | ||
13 | } | ||
14 | |||
15 | fn main_loop( | ||
16 | _params: InitializeParams, | ||
17 | receiver: &Receiver<RawMessage>, | ||
18 | sender: &Sender<RawMessage>, | ||
19 | ) -> Result<(), failure::Error> { | ||
20 | for msg in receiver { | ||
21 | match msg { | ||
22 | RawMessage::Request(req) => { | ||
23 | let req = match handle_shutdown(req, sender) { | ||
24 | None => return Ok(()), | ||
25 | Some(req) => req, | ||
26 | }; | ||
27 | match req.cast::<GotoDefinition>() { | ||
28 | Ok((id, _params)) => { | ||
29 | let resp = RawResponse::ok::<GotoDefinition>( | ||
30 | id, | ||
31 | &Some(GotoDefinitionResponse::Array(Vec::new())), | ||
32 | ); | ||
33 | sender.send(RawMessage::Response(resp))?; | ||
34 | continue; | ||
35 | } | ||
36 | Err(req) => req, | ||
37 | }; | ||
38 | // ... | ||
39 | } | ||
40 | RawMessage::Response(_resp) => (), | ||
41 | RawMessage::Notification(_not) => (), | ||
42 | } | ||
43 | } | ||
44 | Ok(()) | ||
45 | } | ||