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