aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r--crates/ra_lsp_server/src/init.rs39
-rw-r--r--crates/ra_lsp_server/src/lib.rs3
-rw-r--r--crates/ra_lsp_server/src/main.rs20
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs48
-rw-r--r--crates/ra_lsp_server/src/req.rs7
5 files changed, 75 insertions, 42 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 @@
1use serde::{Deserialize, Deserializer};
2
3/// Client provided initialization options
4#[derive(Deserialize, Clone, Copy, Debug)]
5#[serde(rename_all = "camelCase")]
6pub 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
22impl Default for InitializationOptions {
23 fn default() -> InitializationOptions {
24 InitializationOptions { publish_decorations: true, show_workspace_loaded: true }
25 }
26}
27
28fn bool_true() -> bool {
29 true
30}
31
32/// Deserializes a null value to a bool true by default
33fn nullable_bool_true<'de, D>(deserializer: D) -> Result<bool, D::Error>
34where
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;
5mod markdown; 5mod markdown;
6mod project_model; 6mod project_model;
7pub mod req; 7pub mod req;
8pub mod init;
8mod server_world; 9mod server_world;
9 10
10pub type Result<T> = ::std::result::Result<T, ::failure::Error>; 11pub type Result<T> = ::std::result::Result<T, ::failure::Error>;
11pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError}; 12pub 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 03f83c7be..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;
2use flexi_logger::{Duplicate, Logger}; 2use flexi_logger::{Duplicate, Logger};
3use gen_lsp_server::{run_server, stdio_transport}; 3use gen_lsp_server::{run_server, stdio_transport};
4 4
5use ra_lsp_server::Result; 5use ra_lsp_server::{Result, InitializationOptions};
6 6
7fn main() -> Result<()> { 7fn 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")]
29struct 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
36fn main_inner() -> Result<()> { 27fn 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(false, 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 0f8ef10b9..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)]
@@ -46,9 +47,8 @@ enum Task {
46const THREADPOOL_SIZE: usize = 8; 47const THREADPOOL_SIZE: usize = 8;
47 48
48pub fn main_loop( 49pub fn main_loop(
49 internal_mode: bool,
50 ws_root: PathBuf, 50 ws_root: PathBuf,
51 supports_decorations: bool, 51 options: InitializationOptions,
52 msg_receiver: &Receiver<RawMessage>, 52 msg_receiver: &Receiver<RawMessage>,
53 msg_sender: &Sender<RawMessage>, 53 msg_sender: &Sender<RawMessage>,
54) -> Result<()> { 54) -> Result<()> {
@@ -63,11 +63,12 @@ pub fn main_loop(
63 Ok(ws) => vec![ws], 63 Ok(ws) => vec![ws],
64 Err(e) => { 64 Err(e) => {
65 log::error!("loading workspace failed: {}", e); 65 log::error!("loading workspace failed: {}", e);
66 let msg = RawNotification::new::<req::ShowMessage>(&req::ShowMessageParams { 66
67 typ: req::MessageType::Error, 67 show_message(
68 message: format!("rust-analyzer failed to load workspace: {}", e), 68 req::MessageType::Error,
69 }); 69 format!("rust-analyzer failed to load workspace: {}", e),
70 msg_sender.send(msg.into()).unwrap(); 70 msg_sender,
71 );
71 Vec::new() 72 Vec::new()
72 } 73 }
73 } 74 }
@@ -80,8 +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 internal_mode, 84 options,
84 supports_decorations,
85 &pool, 85 &pool,
86 msg_sender, 86 msg_sender,
87 msg_receiver, 87 msg_receiver,
@@ -148,8 +148,7 @@ impl fmt::Debug for Event {
148} 148}
149 149
150fn main_loop_inner( 150fn main_loop_inner(
151 internal_mode: bool, 151 options: InitializationOptions,
152 supports_decorations: bool,
153 pool: &ThreadPool, 152 pool: &ThreadPool,
154 msg_sender: &Sender<RawMessage>, 153 msg_sender: &Sender<RawMessage>,
155 msg_receiver: &Receiver<RawMessage>, 154 msg_receiver: &Receiver<RawMessage>,
@@ -163,6 +162,7 @@ fn main_loop_inner(
163 // time to always have a thread ready to react to input. 162 // time to always have a thread ready to react to input.
164 let mut in_flight_libraries = 0; 163 let mut in_flight_libraries = 0;
165 let mut pending_libraries = Vec::new(); 164 let mut pending_libraries = Vec::new();
165 let mut send_workspace_notification = true;
166 166
167 let (libdata_sender, libdata_receiver) = unbounded(); 167 let (libdata_sender, libdata_receiver) = unbounded();
168 loop { 168 loop {
@@ -190,7 +190,6 @@ fn main_loop_inner(
190 state_changed = true; 190 state_changed = true;
191 } 191 }
192 Event::Lib(lib) => { 192 Event::Lib(lib) => {
193 feedback(internal_mode, "library loaded", msg_sender);
194 state.add_lib(lib); 193 state.add_lib(lib);
195 in_flight_libraries -= 1; 194 in_flight_libraries -= 1;
196 } 195 }
@@ -244,15 +243,23 @@ fn main_loop_inner(
244 }); 243 });
245 } 244 }
246 245
247 if state.roots_to_scan == 0 && pending_libraries.is_empty() && in_flight_libraries == 0 { 246 if send_workspace_notification
248 feedback(internal_mode, "workspace loaded", msg_sender); 247 && state.roots_to_scan == 0
248 && pending_libraries.is_empty()
249 && in_flight_libraries == 0
250 {
251 if options.show_workspace_loaded {
252 show_message(req::MessageType::Info, "workspace loaded", msg_sender);
253 }
254 // Only send the notification first time
255 send_workspace_notification = false;
249 } 256 }
250 257
251 if state_changed { 258 if state_changed {
252 update_file_notifications_on_threadpool( 259 update_file_notifications_on_threadpool(
253 pool, 260 pool,
254 state.snapshot(), 261 state.snapshot(),
255 supports_decorations, 262 options.publish_decorations,
256 task_sender.clone(), 263 task_sender.clone(),
257 subs.subscriptions(), 264 subs.subscriptions(),
258 ) 265 )
@@ -501,11 +508,12 @@ fn update_file_notifications_on_threadpool(
501 }); 508 });
502} 509}
503 510
504fn feedback(intrnal_mode: bool, msg: &str, sender: &Sender<RawMessage>) { 511fn show_message<M: Into<String>>(typ: req::MessageType, msg: M, sender: &Sender<RawMessage>) {
505 if !intrnal_mode { 512 let not = RawNotification::new::<req::ShowMessage>(&req::ShowMessageParams {
506 return; 513 typ,
507 } 514 message: msg.into(),
508 let not = RawNotification::new::<req::InternalFeedback>(&msg.to_string()); 515 });
516
509 sender.send(not.into()).unwrap(); 517 sender.send(not.into()).unwrap();
510} 518}
511 519
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs
index 484fde7e5..e0571fd78 100644
--- a/crates/ra_lsp_server/src/req.rs
+++ b/crates/ra_lsp_server/src/req.rs
@@ -172,10 +172,3 @@ pub struct SourceChange {
172 pub workspace_edit: WorkspaceEdit, 172 pub workspace_edit: WorkspaceEdit,
173 pub cursor_position: Option<TextDocumentPositionParams>, 173 pub cursor_position: Option<TextDocumentPositionParams>,
174} 174}
175
176pub enum InternalFeedback {}
177
178impl Notification for InternalFeedback {
179 const METHOD: &'static str = "internalFeedback";
180 type Params = String;
181}