aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-03-09 12:21:28 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-03-09 12:21:28 +0000
commita9d09b7ec0721e9ad305866a57989d1aa9c67ec1 (patch)
treea742956649df98bf14ba75c70ef80f3a814742af
parentbfea379d88f3a46fffb4a9197eae1df889ef306f (diff)
parentc30c5fb4dd7d358126b505ae060a2d2fe3fec0d2 (diff)
Merge #953
953: Don't default publishDecorations and showWorkspaceLoaded to true on the server r=matklad a=flodiebold If the client doesn't specify these explicitly, that very likely means it doesn't know about them and so we shouldn't send them. In particular, the recent change to this default caused decorations to be sent to emacs, resulting in a lot of warning spam. Co-authored-by: Florian Diebold <[email protected]>
-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}