diff options
Diffstat (limited to 'crates/gen_lsp_server')
-rw-r--r-- | crates/gen_lsp_server/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/gen_lsp_server/src/lib.rs | 21 | ||||
-rw-r--r-- | crates/gen_lsp_server/src/msg.rs | 19 | ||||
-rw-r--r-- | crates/gen_lsp_server/src/stdio.rs | 3 |
4 files changed, 19 insertions, 25 deletions
diff --git a/crates/gen_lsp_server/Cargo.toml b/crates/gen_lsp_server/Cargo.toml index cf5c34a88..08b357b1e 100644 --- a/crates/gen_lsp_server/Cargo.toml +++ b/crates/gen_lsp_server/Cargo.toml | |||
@@ -1,4 +1,5 @@ | |||
1 | [package] | 1 | [package] |
2 | edition = "2018" | ||
2 | name = "gen_lsp_server" | 3 | name = "gen_lsp_server" |
3 | version = "0.1.0" | 4 | version = "0.1.0" |
4 | authors = ["Aleksey Kladov <[email protected]>"] | 5 | authors = ["Aleksey Kladov <[email protected]>"] |
diff --git a/crates/gen_lsp_server/src/lib.rs b/crates/gen_lsp_server/src/lib.rs index 5dab8f408..8779fbf0f 100644 --- a/crates/gen_lsp_server/src/lib.rs +++ b/crates/gen_lsp_server/src/lib.rs | |||
@@ -59,16 +59,7 @@ | |||
59 | //! } | 59 | //! } |
60 | //! ``` | 60 | //! ``` |
61 | 61 | ||
62 | #[macro_use] | 62 | use failure::{bail, format_err}; |
63 | extern crate failure; | ||
64 | #[macro_use] | ||
65 | extern crate log; | ||
66 | extern crate serde; | ||
67 | extern crate serde_json; | ||
68 | #[macro_use] | ||
69 | extern crate serde_derive; | ||
70 | extern crate crossbeam_channel; | ||
71 | extern crate languageserver_types; | ||
72 | 63 | ||
73 | mod msg; | 64 | mod msg; |
74 | mod stdio; | 65 | mod stdio; |
@@ -81,7 +72,7 @@ use languageserver_types::{ | |||
81 | }; | 72 | }; |
82 | 73 | ||
83 | pub type Result<T> = ::std::result::Result<T, failure::Error>; | 74 | pub type Result<T> = ::std::result::Result<T, failure::Error>; |
84 | pub use { | 75 | pub use crate::{ |
85 | msg::{ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, RawResponseError}, | 76 | msg::{ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, RawResponseError}, |
86 | stdio::{stdio_transport, Threads}, | 77 | stdio::{stdio_transport, Threads}, |
87 | }; | 78 | }; |
@@ -98,18 +89,18 @@ pub fn run_server( | |||
98 | sender: Sender<RawMessage>, | 89 | sender: Sender<RawMessage>, |
99 | server: impl FnOnce(InitializeParams, &Receiver<RawMessage>, &Sender<RawMessage>) -> Result<()>, | 90 | server: impl FnOnce(InitializeParams, &Receiver<RawMessage>, &Sender<RawMessage>) -> Result<()>, |
100 | ) -> Result<()> { | 91 | ) -> Result<()> { |
101 | info!("lsp server initializes"); | 92 | log::info!("lsp server initializes"); |
102 | let params = initialize(&receiver, &sender, caps)?; | 93 | let params = initialize(&receiver, &sender, caps)?; |
103 | info!("lsp server initialized, serving requests"); | 94 | log::info!("lsp server initialized, serving requests"); |
104 | server(params, &receiver, &sender)?; | 95 | server(params, &receiver, &sender)?; |
105 | info!("lsp server waiting for exit notification"); | 96 | log::info!("lsp server waiting for exit notification"); |
106 | match receiver.recv() { | 97 | match receiver.recv() { |
107 | Some(RawMessage::Notification(n)) => n | 98 | Some(RawMessage::Notification(n)) => n |
108 | .cast::<Exit>() | 99 | .cast::<Exit>() |
109 | .map_err(|n| format_err!("unexpected notification during shutdown: {:?}", n))?, | 100 | .map_err(|n| format_err!("unexpected notification during shutdown: {:?}", n))?, |
110 | m => bail!("unexpected message during shutdown: {:?}", m), | 101 | m => bail!("unexpected message during shutdown: {:?}", m), |
111 | } | 102 | } |
112 | info!("lsp server shutdown complete"); | 103 | log::info!("lsp server shutdown complete"); |
113 | Ok(()) | 104 | Ok(()) |
114 | } | 105 | } |
115 | 106 | ||
diff --git a/crates/gen_lsp_server/src/msg.rs b/crates/gen_lsp_server/src/msg.rs index e1b27c808..1e5384380 100644 --- a/crates/gen_lsp_server/src/msg.rs +++ b/crates/gen_lsp_server/src/msg.rs | |||
@@ -1,10 +1,11 @@ | |||
1 | use std::io::{BufRead, Write}; | 1 | use std::io::{BufRead, Write}; |
2 | 2 | ||
3 | use languageserver_types::{notification::Notification, request::Request}; | 3 | use languageserver_types::{notification::Notification, request::Request}; |
4 | use serde::{de::DeserializeOwned, Serialize}; | 4 | use serde_derive::{Deserialize, Serialize}; |
5 | use serde_json::{from_str, from_value, to_string, to_value, Value}; | 5 | use serde_json::{from_str, from_value, to_string, to_value, Value}; |
6 | use failure::{bail, format_err}; | ||
6 | 7 | ||
7 | use Result; | 8 | use crate::Result; |
8 | 9 | ||
9 | #[derive(Debug, Serialize, Deserialize, Clone)] | 10 | #[derive(Debug, Serialize, Deserialize, Clone)] |
10 | #[serde(untagged)] | 11 | #[serde(untagged)] |
@@ -91,7 +92,7 @@ impl RawRequest { | |||
91 | pub fn new<R>(id: u64, params: &R::Params) -> RawRequest | 92 | pub fn new<R>(id: u64, params: &R::Params) -> RawRequest |
92 | where | 93 | where |
93 | R: Request, | 94 | R: Request, |
94 | R::Params: Serialize, | 95 | R::Params: serde::Serialize, |
95 | { | 96 | { |
96 | RawRequest { | 97 | RawRequest { |
97 | id, | 98 | id, |
@@ -102,7 +103,7 @@ impl RawRequest { | |||
102 | pub fn cast<R>(self) -> ::std::result::Result<(u64, R::Params), RawRequest> | 103 | pub fn cast<R>(self) -> ::std::result::Result<(u64, R::Params), RawRequest> |
103 | where | 104 | where |
104 | R: Request, | 105 | R: Request, |
105 | R::Params: DeserializeOwned, | 106 | R::Params: serde::de::DeserializeOwned, |
106 | { | 107 | { |
107 | if self.method != R::METHOD { | 108 | if self.method != R::METHOD { |
108 | return Err(self); | 109 | return Err(self); |
@@ -117,7 +118,7 @@ impl RawResponse { | |||
117 | pub fn ok<R>(id: u64, result: &R::Result) -> RawResponse | 118 | pub fn ok<R>(id: u64, result: &R::Result) -> RawResponse |
118 | where | 119 | where |
119 | R: Request, | 120 | R: Request, |
120 | R::Result: Serialize, | 121 | R::Result: serde::Serialize, |
121 | { | 122 | { |
122 | RawResponse { | 123 | RawResponse { |
123 | id, | 124 | id, |
@@ -143,7 +144,7 @@ impl RawNotification { | |||
143 | pub fn new<N>(params: &N::Params) -> RawNotification | 144 | pub fn new<N>(params: &N::Params) -> RawNotification |
144 | where | 145 | where |
145 | N: Notification, | 146 | N: Notification, |
146 | N::Params: Serialize, | 147 | N::Params: serde::Serialize, |
147 | { | 148 | { |
148 | RawNotification { | 149 | RawNotification { |
149 | method: N::METHOD.to_string(), | 150 | method: N::METHOD.to_string(), |
@@ -153,7 +154,7 @@ impl RawNotification { | |||
153 | pub fn cast<N>(self) -> ::std::result::Result<N::Params, RawNotification> | 154 | pub fn cast<N>(self) -> ::std::result::Result<N::Params, RawNotification> |
154 | where | 155 | where |
155 | N: Notification, | 156 | N: Notification, |
156 | N::Params: DeserializeOwned, | 157 | N::Params: serde::de::DeserializeOwned, |
157 | { | 158 | { |
158 | if self.method != N::METHOD { | 159 | if self.method != N::METHOD { |
159 | return Err(self); | 160 | return Err(self); |
@@ -191,12 +192,12 @@ fn read_msg_text(inp: &mut impl BufRead) -> Result<Option<String>> { | |||
191 | buf.resize(size, 0); | 192 | buf.resize(size, 0); |
192 | inp.read_exact(&mut buf)?; | 193 | inp.read_exact(&mut buf)?; |
193 | let buf = String::from_utf8(buf)?; | 194 | let buf = String::from_utf8(buf)?; |
194 | debug!("< {}", buf); | 195 | log::debug!("< {}", buf); |
195 | Ok(Some(buf)) | 196 | Ok(Some(buf)) |
196 | } | 197 | } |
197 | 198 | ||
198 | fn write_msg_text(out: &mut impl Write, msg: &str) -> Result<()> { | 199 | fn write_msg_text(out: &mut impl Write, msg: &str) -> Result<()> { |
199 | debug!("> {}", msg); | 200 | log::debug!("> {}", msg); |
200 | write!(out, "Content-Length: {}\r\n\r\n", msg.len())?; | 201 | write!(out, "Content-Length: {}\r\n\r\n", msg.len())?; |
201 | out.write_all(msg.as_bytes())?; | 202 | out.write_all(msg.as_bytes())?; |
202 | out.flush()?; | 203 | out.flush()?; |
diff --git a/crates/gen_lsp_server/src/stdio.rs b/crates/gen_lsp_server/src/stdio.rs index 3d8a1712a..35d8e46d0 100644 --- a/crates/gen_lsp_server/src/stdio.rs +++ b/crates/gen_lsp_server/src/stdio.rs | |||
@@ -4,8 +4,9 @@ use std::{ | |||
4 | }; | 4 | }; |
5 | 5 | ||
6 | use crossbeam_channel::{bounded, Receiver, Sender}; | 6 | use crossbeam_channel::{bounded, Receiver, Sender}; |
7 | use failure::bail; | ||
7 | 8 | ||
8 | use {RawMessage, Result}; | 9 | use crate::{RawMessage, Result}; |
9 | 10 | ||
10 | pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads) { | 11 | pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads) { |
11 | let (writer_sender, mut writer_receiver) = bounded::<RawMessage>(16); | 12 | let (writer_sender, mut writer_receiver) = bounded::<RawMessage>(16); |