diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_lsp_server/src/init.rs | 39 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/lib.rs | 3 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main.rs | 20 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 13 | ||||
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/support.rs | 9 |
5 files changed, 63 insertions, 21 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 | } | ||
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs index 5b5f3b948..59e16a47c 100644 --- a/crates/ra_lsp_server/src/lib.rs +++ b/crates/ra_lsp_server/src/lib.rs | |||
@@ -5,7 +5,8 @@ mod main_loop; | |||
5 | mod markdown; | 5 | mod markdown; |
6 | mod project_model; | 6 | mod project_model; |
7 | pub mod req; | 7 | pub mod req; |
8 | pub mod init; | ||
8 | mod server_world; | 9 | mod server_world; |
9 | 10 | ||
10 | pub type Result<T> = ::std::result::Result<T, ::failure::Error>; | 11 | pub type Result<T> = ::std::result::Result<T, ::failure::Error>; |
11 | pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError}; | 12 | pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError, init::InitializationOptions}; |
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index 9dc2e3f87..5a2905207 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs | |||
@@ -2,7 +2,7 @@ use serde::Deserialize; | |||
2 | use flexi_logger::{Duplicate, Logger}; | 2 | use flexi_logger::{Duplicate, Logger}; |
3 | use gen_lsp_server::{run_server, stdio_transport}; | 3 | use gen_lsp_server::{run_server, stdio_transport}; |
4 | 4 | ||
5 | use ra_lsp_server::Result; | 5 | use ra_lsp_server::{Result, InitializationOptions}; |
6 | 6 | ||
7 | fn main() -> Result<()> { | 7 | fn main() -> Result<()> { |
8 | ::std::env::set_var("RUST_BACKTRACE", "short"); | 8 | ::std::env::set_var("RUST_BACKTRACE", "short"); |
@@ -24,26 +24,18 @@ fn main() -> Result<()> { | |||
24 | } | 24 | } |
25 | } | 25 | } |
26 | 26 | ||
27 | #[derive(Deserialize)] | ||
28 | #[serde(rename_all = "camelCase")] | ||
29 | struct InitializationOptions { | ||
30 | // Whether the client supports our custom highlighting publishing decorations. | ||
31 | // This is different to the highlightingOn setting, which is whether the user | ||
32 | // wants our custom highlighting to be used. | ||
33 | publish_decorations: Option<bool>, | ||
34 | } | ||
35 | |||
36 | fn main_inner() -> Result<()> { | 27 | fn main_inner() -> Result<()> { |
37 | let (receiver, sender, threads) = stdio_transport(); | 28 | let (receiver, sender, threads) = stdio_transport(); |
38 | let cwd = ::std::env::current_dir()?; | 29 | let cwd = ::std::env::current_dir()?; |
39 | run_server(ra_lsp_server::server_capabilities(), receiver, sender, |params, r, s| { | 30 | run_server(ra_lsp_server::server_capabilities(), receiver, sender, |params, r, s| { |
40 | let root = params.root_uri.and_then(|it| it.to_file_path().ok()).unwrap_or(cwd); | 31 | let root = params.root_uri.and_then(|it| it.to_file_path().ok()).unwrap_or(cwd); |
41 | let supports_decorations = params | 32 | |
33 | let opts = params | ||
42 | .initialization_options | 34 | .initialization_options |
43 | .and_then(|v| InitializationOptions::deserialize(v).ok()) | 35 | .and_then(|v| InitializationOptions::deserialize(v).ok()) |
44 | .and_then(|it| it.publish_decorations) | 36 | .unwrap_or(InitializationOptions::default()); |
45 | == Some(true); | 37 | |
46 | ra_lsp_server::main_loop(root, supports_decorations, r, s) | 38 | ra_lsp_server::main_loop(root, opts, r, s) |
47 | })?; | 39 | })?; |
48 | log::info!("shutting down IO..."); | 40 | log::info!("shutting down IO..."); |
49 | threads.join()?; | 41 | threads.join()?; |
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index fb2305b26..d0c2a95ef 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -22,6 +22,7 @@ use crate::{ | |||
22 | req, | 22 | req, |
23 | server_world::{ServerWorld, ServerWorldState}, | 23 | server_world::{ServerWorld, ServerWorldState}, |
24 | Result, | 24 | Result, |
25 | InitializationOptions, | ||
25 | }; | 26 | }; |
26 | 27 | ||
27 | #[derive(Debug, Fail)] | 28 | #[derive(Debug, Fail)] |
@@ -47,7 +48,7 @@ const THREADPOOL_SIZE: usize = 8; | |||
47 | 48 | ||
48 | pub fn main_loop( | 49 | pub fn main_loop( |
49 | ws_root: PathBuf, | 50 | ws_root: PathBuf, |
50 | supports_decorations: bool, | 51 | options: InitializationOptions, |
51 | msg_receiver: &Receiver<RawMessage>, | 52 | msg_receiver: &Receiver<RawMessage>, |
52 | msg_sender: &Sender<RawMessage>, | 53 | msg_sender: &Sender<RawMessage>, |
53 | ) -> Result<()> { | 54 | ) -> Result<()> { |
@@ -80,7 +81,7 @@ pub fn main_loop( | |||
80 | let mut pending_requests = FxHashSet::default(); | 81 | let mut pending_requests = FxHashSet::default(); |
81 | let mut subs = Subscriptions::new(); | 82 | let mut subs = Subscriptions::new(); |
82 | let main_res = main_loop_inner( | 83 | let main_res = main_loop_inner( |
83 | supports_decorations, | 84 | options, |
84 | &pool, | 85 | &pool, |
85 | msg_sender, | 86 | msg_sender, |
86 | msg_receiver, | 87 | msg_receiver, |
@@ -147,7 +148,7 @@ impl fmt::Debug for Event { | |||
147 | } | 148 | } |
148 | 149 | ||
149 | fn main_loop_inner( | 150 | fn main_loop_inner( |
150 | supports_decorations: bool, | 151 | options: InitializationOptions, |
151 | pool: &ThreadPool, | 152 | pool: &ThreadPool, |
152 | msg_sender: &Sender<RawMessage>, | 153 | msg_sender: &Sender<RawMessage>, |
153 | msg_receiver: &Receiver<RawMessage>, | 154 | msg_receiver: &Receiver<RawMessage>, |
@@ -247,7 +248,9 @@ fn main_loop_inner( | |||
247 | && pending_libraries.is_empty() | 248 | && pending_libraries.is_empty() |
248 | && in_flight_libraries == 0 | 249 | && in_flight_libraries == 0 |
249 | { | 250 | { |
250 | show_message(req::MessageType::Info, "workspace loaded", msg_sender); | 251 | if options.show_workspace_loaded { |
252 | show_message(req::MessageType::Info, "workspace loaded", msg_sender); | ||
253 | } | ||
251 | // Only send the notification first time | 254 | // Only send the notification first time |
252 | send_workspace_notification = false; | 255 | send_workspace_notification = false; |
253 | } | 256 | } |
@@ -256,7 +259,7 @@ fn main_loop_inner( | |||
256 | update_file_notifications_on_threadpool( | 259 | update_file_notifications_on_threadpool( |
257 | pool, | 260 | pool, |
258 | state.snapshot(), | 261 | state.snapshot(), |
259 | supports_decorations, | 262 | options.publish_decorations, |
260 | task_sender.clone(), | 263 | task_sender.clone(), |
261 | subs.subscriptions(), | 264 | subs.subscriptions(), |
262 | ) | 265 | ) |
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs index 08f7ad6fd..8bfc8d622 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/support.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs | |||
@@ -23,6 +23,7 @@ use test_utils::{parse_fixture, find_mismatch}; | |||
23 | 23 | ||
24 | use ra_lsp_server::{ | 24 | use ra_lsp_server::{ |
25 | main_loop, req, | 25 | main_loop, req, |
26 | InitializationOptions, | ||
26 | }; | 27 | }; |
27 | 28 | ||
28 | pub fn project(fixture: &str) -> Server { | 29 | pub fn project(fixture: &str) -> Server { |
@@ -57,7 +58,13 @@ impl Server { | |||
57 | "test server", | 58 | "test server", |
58 | 128, | 59 | 128, |
59 | move |mut msg_receiver, mut msg_sender| { | 60 | move |mut msg_receiver, mut msg_sender| { |
60 | main_loop(path, true, &mut msg_receiver, &mut msg_sender).unwrap() | 61 | main_loop( |
62 | path, | ||
63 | InitializationOptions::default(), | ||
64 | &mut msg_receiver, | ||
65 | &mut msg_sender, | ||
66 | ) | ||
67 | .unwrap() | ||
61 | }, | 68 | }, |
62 | ); | 69 | ); |
63 | let res = Server { | 70 | let res = Server { |