2019-10-25 01:00:30 -05:00
|
|
|
//! Config used by the language server.
|
|
|
|
//!
|
|
|
|
//! We currently get this config from `initialize` LSP request, which is not the
|
|
|
|
//! best way to do it, but was the simplest thing we could implement.
|
|
|
|
//!
|
|
|
|
//! Of particular interest is the `feature_flags` hash map: while other fields
|
|
|
|
//! configure the server itself, feature flags are passed into analysis, and
|
|
|
|
//! tweak things like automatic insertion of `()` in completions.
|
2019-09-30 03:58:53 -05:00
|
|
|
|
2020-03-10 20:59:49 -05:00
|
|
|
use crate::req::InlayConfigDef;
|
|
|
|
use ra_ide::InlayConfig;
|
2019-08-22 06:44:16 -05:00
|
|
|
use rustc_hash::FxHashMap;
|
|
|
|
|
2019-12-13 04:16:34 -06:00
|
|
|
use ra_project_model::CargoFeatures;
|
2019-03-07 14:06:25 -06:00
|
|
|
use serde::{Deserialize, Deserializer};
|
|
|
|
|
|
|
|
/// Client provided initialization options
|
2019-08-06 06:34:28 -05:00
|
|
|
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
|
2019-03-07 14:06:25 -06:00
|
|
|
#[serde(rename_all = "camelCase", default)]
|
2019-08-06 06:12:58 -05:00
|
|
|
pub struct ServerConfig {
|
2019-03-07 14:06:25 -06:00
|
|
|
/// 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,
|
|
|
|
|
2019-08-06 06:34:28 -05:00
|
|
|
pub exclude_globs: Vec<String>,
|
2019-09-06 08:25:24 -05:00
|
|
|
#[serde(deserialize_with = "nullable_bool_false")]
|
|
|
|
pub use_client_watching: bool,
|
2019-08-06 06:34:28 -05:00
|
|
|
|
2019-06-07 12:49:29 -05:00
|
|
|
pub lru_capacity: Option<usize>,
|
2019-08-19 07:41:18 -05:00
|
|
|
|
2020-03-10 13:21:56 -05:00
|
|
|
#[serde(with = "InlayConfigDef")]
|
|
|
|
pub inlay_hint_opts: InlayConfig,
|
2019-11-18 11:02:28 -06:00
|
|
|
|
2019-12-25 13:23:44 -06:00
|
|
|
pub cargo_watch_enable: bool,
|
|
|
|
pub cargo_watch_args: Vec<String>,
|
|
|
|
pub cargo_watch_command: String,
|
|
|
|
pub cargo_watch_all_targets: bool,
|
2019-12-25 09:50:38 -06:00
|
|
|
|
2019-08-19 07:41:18 -05:00
|
|
|
/// For internal usage to make integrated tests faster.
|
|
|
|
#[serde(deserialize_with = "nullable_bool_true")]
|
|
|
|
pub with_sysroot: bool,
|
2019-08-22 06:44:16 -05:00
|
|
|
|
|
|
|
/// Fine grained feature flags to disable specific features.
|
|
|
|
pub feature_flags: FxHashMap<String, bool>,
|
2019-12-13 04:16:34 -06:00
|
|
|
|
2020-02-17 02:44:58 -06:00
|
|
|
pub rustfmt_args: Vec<String>,
|
|
|
|
|
2019-12-13 04:16:34 -06:00
|
|
|
/// Cargo feature configurations.
|
|
|
|
pub cargo_features: CargoFeatures,
|
2019-03-07 14:06:25 -06:00
|
|
|
}
|
|
|
|
|
2019-08-06 06:12:58 -05:00
|
|
|
impl Default for ServerConfig {
|
|
|
|
fn default() -> ServerConfig {
|
2019-08-06 06:34:28 -05:00
|
|
|
ServerConfig {
|
|
|
|
publish_decorations: false,
|
|
|
|
exclude_globs: Vec::new(),
|
2019-09-06 08:25:24 -05:00
|
|
|
use_client_watching: false,
|
2019-08-06 06:34:28 -05:00
|
|
|
lru_capacity: None,
|
2020-03-10 02:55:46 -05:00
|
|
|
inlay_hint_opts: Default::default(),
|
2019-12-25 13:23:44 -06:00
|
|
|
cargo_watch_enable: true,
|
|
|
|
cargo_watch_args: Vec::new(),
|
|
|
|
cargo_watch_command: "check".to_string(),
|
|
|
|
cargo_watch_all_targets: true,
|
2019-08-19 07:41:18 -05:00
|
|
|
with_sysroot: true,
|
2019-08-22 06:44:16 -05:00
|
|
|
feature_flags: FxHashMap::default(),
|
2019-12-13 04:16:34 -06:00
|
|
|
cargo_features: Default::default(),
|
2020-02-17 02:44:58 -06:00
|
|
|
rustfmt_args: Vec::new(),
|
2019-08-06 06:34:28 -05:00
|
|
|
}
|
2019-03-07 14:06:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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 06:12:58 -05:00
|
|
|
let default = ServerConfig::default();
|
2019-03-07 14:06:25 -06:00
|
|
|
assert_eq!(default, serde_json::from_str(r#"{}"#).unwrap());
|
|
|
|
assert_eq!(
|
|
|
|
default,
|
2019-10-25 01:00:30 -05:00
|
|
|
serde_json::from_str(r#"{"publishDecorations":null, "lruCapacity":null}"#).unwrap()
|
2019-03-07 14:06:25 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|