From 4dd5afb7fe2eb20748ade9141e74b04f5dd2f922 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 22 Aug 2019 11:08:22 +0300 Subject: show error to the user when deserializing config --- crates/ra_lsp_server/src/lib.rs | 5 ++++- crates/ra_lsp_server/src/main.rs | 19 +++++++++++++------ crates/ra_lsp_server/src/main_loop.rs | 6 +++++- 3 files changed, 22 insertions(+), 8 deletions(-) (limited to 'crates/ra_lsp_server/src') diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs index ca388e472..2c5d7c72d 100644 --- a/crates/ra_lsp_server/src/lib.rs +++ b/crates/ra_lsp_server/src/lib.rs @@ -11,5 +11,8 @@ mod world; pub type Result = std::result::Result>; pub use crate::{ - caps::server_capabilities, config::ServerConfig, main_loop::main_loop, main_loop::LspError, + caps::server_capabilities, + config::ServerConfig, + main_loop::LspError, + main_loop::{main_loop, show_message}, }; diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index 36d4898bd..ae1392cb5 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs @@ -1,8 +1,7 @@ use flexi_logger::{Duplicate, Logger}; use gen_lsp_server::{run_server, stdio_transport}; -use serde::Deserialize; -use ra_lsp_server::{Result, ServerConfig}; +use ra_lsp_server::{show_message, Result, ServerConfig}; use ra_prof; fn main() -> Result<()> { @@ -46,15 +45,23 @@ fn main_inner() -> Result<()> { .filter(|workspaces| !workspaces.is_empty()) .unwrap_or_else(|| vec![root]); - let opts = params + let server_config: ServerConfig = params .initialization_options .and_then(|v| { - ServerConfig::deserialize(v) - .map_err(|e| log::error!("failed to deserialize config: {}", e)) + serde_json::from_value(v) + .map_err(|e| { + log::error!("failed to deserialize config: {}", e); + show_message( + lsp_types::MessageType::Error, + format!("failed to deserialize config: {}", e), + s, + ); + }) .ok() }) .unwrap_or_default(); - ra_lsp_server::main_loop(workspace_roots, params.capabilities, opts, r, s) + + ra_lsp_server::main_loop(workspace_roots, params.capabilities, server_config, r, s) })?; log::info!("shutting down IO..."); threads.join()?; diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index fcb782386..c0395c6d8 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -617,7 +617,11 @@ fn update_file_notifications_on_threadpool( }); } -fn show_message(typ: req::MessageType, message: impl Into, sender: &Sender) { +pub fn show_message( + typ: req::MessageType, + message: impl Into, + sender: &Sender, +) { let message = message.into(); let params = req::ShowMessageParams { typ, message }; let not = RawNotification::new::(¶ms); -- cgit v1.2.3