diff options
Diffstat (limited to 'crates/gen_lsp_server/src/msg.rs')
-rw-r--r-- | crates/gen_lsp_server/src/msg.rs | 19 |
1 files changed, 10 insertions, 9 deletions
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()?; |