aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/main_loop/mod.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-06 18:03:39 +0000
committerAleksey Kladov <[email protected]>2018-12-06 18:03:39 +0000
commitf6e8b376d1d21b8b697de5ef1e35a341855202ed (patch)
tree395282e236ea516d4ed57e4771d3aae4eba0029b /crates/ra_lsp_server/src/main_loop/mod.rs
parente477b8745542d5ac85b2cbbb3be2eb0df22486cd (diff)
modernize more
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop/mod.rs')
-rw-r--r--crates/ra_lsp_server/src/main_loop/mod.rs38
1 files changed, 20 insertions, 18 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs
index 36f08be2f..0e1878906 100644
--- a/crates/ra_lsp_server/src/main_loop/mod.rs
+++ b/crates/ra_lsp_server/src/main_loop/mod.rs
@@ -3,7 +3,7 @@ mod subscriptions;
3 3
4use std::path::PathBuf; 4use std::path::PathBuf;
5 5
6use crossbeam_channel::{unbounded, Receiver, Sender}; 6use crossbeam_channel::{unbounded, select, Receiver, Sender};
7use gen_lsp_server::{ 7use gen_lsp_server::{
8 handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, 8 handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse,
9}; 9};
@@ -12,6 +12,8 @@ use ra_analysis::{Canceled, FileId, LibraryData};
12use rayon::{self, ThreadPool}; 12use rayon::{self, ThreadPool};
13use rustc_hash::FxHashSet; 13use rustc_hash::FxHashSet;
14use serde::{de::DeserializeOwned, Serialize}; 14use serde::{de::DeserializeOwned, Serialize};
15use failure::{format_err, bail};
16use failure_derive::Fail;
15 17
16use crate::{ 18use crate::{
17 main_loop::subscriptions::Subscriptions, 19 main_loop::subscriptions::Subscriptions,
@@ -54,14 +56,14 @@ pub fn main_loop(
54) -> Result<()> { 56) -> Result<()> {
55 let pool = rayon::ThreadPoolBuilder::new() 57 let pool = rayon::ThreadPoolBuilder::new()
56 .num_threads(4) 58 .num_threads(4)
57 .panic_handler(|_| error!("thread panicked :(")) 59 .panic_handler(|_| log::error!("thread panicked :("))
58 .build() 60 .build()
59 .unwrap(); 61 .unwrap();
60 let (task_sender, task_receiver) = unbounded::<Task>(); 62 let (task_sender, task_receiver) = unbounded::<Task>();
61 let (fs_worker, fs_watcher) = vfs::roots_loader(); 63 let (fs_worker, fs_watcher) = vfs::roots_loader();
62 let (ws_worker, ws_watcher) = workspace_loader(); 64 let (ws_worker, ws_watcher) = workspace_loader();
63 65
64 info!("server initialized, serving requests"); 66 log::info!("server initialized, serving requests");
65 let mut state = ServerWorldState::default(); 67 let mut state = ServerWorldState::default();
66 68
67 let mut pending_requests = FxHashSet::default(); 69 let mut pending_requests = FxHashSet::default();
@@ -82,12 +84,12 @@ pub fn main_loop(
82 &mut subs, 84 &mut subs,
83 ); 85 );
84 86
85 info!("waiting for tasks to finish..."); 87 log::info!("waiting for tasks to finish...");
86 task_receiver.for_each(|task| on_task(task, msg_sender, &mut pending_requests)); 88 task_receiver.for_each(|task| on_task(task, msg_sender, &mut pending_requests));
87 info!("...tasks have finished"); 89 log::info!("...tasks have finished");
88 info!("joining threadpool..."); 90 log::info!("joining threadpool...");
89 drop(pool); 91 drop(pool);
90 info!("...threadpool has finished"); 92 log::info!("...threadpool has finished");
91 93
92 let fs_res = fs_watcher.stop(); 94 let fs_res = fs_watcher.stop();
93 let ws_res = ws_watcher.stop(); 95 let ws_res = ws_watcher.stop();
@@ -126,7 +128,7 @@ fn main_loop_inner(
126 Ws(Result<CargoWorkspace>), 128 Ws(Result<CargoWorkspace>),
127 Lib(LibraryData), 129 Lib(LibraryData),
128 } 130 }
129 trace!("selecting"); 131 log::trace!("selecting");
130 let event = select! { 132 let event = select! {
131 recv(msg_receiver, msg) => match msg { 133 recv(msg_receiver, msg) => match msg {
132 Some(msg) => Event::Msg(msg), 134 Some(msg) => Event::Msg(msg),
@@ -147,7 +149,7 @@ fn main_loop_inner(
147 match event { 149 match event {
148 Event::Task(task) => on_task(task, msg_sender, pending_requests), 150 Event::Task(task) => on_task(task, msg_sender, pending_requests),
149 Event::Fs(root, events) => { 151 Event::Fs(root, events) => {
150 info!("fs change, {}, {} events", root.display(), events.len()); 152 log::info!("fs change, {}, {} events", root.display(), events.len());
151 if root == ws_root { 153 if root == ws_root {
152 state.apply_fs_changes(events); 154 state.apply_fs_changes(events);
153 } else { 155 } else {
@@ -155,9 +157,9 @@ fn main_loop_inner(
155 let sender = libdata_sender.clone(); 157 let sender = libdata_sender.clone();
156 pool.spawn(move || { 158 pool.spawn(move || {
157 let start = ::std::time::Instant::now(); 159 let start = ::std::time::Instant::now();
158 info!("indexing {} ... ", root.display()); 160 log::info!("indexing {} ... ", root.display());
159 let data = LibraryData::prepare(files, resolver); 161 let data = LibraryData::prepare(files, resolver);
160 info!("indexed {:?} {}", start.elapsed(), root.display()); 162 log::info!("indexed {:?} {}", start.elapsed(), root.display());
161 sender.send(data); 163 sender.send(data);
162 }); 164 });
163 } 165 }
@@ -195,14 +197,14 @@ fn main_loop_inner(
195 .map(|(_idx, root)| root); 197 .map(|(_idx, root)| root);
196 198
197 for root in unique { 199 for root in unique {
198 debug!("sending root, {}", root.display()); 200 log::debug!("sending root, {}", root.display());
199 fs_worker.send(root.to_owned()); 201 fs_worker.send(root.to_owned());
200 } 202 }
201 } 203 }
202 state.set_workspaces(workspaces); 204 state.set_workspaces(workspaces);
203 state_changed = true; 205 state_changed = true;
204 } 206 }
205 Err(e) => warn!("loading workspace failed: {}", e), 207 Err(e) => log::warn!("loading workspace failed: {}", e),
206 }, 208 },
207 Event::Lib(lib) => { 209 Event::Lib(lib) => {
208 feedback(internal_mode, "library loaded", msg_sender); 210 feedback(internal_mode, "library loaded", msg_sender);
@@ -217,7 +219,7 @@ fn main_loop_inner(
217 match on_request(state, pending_requests, pool, &task_sender, req)? { 219 match on_request(state, pending_requests, pool, &task_sender, req)? {
218 None => (), 220 None => (),
219 Some(req) => { 221 Some(req) => {
220 error!("unknown request: {:?}", req); 222 log::error!("unknown request: {:?}", req);
221 let resp = RawResponse::err( 223 let resp = RawResponse::err(
222 req.id, 224 req.id,
223 ErrorCode::MethodNotFound as i32, 225 ErrorCode::MethodNotFound as i32,
@@ -231,7 +233,7 @@ fn main_loop_inner(
231 on_notification(msg_sender, state, pending_requests, subs, not)?; 233 on_notification(msg_sender, state, pending_requests, subs, not)?;
232 state_changed = true; 234 state_changed = true;
233 } 235 }
234 RawMessage::Response(resp) => error!("unexpected response: {:?}", resp), 236 RawMessage::Response(resp) => log::error!("unexpected response: {:?}", resp),
235 }, 237 },
236 }; 238 };
237 239
@@ -370,7 +372,7 @@ fn on_notification(
370 } 372 }
371 Err(not) => not, 373 Err(not) => not,
372 }; 374 };
373 error!("unhandled notification: {:?}", not); 375 log::error!("unhandled notification: {:?}", not);
374 Ok(()) 376 Ok(())
375} 377}
376 378
@@ -455,7 +457,7 @@ fn update_file_notifications_on_threadpool(
455 match handlers::publish_diagnostics(&world, file_id) { 457 match handlers::publish_diagnostics(&world, file_id) {
456 Err(e) => { 458 Err(e) => {
457 if !is_canceled(&e) { 459 if !is_canceled(&e) {
458 error!("failed to compute diagnostics: {:?}", e); 460 log::error!("failed to compute diagnostics: {:?}", e);
459 } 461 }
460 } 462 }
461 Ok(params) => { 463 Ok(params) => {
@@ -467,7 +469,7 @@ fn update_file_notifications_on_threadpool(
467 match handlers::publish_decorations(&world, file_id) { 469 match handlers::publish_decorations(&world, file_id) {
468 Err(e) => { 470 Err(e) => {
469 if !is_canceled(&e) { 471 if !is_canceled(&e) {
470 error!("failed to compute decorations: {:?}", e); 472 log::error!("failed to compute decorations: {:?}", e);
471 } 473 }
472 } 474 }
473 Ok(params) => { 475 Ok(params) => {