diff options
author | Aleksey Kladov <[email protected]> | 2020-02-11 08:46:45 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-11 08:46:45 +0000 |
commit | 44425eaebcf9c1b3fb8ad311bed83887ab54a43b (patch) | |
tree | 64011248f5c92002bda04fc990d46363bf0e1967 /crates/ra_lsp_server/src/main.rs | |
parent | f8d6d6f23bfb15021be91031ba983da19f0d3ada (diff) |
Better error messages while deserializing
Diffstat (limited to 'crates/ra_lsp_server/src/main.rs')
-rw-r--r-- | crates/ra_lsp_server/src/main.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index 3879eeff2..c8a017c5c 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! `ra_lsp_server` binary | 1 | //! `ra_lsp_server` binary |
2 | 2 | ||
3 | use lsp_server::Connection; | 3 | use lsp_server::Connection; |
4 | use ra_lsp_server::{show_message, Result, ServerConfig}; | 4 | use ra_lsp_server::{from_json, show_message, Result, ServerConfig}; |
5 | use ra_prof; | 5 | use ra_prof; |
6 | 6 | ||
7 | fn main() -> Result<()> { | 7 | fn main() -> Result<()> { |
@@ -45,7 +45,8 @@ fn run_server() -> Result<()> { | |||
45 | let server_capabilities = serde_json::to_value(ra_lsp_server::server_capabilities()).unwrap(); | 45 | let server_capabilities = serde_json::to_value(ra_lsp_server::server_capabilities()).unwrap(); |
46 | 46 | ||
47 | let initialize_params = connection.initialize(server_capabilities)?; | 47 | let initialize_params = connection.initialize(server_capabilities)?; |
48 | let initialize_params: lsp_types::InitializeParams = serde_json::from_value(initialize_params)?; | 48 | let initialize_params = |
49 | from_json::<lsp_types::InitializeParams>("InitializeParams", initialize_params)?; | ||
49 | 50 | ||
50 | if let Some(client_info) = initialize_params.client_info { | 51 | if let Some(client_info) = initialize_params.client_info { |
51 | log::info!("Client '{}' {}", client_info.name, client_info.version.unwrap_or_default()); | 52 | log::info!("Client '{}' {}", client_info.name, client_info.version.unwrap_or_default()); |
@@ -62,17 +63,13 @@ fn run_server() -> Result<()> { | |||
62 | .filter(|workspaces| !workspaces.is_empty()) | 63 | .filter(|workspaces| !workspaces.is_empty()) |
63 | .unwrap_or_else(|| vec![root]); | 64 | .unwrap_or_else(|| vec![root]); |
64 | 65 | ||
65 | let server_config: ServerConfig = initialize_params | 66 | let server_config = initialize_params |
66 | .initialization_options | 67 | .initialization_options |
67 | .and_then(|v| { | 68 | .and_then(|v| { |
68 | serde_json::from_value(v) | 69 | from_json::<ServerConfig>("config", v) |
69 | .map_err(|e| { | 70 | .map_err(|e| { |
70 | log::error!("failed to deserialize config: {}", e); | 71 | log::error!("{}", e); |
71 | show_message( | 72 | show_message(lsp_types::MessageType::Error, e.to_string(), &connection.sender); |
72 | lsp_types::MessageType::Error, | ||
73 | format!("failed to deserialize config: {}", e), | ||
74 | &connection.sender, | ||
75 | ); | ||
76 | }) | 73 | }) |
77 | .ok() | 74 | .ok() |
78 | }) | 75 | }) |