From f70b7e1f079e7b4a51ddd6503860eb97f1a6fcbe Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 6 Aug 2019 13:12:58 +0200 Subject: rename config --- crates/ra_lsp_server/src/config.rs | 65 +++++++++++++++++++++++++++++++++ crates/ra_lsp_server/src/init.rs | 69 ----------------------------------- crates/ra_lsp_server/src/lib.rs | 5 +-- crates/ra_lsp_server/src/main.rs | 4 +- crates/ra_lsp_server/src/main_loop.rs | 10 ++--- 5 files changed, 74 insertions(+), 79 deletions(-) create mode 100644 crates/ra_lsp_server/src/config.rs delete mode 100644 crates/ra_lsp_server/src/init.rs (limited to 'crates') diff --git a/crates/ra_lsp_server/src/config.rs b/crates/ra_lsp_server/src/config.rs new file mode 100644 index 000000000..a16cc292e --- /dev/null +++ b/crates/ra_lsp_server/src/config.rs @@ -0,0 +1,65 @@ +use serde::{Deserialize, Deserializer}; + +/// Client provided initialization options +#[derive(Deserialize, Clone, Copy, Debug, PartialEq, Eq)] +#[serde(rename_all = "camelCase", default)] +pub struct ServerConfig { + /// Whether the client supports our custom highlighting publishing decorations. + /// This is different to the highlightingOn setting, which is whether the user + /// wants our custom highlighting to be used. + /// + /// Defaults to `false` + #[serde(deserialize_with = "nullable_bool_false")] + pub publish_decorations: bool, + + /// Whether or not the workspace loaded notification should be sent + /// + /// Defaults to `true` + #[serde(deserialize_with = "nullable_bool_true")] + pub show_workspace_loaded: bool, + + pub lru_capacity: Option, +} + +impl Default for ServerConfig { + fn default() -> ServerConfig { + ServerConfig { publish_decorations: false, show_workspace_loaded: true, lru_capacity: None } + } +} + +/// Deserializes a null value to a bool false by default +fn nullable_bool_false<'de, D>(deserializer: D) -> Result +where + D: Deserializer<'de>, +{ + let opt = Option::deserialize(deserializer)?; + Ok(opt.unwrap_or(false)) +} + +/// Deserializes a null value to a bool true by default +fn nullable_bool_true<'de, D>(deserializer: D) -> Result +where + D: Deserializer<'de>, +{ + let opt = Option::deserialize(deserializer)?; + Ok(opt.unwrap_or(true)) +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn deserialize_init_options_defaults() { + // check that null == default for both fields + let default = ServerConfig::default(); + assert_eq!(default, serde_json::from_str(r#"{}"#).unwrap()); + assert_eq!( + default, + serde_json::from_str( + r#"{"publishDecorations":null, "showWorkspaceLoaded":null, "lruCapacity":null}"# + ) + .unwrap() + ); + } +} diff --git a/crates/ra_lsp_server/src/init.rs b/crates/ra_lsp_server/src/init.rs deleted file mode 100644 index b894b449d..000000000 --- a/crates/ra_lsp_server/src/init.rs +++ /dev/null @@ -1,69 +0,0 @@ -use serde::{Deserialize, Deserializer}; - -/// Client provided initialization options -#[derive(Deserialize, Clone, Copy, Debug, PartialEq, Eq)] -#[serde(rename_all = "camelCase", default)] -pub struct InitializationOptions { - /// Whether the client supports our custom highlighting publishing decorations. - /// This is different to the highlightingOn setting, which is whether the user - /// wants our custom highlighting to be used. - /// - /// Defaults to `false` - #[serde(deserialize_with = "nullable_bool_false")] - pub publish_decorations: bool, - - /// Whether or not the workspace loaded notification should be sent - /// - /// Defaults to `true` - #[serde(deserialize_with = "nullable_bool_true")] - pub show_workspace_loaded: bool, - - pub lru_capacity: Option, -} - -impl Default for InitializationOptions { - fn default() -> InitializationOptions { - InitializationOptions { - publish_decorations: false, - show_workspace_loaded: true, - lru_capacity: None, - } - } -} - -/// Deserializes a null value to a bool false by default -fn nullable_bool_false<'de, D>(deserializer: D) -> Result -where - D: Deserializer<'de>, -{ - let opt = Option::deserialize(deserializer)?; - Ok(opt.unwrap_or(false)) -} - -/// Deserializes a null value to a bool true by default -fn nullable_bool_true<'de, D>(deserializer: D) -> Result -where - D: Deserializer<'de>, -{ - let opt = Option::deserialize(deserializer)?; - Ok(opt.unwrap_or(true)) -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn deserialize_init_options_defaults() { - // check that null == default for both fields - let default = InitializationOptions::default(); - assert_eq!(default, serde_json::from_str(r#"{}"#).unwrap()); - assert_eq!( - default, - serde_json::from_str( - r#"{"publishDecorations":null, "showWorkspaceLoaded":null, "lruCapacity":null}"# - ) - .unwrap() - ); - } -} diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs index 2ae6300c8..795f86383 100644 --- a/crates/ra_lsp_server/src/lib.rs +++ b/crates/ra_lsp_server/src/lib.rs @@ -5,11 +5,10 @@ mod main_loop; mod markdown; mod project_model; pub mod req; -pub mod init; +pub mod config; mod world; pub type Result = std::result::Result>; pub use crate::{ - caps::server_capabilities, init::InitializationOptions, main_loop::main_loop, - main_loop::LspError, + caps::server_capabilities, config::ServerConfig, main_loop::main_loop, main_loop::LspError, }; diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index c1f8243be..1a2ab1bc2 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs @@ -2,7 +2,7 @@ use flexi_logger::{Duplicate, Logger}; use gen_lsp_server::{run_server, stdio_transport}; use serde::Deserialize; -use ra_lsp_server::{InitializationOptions, Result}; +use ra_lsp_server::{Result, ServerConfig}; use ra_prof; fn main() -> Result<()> { @@ -48,7 +48,7 @@ fn main_inner() -> Result<()> { let opts = params .initialization_options - .and_then(|v| InitializationOptions::deserialize(v).ok()) + .and_then(|v| ServerConfig::deserialize(v).ok()) .unwrap_or_default(); ra_lsp_server::main_loop(workspace_roots, params.capabilities, opts, r, s) diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 9a38d43d2..8ab501828 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -23,7 +23,7 @@ use crate::{ project_model::workspace_loader, req, world::{Options, WorldSnapshot, WorldState}, - InitializationOptions, Result, + Result, ServerConfig, }; const THREADPOOL_SIZE: usize = 8; @@ -52,7 +52,7 @@ impl Error for LspError {} pub fn main_loop( ws_roots: Vec, client_caps: ClientCapabilities, - options: InitializationOptions, + config: ServerConfig, msg_receiver: &Receiver, msg_sender: &Sender, ) -> Result<()> { @@ -81,10 +81,10 @@ pub fn main_loop( let mut state = WorldState::new( ws_roots, workspaces, - options.lru_capacity, + config.lru_capacity, Options { - publish_decorations: options.publish_decorations, - show_workspace_loaded: options.show_workspace_loaded, + publish_decorations: config.publish_decorations, + show_workspace_loaded: config.show_workspace_loaded, supports_location_link: client_caps .text_document .and_then(|it| it.definition) -- cgit v1.2.3