diff options
Diffstat (limited to 'crates/ra_lsp_server/src/lib.rs')
-rw-r--r-- | crates/ra_lsp_server/src/lib.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs index 1208c1343..a3464a5a3 100644 --- a/crates/ra_lsp_server/src/lib.rs +++ b/crates/ra_lsp_server/src/lib.rs | |||
@@ -31,6 +31,8 @@ mod config; | |||
31 | mod world; | 31 | mod world; |
32 | mod diagnostics; | 32 | mod diagnostics; |
33 | 33 | ||
34 | use serde::de::DeserializeOwned; | ||
35 | |||
34 | pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>; | 36 | pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>; |
35 | pub use crate::{ | 37 | pub use crate::{ |
36 | caps::server_capabilities, | 38 | caps::server_capabilities, |
@@ -38,3 +40,9 @@ pub use crate::{ | |||
38 | main_loop::LspError, | 40 | main_loop::LspError, |
39 | main_loop::{main_loop, show_message}, | 41 | main_loop::{main_loop, show_message}, |
40 | }; | 42 | }; |
43 | |||
44 | pub fn from_json<T: DeserializeOwned>(what: &'static str, json: serde_json::Value) -> Result<T> { | ||
45 | let res = T::deserialize(&json) | ||
46 | .map_err(|e| format!("Failed to deserialize {}: {}; {}", what, e, json))?; | ||
47 | Ok(res) | ||
48 | } | ||