aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/init.rs
diff options
context:
space:
mode:
authorLucas Spits <[email protected]>2019-03-11 19:41:48 +0000
committerLucas Spits <[email protected]>2019-03-11 19:41:48 +0000
commitde4ad44282785d0928824eda5f062c2367a870f7 (patch)
treeb89261aa34f9216d61e8f3751a009735ec139323 /crates/ra_lsp_server/src/init.rs
parent7185c594fe1b6c282c432c1fbb57e8e6e23421ed (diff)
parentf96df105ea6d27f295cc1c0a6cdb6c50979f67ed (diff)
Merge branch 'master' of https://github.com/LDSpits/rust-analyzer into feature/workspace-directory
Diffstat (limited to 'crates/ra_lsp_server/src/init.rs')
-rw-r--r--crates/ra_lsp_server/src/init.rs100
1 files changed, 61 insertions, 39 deletions
diff --git a/crates/ra_lsp_server/src/init.rs b/crates/ra_lsp_server/src/init.rs
index 0b7a47a0b..1b77e0312 100644
--- a/crates/ra_lsp_server/src/init.rs
+++ b/crates/ra_lsp_server/src/init.rs
@@ -1,39 +1,61 @@
1use serde::{Deserialize, Deserializer}; 1use serde::{Deserialize, Deserializer};
2 2
3/// Client provided initialization options 3/// Client provided initialization options
4#[derive(Deserialize, Clone, Copy, Debug)] 4#[derive(Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
5#[serde(rename_all = "camelCase")] 5#[serde(rename_all = "camelCase", default)]
6pub struct InitializationOptions { 6pub struct InitializationOptions {
7 /// Whether the client supports our custom highlighting publishing decorations. 7 /// Whether the client supports our custom highlighting publishing decorations.
8 /// This is different to the highlightingOn setting, which is whether the user 8 /// This is different to the highlightingOn setting, which is whether the user
9 /// wants our custom highlighting to be used. 9 /// wants our custom highlighting to be used.
10 /// 10 ///
11 /// Defaults to `true` 11 /// Defaults to `false`
12 #[serde(default = "bool_true", deserialize_with = "nullable_bool_true")] 12 #[serde(deserialize_with = "nullable_bool_false")]
13 pub publish_decorations: bool, 13 pub publish_decorations: bool,
14 14
15 /// Whether or not the workspace loaded notification should be sent 15 /// Whether or not the workspace loaded notification should be sent
16 /// 16 ///
17 /// Defaults to `true` 17 /// Defaults to `true`
18 #[serde(default = "bool_true", deserialize_with = "nullable_bool_true")] 18 #[serde(deserialize_with = "nullable_bool_true")]
19 pub show_workspace_loaded: bool, 19 pub show_workspace_loaded: bool,
20} 20}
21 21
22impl Default for InitializationOptions { 22impl Default for InitializationOptions {
23 fn default() -> InitializationOptions { 23 fn default() -> InitializationOptions {
24 InitializationOptions { publish_decorations: true, show_workspace_loaded: true } 24 InitializationOptions { publish_decorations: false, show_workspace_loaded: true }
25 } 25 }
26} 26}
27 27
28fn bool_true() -> bool { 28/// Deserializes a null value to a bool false by default
29 true 29fn nullable_bool_false<'de, D>(deserializer: D) -> Result<bool, D::Error>
30} 30where
31 31 D: Deserializer<'de>,
32/// Deserializes a null value to a bool true by default 32{
33fn nullable_bool_true<'de, D>(deserializer: D) -> Result<bool, D::Error> 33 let opt = Option::deserialize(deserializer)?;
34where 34 Ok(opt.unwrap_or(false))
35 D: Deserializer<'de>, 35}
36{ 36
37 let opt = Option::deserialize(deserializer)?; 37/// Deserializes a null value to a bool true by default
38 Ok(opt.unwrap_or(true)) 38fn nullable_bool_true<'de, D>(deserializer: D) -> Result<bool, D::Error>
39} 39where
40 D: Deserializer<'de>,
41{
42 let opt = Option::deserialize(deserializer)?;
43 Ok(opt.unwrap_or(true))
44}
45
46#[cfg(test)]
47mod test {
48 use super::*;
49
50 #[test]
51 fn deserialize_init_options_defaults() {
52 // check that null == default for both fields
53 let default = InitializationOptions::default();
54 assert_eq!(default, serde_json::from_str(r#"{}"#).unwrap());
55 assert_eq!(
56 default,
57 serde_json::from_str(r#"{"publishDecorations":null, "showWorkspaceLoaded":null}"#)
58 .unwrap()
59 );
60 }
61}