aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src/config.rs')
-rw-r--r--crates/ra_lsp_server/src/config.rs105
1 files changed, 0 insertions, 105 deletions
diff --git a/crates/ra_lsp_server/src/config.rs b/crates/ra_lsp_server/src/config.rs
deleted file mode 100644
index 3314269ec..000000000
--- a/crates/ra_lsp_server/src/config.rs
+++ /dev/null
@@ -1,105 +0,0 @@
1//! Config used by the language server.
2//!
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.
5//!
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.
9
10use rustc_hash::FxHashMap;
11
12use ra_project_model::CargoFeatures;
13use serde::{Deserialize, Deserializer};
14
15/// Client provided initialization options
16#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
17#[serde(rename_all = "camelCase", default)]
18pub 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.
22 ///
23 /// Defaults to `false`
24 #[serde(deserialize_with = "nullable_bool_false")]
25 pub publish_decorations: bool,
26
27 pub exclude_globs: Vec<String>,
28 #[serde(deserialize_with = "nullable_bool_false")]
29 pub use_client_watching: bool,
30
31 pub lru_capacity: Option<usize>,
32
33 pub max_inlay_hint_length: Option<usize>,
34
35 pub cargo_watch_enable: bool,
36 pub cargo_watch_args: Vec<String>,
37 pub cargo_watch_command: String,
38 pub cargo_watch_all_targets: bool,
39
40 /// For internal usage to make integrated tests faster.
41 #[serde(deserialize_with = "nullable_bool_true")]
42 pub with_sysroot: bool,
43
44 /// Fine grained feature flags to disable specific features.
45 pub feature_flags: FxHashMap<String, bool>,
46
47 pub rustfmt_args: Vec<String>,
48
49 /// Cargo feature configurations.
50 pub cargo_features: CargoFeatures,
51}
52
53impl Default for ServerConfig {
54 fn default() -> ServerConfig {
55 ServerConfig {
56 publish_decorations: false,
57 exclude_globs: Vec::new(),
58 use_client_watching: false,
59 lru_capacity: None,
60 max_inlay_hint_length: None,
61 cargo_watch_enable: true,
62 cargo_watch_args: Vec::new(),
63 cargo_watch_command: "check".to_string(),
64 cargo_watch_all_targets: true,
65 with_sysroot: true,
66 feature_flags: FxHashMap::default(),
67 cargo_features: Default::default(),
68 rustfmt_args: Vec::new(),
69 }
70 }
71}
72
73/// Deserializes a null value to a bool false by default
74fn nullable_bool_false<'de, D>(deserializer: D) -> Result<bool, D::Error>
75where
76 D: Deserializer<'de>,
77{
78 let opt = Option::deserialize(deserializer)?;
79 Ok(opt.unwrap_or(false))
80}
81
82/// Deserializes a null value to a bool true by default
83fn nullable_bool_true<'de, D>(deserializer: D) -> Result<bool, D::Error>
84where
85 D: Deserializer<'de>,
86{
87 let opt = Option::deserialize(deserializer)?;
88 Ok(opt.unwrap_or(true))
89}
90
91#[cfg(test)]
92mod test {
93 use super::*;
94
95 #[test]
96 fn deserialize_init_options_defaults() {
97 // check that null == default for both fields
98 let default = ServerConfig::default();
99 assert_eq!(default, serde_json::from_str(r#"{}"#).unwrap());
100 assert_eq!(
101 default,
102 serde_json::from_str(r#"{"publishDecorations":null, "lruCapacity":null}"#).unwrap()
103 );
104 }
105}