aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
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
parente477b8745542d5ac85b2cbbb3be2eb0df22486cd (diff)
modernize more
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/src/lib.rs12
-rw-r--r--crates/ra_lsp_server/src/main.rs22
-rw-r--r--crates/ra_lsp_server/src/main_loop/mod.rs38
-rw-r--r--crates/ra_lsp_server/src/project_model.rs4
-rw-r--r--crates/ra_lsp_server/src/req.rs1
-rw-r--r--crates/ra_lsp_server/src/server_world.rs1
-rw-r--r--crates/ra_lsp_server/src/thread_watcher.rs7
-rw-r--r--crates/ra_lsp_server/src/vfs.rs8
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/main.rs3
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/support.rs2
10 files changed, 42 insertions, 56 deletions
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs
index e370be554..75c6fa1b8 100644
--- a/crates/ra_lsp_server/src/lib.rs
+++ b/crates/ra_lsp_server/src/lib.rs
@@ -1,15 +1,3 @@
1#[macro_use]
2extern crate failure;
3#[macro_use]
4extern crate serde_derive;
5#[macro_use]
6extern crate crossbeam_channel;
7#[macro_use]
8extern crate log;
9#[macro_use]
10extern crate failure_derive;
11
12
13mod caps; 1mod caps;
14mod conv; 2mod conv;
15mod main_loop; 3mod main_loop;
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs
index a50ac76ff..9ba972562 100644
--- a/crates/ra_lsp_server/src/main.rs
+++ b/crates/ra_lsp_server/src/main.rs
@@ -1,11 +1,5 @@
1#[macro_use] 1use serde_derive::Deserialize;
2extern crate log; 2use serde::Deserialize as _D;
3#[macro_use]
4extern crate failure;
5#[macro_use]
6extern crate serde_derive;
7
8use serde::Deserialize;
9use flexi_logger::{Duplicate, Logger}; 3use flexi_logger::{Duplicate, Logger};
10use gen_lsp_server::{run_server, stdio_transport}; 4use gen_lsp_server::{run_server, stdio_transport};
11use ra_lsp_server::Result; 5use ra_lsp_server::Result;
@@ -17,15 +11,15 @@ fn main() -> Result<()> {
17 .log_to_file() 11 .log_to_file()
18 .directory("log") 12 .directory("log")
19 .start()?; 13 .start()?;
20 info!("lifecycle: server started"); 14 log::info!("lifecycle: server started");
21 match ::std::panic::catch_unwind(main_inner) { 15 match ::std::panic::catch_unwind(main_inner) {
22 Ok(res) => { 16 Ok(res) => {
23 info!("lifecycle: terminating process with {:?}", res); 17 log::info!("lifecycle: terminating process with {:?}", res);
24 res 18 res
25 } 19 }
26 Err(_) => { 20 Err(_) => {
27 error!("server panicked"); 21 log::error!("server panicked");
28 bail!("server panicked") 22 failure::bail!("server panicked")
29 } 23 }
30 } 24 }
31} 25}
@@ -56,8 +50,8 @@ fn main_inner() -> Result<()> {
56 ra_lsp_server::main_loop(false, root, publish_decorations, r, s) 50 ra_lsp_server::main_loop(false, root, publish_decorations, r, s)
57 }, 51 },
58 )?; 52 )?;
59 info!("shutting down IO..."); 53 log::info!("shutting down IO...");
60 threads.join()?; 54 threads.join()?;
61 info!("... IO is down"); 55 log::info!("... IO is down");
62 Ok(()) 56 Ok(())
63} 57}
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) => {
diff --git a/crates/ra_lsp_server/src/project_model.rs b/crates/ra_lsp_server/src/project_model.rs
index cabb336a3..3305d468a 100644
--- a/crates/ra_lsp_server/src/project_model.rs
+++ b/crates/ra_lsp_server/src/project_model.rs
@@ -1,12 +1,14 @@
1use std::path::{Path, PathBuf}; 1use std::path::{Path, PathBuf};
2 2
3use serde_derive::Serialize;
3use cargo_metadata::{metadata_run, CargoOpt}; 4use cargo_metadata::{metadata_run, CargoOpt};
4use ra_syntax::SmolStr; 5use ra_syntax::SmolStr;
5use rustc_hash::{FxHashMap, FxHashSet}; 6use rustc_hash::{FxHashMap, FxHashSet};
7use failure::{format_err, bail};
6 8
7use crate::{ 9use crate::{
8 thread_watcher::{ThreadWatcher, Worker},
9 Result, 10 Result,
11 thread_watcher::{ThreadWatcher, Worker},
10}; 12};
11 13
12#[derive(Debug, Clone)] 14#[derive(Debug, Clone)]
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs
index fcb7e94e1..999792ecb 100644
--- a/crates/ra_lsp_server/src/req.rs
+++ b/crates/ra_lsp_server/src/req.rs
@@ -1,3 +1,4 @@
1use serde_derive::{Serialize, Deserialize};
1use languageserver_types::{Location, Position, Range, TextDocumentIdentifier, Url}; 2use languageserver_types::{Location, Position, Range, TextDocumentIdentifier, Url};
2use rustc_hash::FxHashMap; 3use rustc_hash::FxHashMap;
3use url_serde; 4use url_serde;
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs
index 12faeb93a..c3f89ad5f 100644
--- a/crates/ra_lsp_server/src/server_world.rs
+++ b/crates/ra_lsp_server/src/server_world.rs
@@ -9,6 +9,7 @@ use ra_analysis::{
9 Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FileResolver, LibraryData, 9 Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FileResolver, LibraryData,
10}; 10};
11use rustc_hash::FxHashMap; 11use rustc_hash::FxHashMap;
12use failure::{bail, format_err};
12 13
13use crate::{ 14use crate::{
14 path_map::{PathMap, Root}, 15 path_map::{PathMap, Root},
diff --git a/crates/ra_lsp_server/src/thread_watcher.rs b/crates/ra_lsp_server/src/thread_watcher.rs
index 5143c77ae..99825d440 100644
--- a/crates/ra_lsp_server/src/thread_watcher.rs
+++ b/crates/ra_lsp_server/src/thread_watcher.rs
@@ -2,6 +2,7 @@ use std::thread;
2 2
3use crossbeam_channel::{bounded, unbounded, Receiver, Sender}; 3use crossbeam_channel::{bounded, unbounded, Receiver, Sender};
4use drop_bomb::DropBomb; 4use drop_bomb::DropBomb;
5use failure::format_err;
5 6
6use crate::Result; 7use crate::Result;
7 8
@@ -48,7 +49,7 @@ impl ThreadWatcher {
48 } 49 }
49 50
50 pub fn stop(mut self) -> Result<()> { 51 pub fn stop(mut self) -> Result<()> {
51 info!("waiting for {} to finish ...", self.name); 52 log::info!("waiting for {} to finish ...", self.name);
52 let name = self.name; 53 let name = self.name;
53 self.bomb.defuse(); 54 self.bomb.defuse();
54 let res = self 55 let res = self
@@ -56,8 +57,8 @@ impl ThreadWatcher {
56 .join() 57 .join()
57 .map_err(|_| format_err!("ThreadWatcher {} died", name)); 58 .map_err(|_| format_err!("ThreadWatcher {} died", name));
58 match &res { 59 match &res {
59 Ok(()) => info!("... {} terminated with ok", name), 60 Ok(()) => log::info!("... {} terminated with ok", name),
60 Err(_) => error!("... {} terminated with err", name), 61 Err(_) => log::error!("... {} terminated with err", name),
61 } 62 }
62 res 63 res
63 } 64 }
diff --git a/crates/ra_lsp_server/src/vfs.rs b/crates/ra_lsp_server/src/vfs.rs
index 6e317d854..00ab3e6c3 100644
--- a/crates/ra_lsp_server/src/vfs.rs
+++ b/crates/ra_lsp_server/src/vfs.rs
@@ -25,9 +25,9 @@ pub fn roots_loader() -> (Worker<PathBuf, (PathBuf, Vec<FileEvent>)>, ThreadWatc
25 |input_receiver, output_sender| { 25 |input_receiver, output_sender| {
26 input_receiver 26 input_receiver
27 .map(|path| { 27 .map(|path| {
28 debug!("loading {} ...", path.as_path().display()); 28 log::debug!("loading {} ...", path.as_path().display());
29 let events = load_root(path.as_path()); 29 let events = load_root(path.as_path());
30 debug!("... loaded {}", path.as_path().display()); 30 log::debug!("... loaded {}", path.as_path().display());
31 (path, events) 31 (path, events)
32 }) 32 })
33 .for_each(|it| output_sender.send(it)) 33 .for_each(|it| output_sender.send(it))
@@ -41,7 +41,7 @@ fn load_root(path: &Path) -> Vec<FileEvent> {
41 let entry = match entry { 41 let entry = match entry {
42 Ok(entry) => entry, 42 Ok(entry) => entry,
43 Err(e) => { 43 Err(e) => {
44 warn!("watcher error: {}", e); 44 log::warn!("watcher error: {}", e);
45 continue; 45 continue;
46 } 46 }
47 }; 47 };
@@ -55,7 +55,7 @@ fn load_root(path: &Path) -> Vec<FileEvent> {
55 let text = match fs::read_to_string(path) { 55 let text = match fs::read_to_string(path) {
56 Ok(text) => text, 56 Ok(text) => text,
57 Err(e) => { 57 Err(e) => {
58 warn!("watcher error: {}", e); 58 log::warn!("watcher error: {}", e);
59 continue; 59 continue;
60 } 60 }
61 }; 61 };
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs
index bcb854fef..cbc0c8844 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/main.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs
@@ -1,6 +1,3 @@
1#[macro_use]
2extern crate crossbeam_channel;
3
4mod support; 1mod support;
5 2
6use ra_lsp_server::req::{Runnables, RunnablesParams}; 3use ra_lsp_server::req::{Runnables, RunnablesParams};
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs
index 88d379bfa..019048a3a 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/support.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs
@@ -6,7 +6,7 @@ use std::{
6 time::Duration, 6 time::Duration,
7}; 7};
8 8
9use crossbeam_channel::{after, Receiver}; 9use crossbeam_channel::{after, select, Receiver};
10use flexi_logger::Logger; 10use flexi_logger::Logger;
11use gen_lsp_server::{RawMessage, RawNotification, RawRequest}; 11use gen_lsp_server::{RawMessage, RawNotification, RawRequest};
12use languageserver_types::{ 12use languageserver_types::{