diff options
Diffstat (limited to 'crates/gen_lsp_server')
-rw-r--r-- | crates/gen_lsp_server/Cargo.toml | 3 | ||||
-rw-r--r-- | crates/gen_lsp_server/src/msg.rs | 12 |
2 files changed, 10 insertions, 5 deletions
diff --git a/crates/gen_lsp_server/Cargo.toml b/crates/gen_lsp_server/Cargo.toml index 6c91e38aa..9776a82e3 100644 --- a/crates/gen_lsp_server/Cargo.toml +++ b/crates/gen_lsp_server/Cargo.toml | |||
@@ -12,6 +12,5 @@ languageserver-types = "0.53.0" | |||
12 | log = "0.4.3" | 12 | log = "0.4.3" |
13 | failure = "0.1.2" | 13 | failure = "0.1.2" |
14 | serde_json = "1.0.24" | 14 | serde_json = "1.0.24" |
15 | serde = "1.0.71" | 15 | serde = { version = "1.0.71", features = ["derive"] } |
16 | serde_derive = "1.0.71" | ||
17 | crossbeam-channel = "0.2.4" | 16 | crossbeam-channel = "0.2.4" |
diff --git a/crates/gen_lsp_server/src/msg.rs b/crates/gen_lsp_server/src/msg.rs index 22d273d55..f68cbc541 100644 --- a/crates/gen_lsp_server/src/msg.rs +++ b/crates/gen_lsp_server/src/msg.rs | |||
@@ -1,13 +1,13 @@ | |||
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_derive::{Deserialize, Serialize}; | 4 | use serde::{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 | use failure::{bail, format_err}; |
7 | 7 | ||
8 | use crate::Result; | 8 | use crate::Result; |
9 | 9 | ||
10 | #[derive(Debug, Serialize, Deserialize, Clone)] | 10 | #[derive(Serialize, Deserialize, Debug, Clone)] |
11 | #[serde(untagged)] | 11 | #[serde(untagged)] |
12 | pub enum RawMessage { | 12 | pub enum RawMessage { |
13 | Request(RawRequest), | 13 | Request(RawRequest), |
@@ -152,12 +152,18 @@ impl RawNotification { | |||
152 | params: to_value(params).unwrap(), | 152 | params: to_value(params).unwrap(), |
153 | } | 153 | } |
154 | } | 154 | } |
155 | pub fn is<N>(&self) -> bool | ||
156 | where | ||
157 | N: Notification, | ||
158 | { | ||
159 | self.method == N::METHOD | ||
160 | } | ||
155 | pub fn cast<N>(self) -> ::std::result::Result<N::Params, RawNotification> | 161 | pub fn cast<N>(self) -> ::std::result::Result<N::Params, RawNotification> |
156 | where | 162 | where |
157 | N: Notification, | 163 | N: Notification, |
158 | N::Params: serde::de::DeserializeOwned, | 164 | N::Params: serde::de::DeserializeOwned, |
159 | { | 165 | { |
160 | if self.method != N::METHOD { | 166 | if !self.is::<N>() { |
161 | return Err(self); | 167 | return Err(self); |
162 | } | 168 | } |
163 | Ok(from_value(self.params).unwrap()) | 169 | Ok(from_value(self.params).unwrap()) |