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.rs72
1 files changed, 72 insertions, 0 deletions
diff --git a/crates/ra_lsp_server/src/config.rs b/crates/ra_lsp_server/src/config.rs
new file mode 100644
index 000000000..6dcdc695a
--- /dev/null
+++ b/crates/ra_lsp_server/src/config.rs
@@ -0,0 +1,72 @@
1use serde::{Deserialize, Deserializer};
2
3/// Client provided initialization options
4#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
5#[serde(rename_all = "camelCase", default)]
6pub struct ServerConfig {
7 /// Whether the client supports our custom highlighting publishing decorations.
8 /// This is different to the highlightingOn setting, which is whether the user
9 /// wants our custom highlighting to be used.
10 ///
11 /// Defaults to `false`
12 #[serde(deserialize_with = "nullable_bool_false")]
13 pub publish_decorations: bool,
14
15 /// Whether or not the workspace loaded notification should be sent
16 ///
17 /// Defaults to `true`
18 #[serde(deserialize_with = "nullable_bool_true")]
19 pub show_workspace_loaded: bool,
20
21 pub exclude_globs: Vec<String>,
22
23 pub lru_capacity: Option<usize>,
24}
25
26impl Default for ServerConfig {
27 fn default() -> ServerConfig {
28 ServerConfig {
29 publish_decorations: false,
30 show_workspace_loaded: true,
31 exclude_globs: Vec::new(),
32 lru_capacity: None,
33 }
34 }
35}
36
37/// Deserializes a null value to a bool false by default
38fn nullable_bool_false<'de, D>(deserializer: D) -> Result<bool, D::Error>
39where
40 D: Deserializer<'de>,
41{
42 let opt = Option::deserialize(deserializer)?;
43 Ok(opt.unwrap_or(false))
44}
45
46/// Deserializes a null value to a bool true by default
47fn nullable_bool_true<'de, D>(deserializer: D) -> Result<bool, D::Error>
48where
49 D: Deserializer<'de>,
50{
51 let opt = Option::deserialize(deserializer)?;
52 Ok(opt.unwrap_or(true))
53}
54
55#[cfg(test)]
56mod test {
57 use super::*;
58
59 #[test]
60 fn deserialize_init_options_defaults() {
61 // check that null == default for both fields
62 let default = ServerConfig::default();
63 assert_eq!(default, serde_json::from_str(r#"{}"#).unwrap());
64 assert_eq!(
65 default,
66 serde_json::from_str(
67 r#"{"publishDecorations":null, "showWorkspaceLoaded":null, "lruCapacity":null}"#
68 )
69 .unwrap()
70 );
71 }
72}