rust-analyzer/crates/ra_lsp_server/src/config.rs

82 lines
2.3 KiB
Rust
Raw Normal View History

//! FIXME: write short doc here
2019-08-22 11:44:16 +00:00
use rustc_hash::FxHashMap;
use serde::{Deserialize, Deserializer};
/// Client provided initialization options
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase", default)]
2019-08-06 11:12:58 +00:00
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,
pub exclude_globs: Vec<String>,
2019-09-06 13:25:24 +00:00
#[serde(deserialize_with = "nullable_bool_false")]
pub use_client_watching: bool,
2019-06-07 17:49:29 +00:00
pub lru_capacity: Option<usize>,
2019-08-19 12:41:18 +00:00
/// For internal usage to make integrated tests faster.
#[serde(deserialize_with = "nullable_bool_true")]
pub with_sysroot: bool,
2019-08-22 11:44:16 +00:00
/// Fine grained feature flags to disable specific features.
pub feature_flags: FxHashMap<String, bool>,
}
2019-08-06 11:12:58 +00:00
impl Default for ServerConfig {
fn default() -> ServerConfig {
ServerConfig {
publish_decorations: false,
exclude_globs: Vec::new(),
2019-09-06 13:25:24 +00:00
use_client_watching: false,
lru_capacity: None,
2019-08-19 12:41:18 +00:00
with_sysroot: true,
2019-08-22 11:44:16 +00:00
feature_flags: FxHashMap::default(),
}
}
}
/// Deserializes a null value to a bool false by default
fn nullable_bool_false<'de, D>(deserializer: D) -> Result<bool, D::Error>
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<bool, D::Error>
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
2019-08-06 11:12:58 +00:00
let default = ServerConfig::default();
assert_eq!(default, serde_json::from_str(r#"{}"#).unwrap());
assert_eq!(
default,
2019-06-07 17:49:29 +00:00
serde_json::from_str(
r#"{"publishDecorations":null, "showWorkspaceLoaded":null, "lruCapacity":null}"#
)
.unwrap()
);
}
}