1 //! Config used by the language server.
3 //! We currently get this config from `initialize` LSP request, which is not the
4 //! best way to do it, but was the simplest thing we could implement.
6 //! Of particular interest is the `feature_flags` hash map: while other fields
7 //! configure the server itself, feature flags are passed into analysis, and
8 //! tweak things like automatic insertion of `()` in completions.
10 use rustc_hash::FxHashMap;
12 use ra_project_model::CargoFeatures;
13 use serde::{Deserialize, Deserializer};
15 /// Client provided initialization options
16 #[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
17 #[serde(rename_all = "camelCase", default)]
18 pub struct ServerConfig {
19 /// Whether the client supports our custom highlighting publishing decorations.
20 /// This is different to the highlightingOn setting, which is whether the user
21 /// wants our custom highlighting to be used.
23 /// Defaults to `false`
24 #[serde(deserialize_with = "nullable_bool_false")]
25 pub publish_decorations: bool,
27 pub exclude_globs: Vec<String>,
28 #[serde(deserialize_with = "nullable_bool_false")]
29 pub use_client_watching: bool,
31 pub lru_capacity: Option<usize>,
33 pub max_inlay_hint_length: Option<usize>,
35 /// For internal usage to make integrated tests faster.
36 #[serde(deserialize_with = "nullable_bool_true")]
37 pub with_sysroot: bool,
39 /// Fine grained feature flags to disable specific features.
40 pub feature_flags: FxHashMap<String, bool>,
42 /// Cargo feature configurations.
43 pub cargo_features: CargoFeatures,
46 impl Default for ServerConfig {
47 fn default() -> ServerConfig {
49 publish_decorations: false,
50 exclude_globs: Vec::new(),
51 use_client_watching: false,
53 max_inlay_hint_length: None,
55 feature_flags: FxHashMap::default(),
56 cargo_features: Default::default(),
61 /// Deserializes a null value to a bool false by default
62 fn nullable_bool_false<'de, D>(deserializer: D) -> Result<bool, D::Error>
66 let opt = Option::deserialize(deserializer)?;
67 Ok(opt.unwrap_or(false))
70 /// Deserializes a null value to a bool true by default
71 fn nullable_bool_true<'de, D>(deserializer: D) -> Result<bool, D::Error>
75 let opt = Option::deserialize(deserializer)?;
76 Ok(opt.unwrap_or(true))
84 fn deserialize_init_options_defaults() {
85 // check that null == default for both fields
86 let default = ServerConfig::default();
87 assert_eq!(default, serde_json::from_str(r#"{}"#).unwrap());
90 serde_json::from_str(r#"{"publishDecorations":null, "lruCapacity":null}"#).unwrap()