diff options
Diffstat (limited to 'crates/ra_lsp_server/src/init.rs')
-rw-r--r-- | crates/ra_lsp_server/src/init.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/crates/ra_lsp_server/src/init.rs b/crates/ra_lsp_server/src/init.rs new file mode 100644 index 000000000..0b7a47a0b --- /dev/null +++ b/crates/ra_lsp_server/src/init.rs | |||
@@ -0,0 +1,39 @@ | |||
1 | use serde::{Deserialize, Deserializer}; | ||
2 | |||
3 | /// Client provided initialization options | ||
4 | #[derive(Deserialize, Clone, Copy, Debug)] | ||
5 | #[serde(rename_all = "camelCase")] | ||
6 | pub struct InitializationOptions { | ||
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 `true` | ||
12 | #[serde(default = "bool_true", deserialize_with = "nullable_bool_true")] | ||
13 | pub publish_decorations: bool, | ||
14 | |||
15 | /// Whether or not the workspace loaded notification should be sent | ||
16 | /// | ||
17 | /// Defaults to `true` | ||
18 | #[serde(default = "bool_true", deserialize_with = "nullable_bool_true")] | ||
19 | pub show_workspace_loaded: bool, | ||
20 | } | ||
21 | |||
22 | impl Default for InitializationOptions { | ||
23 | fn default() -> InitializationOptions { | ||
24 | InitializationOptions { publish_decorations: true, show_workspace_loaded: true } | ||
25 | } | ||
26 | } | ||
27 | |||
28 | fn bool_true() -> bool { | ||
29 | true | ||
30 | } | ||
31 | |||
32 | /// Deserializes a null value to a bool true by default | ||
33 | fn nullable_bool_true<'de, D>(deserializer: D) -> Result<bool, D::Error> | ||
34 | where | ||
35 | D: Deserializer<'de>, | ||
36 | { | ||
37 | let opt = Option::deserialize(deserializer)?; | ||
38 | Ok(opt.unwrap_or(true)) | ||
39 | } | ||