modernize more

This commit is contained in:
Aleksey Kladov 2018-12-06 21:03:39 +03:00
parent e477b87455
commit f6e8b376d1
10 changed files with 42 additions and 56 deletions

View file

@ -1,15 +1,3 @@
#[macro_use]
extern crate failure;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate crossbeam_channel;
#[macro_use]
extern crate log;
#[macro_use]
extern crate failure_derive;
mod caps;
mod conv;
mod main_loop;

View file

@ -1,11 +1,5 @@
#[macro_use]
extern crate log;
#[macro_use]
extern crate failure;
#[macro_use]
extern crate serde_derive;
use serde::Deserialize;
use serde_derive::Deserialize;
use serde::Deserialize as _D;
use flexi_logger::{Duplicate, Logger};
use gen_lsp_server::{run_server, stdio_transport};
use ra_lsp_server::Result;
@ -17,15 +11,15 @@ fn main() -> Result<()> {
.log_to_file()
.directory("log")
.start()?;
info!("lifecycle: server started");
log::info!("lifecycle: server started");
match ::std::panic::catch_unwind(main_inner) {
Ok(res) => {
info!("lifecycle: terminating process with {:?}", res);
log::info!("lifecycle: terminating process with {:?}", res);
res
}
Err(_) => {
error!("server panicked");
bail!("server panicked")
log::error!("server panicked");
failure::bail!("server panicked")
}
}
}
@ -56,8 +50,8 @@ fn main_inner() -> Result<()> {
ra_lsp_server::main_loop(false, root, publish_decorations, r, s)
},
)?;
info!("shutting down IO...");
log::info!("shutting down IO...");
threads.join()?;
info!("... IO is down");
log::info!("... IO is down");
Ok(())
}

View file

@ -3,7 +3,7 @@ mod subscriptions;
use std::path::PathBuf;
use crossbeam_channel::{unbounded, Receiver, Sender};
use crossbeam_channel::{unbounded, select, Receiver, Sender};
use gen_lsp_server::{
handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse,
};
@ -12,6 +12,8 @@ use ra_analysis::{Canceled, FileId, LibraryData};
use rayon::{self, ThreadPool};
use rustc_hash::FxHashSet;
use serde::{de::DeserializeOwned, Serialize};
use failure::{format_err, bail};
use failure_derive::Fail;
use crate::{
main_loop::subscriptions::Subscriptions,
@ -54,14 +56,14 @@ pub fn main_loop(
) -> Result<()> {
let pool = rayon::ThreadPoolBuilder::new()
.num_threads(4)
.panic_handler(|_| error!("thread panicked :("))
.panic_handler(|_| log::error!("thread panicked :("))
.build()
.unwrap();
let (task_sender, task_receiver) = unbounded::<Task>();
let (fs_worker, fs_watcher) = vfs::roots_loader();
let (ws_worker, ws_watcher) = workspace_loader();
info!("server initialized, serving requests");
log::info!("server initialized, serving requests");
let mut state = ServerWorldState::default();
let mut pending_requests = FxHashSet::default();
@ -82,12 +84,12 @@ pub fn main_loop(
&mut subs,
);
info!("waiting for tasks to finish...");
log::info!("waiting for tasks to finish...");
task_receiver.for_each(|task| on_task(task, msg_sender, &mut pending_requests));
info!("...tasks have finished");
info!("joining threadpool...");
log::info!("...tasks have finished");
log::info!("joining threadpool...");
drop(pool);
info!("...threadpool has finished");
log::info!("...threadpool has finished");
let fs_res = fs_watcher.stop();
let ws_res = ws_watcher.stop();
@ -126,7 +128,7 @@ fn main_loop_inner(
Ws(Result<CargoWorkspace>),
Lib(LibraryData),
}
trace!("selecting");
log::trace!("selecting");
let event = select! {
recv(msg_receiver, msg) => match msg {
Some(msg) => Event::Msg(msg),
@ -147,7 +149,7 @@ fn main_loop_inner(
match event {
Event::Task(task) => on_task(task, msg_sender, pending_requests),
Event::Fs(root, events) => {
info!("fs change, {}, {} events", root.display(), events.len());
log::info!("fs change, {}, {} events", root.display(), events.len());
if root == ws_root {
state.apply_fs_changes(events);
} else {
@ -155,9 +157,9 @@ fn main_loop_inner(
let sender = libdata_sender.clone();
pool.spawn(move || {
let start = ::std::time::Instant::now();
info!("indexing {} ... ", root.display());
log::info!("indexing {} ... ", root.display());
let data = LibraryData::prepare(files, resolver);
info!("indexed {:?} {}", start.elapsed(), root.display());
log::info!("indexed {:?} {}", start.elapsed(), root.display());
sender.send(data);
});
}
@ -195,14 +197,14 @@ fn main_loop_inner(
.map(|(_idx, root)| root);
for root in unique {
debug!("sending root, {}", root.display());
log::debug!("sending root, {}", root.display());
fs_worker.send(root.to_owned());
}
}
state.set_workspaces(workspaces);
state_changed = true;
}
Err(e) => warn!("loading workspace failed: {}", e),
Err(e) => log::warn!("loading workspace failed: {}", e),
},
Event::Lib(lib) => {
feedback(internal_mode, "library loaded", msg_sender);
@ -217,7 +219,7 @@ fn main_loop_inner(
match on_request(state, pending_requests, pool, &task_sender, req)? {
None => (),
Some(req) => {
error!("unknown request: {:?}", req);
log::error!("unknown request: {:?}", req);
let resp = RawResponse::err(
req.id,
ErrorCode::MethodNotFound as i32,
@ -231,7 +233,7 @@ fn main_loop_inner(
on_notification(msg_sender, state, pending_requests, subs, not)?;
state_changed = true;
}
RawMessage::Response(resp) => error!("unexpected response: {:?}", resp),
RawMessage::Response(resp) => log::error!("unexpected response: {:?}", resp),
},
};
@ -370,7 +372,7 @@ fn on_notification(
}
Err(not) => not,
};
error!("unhandled notification: {:?}", not);
log::error!("unhandled notification: {:?}", not);
Ok(())
}
@ -455,7 +457,7 @@ fn update_file_notifications_on_threadpool(
match handlers::publish_diagnostics(&world, file_id) {
Err(e) => {
if !is_canceled(&e) {
error!("failed to compute diagnostics: {:?}", e);
log::error!("failed to compute diagnostics: {:?}", e);
}
}
Ok(params) => {
@ -467,7 +469,7 @@ fn update_file_notifications_on_threadpool(
match handlers::publish_decorations(&world, file_id) {
Err(e) => {
if !is_canceled(&e) {
error!("failed to compute decorations: {:?}", e);
log::error!("failed to compute decorations: {:?}", e);
}
}
Ok(params) => {

View file

@ -1,12 +1,14 @@
use std::path::{Path, PathBuf};
use serde_derive::Serialize;
use cargo_metadata::{metadata_run, CargoOpt};
use ra_syntax::SmolStr;
use rustc_hash::{FxHashMap, FxHashSet};
use failure::{format_err, bail};
use crate::{
thread_watcher::{ThreadWatcher, Worker},
Result,
thread_watcher::{ThreadWatcher, Worker},
};
#[derive(Debug, Clone)]

View file

@ -1,3 +1,4 @@
use serde_derive::{Serialize, Deserialize};
use languageserver_types::{Location, Position, Range, TextDocumentIdentifier, Url};
use rustc_hash::FxHashMap;
use url_serde;

View file

@ -9,6 +9,7 @@ use ra_analysis::{
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FileResolver, LibraryData,
};
use rustc_hash::FxHashMap;
use failure::{bail, format_err};
use crate::{
path_map::{PathMap, Root},

View file

@ -2,6 +2,7 @@ use std::thread;
use crossbeam_channel::{bounded, unbounded, Receiver, Sender};
use drop_bomb::DropBomb;
use failure::format_err;
use crate::Result;
@ -48,7 +49,7 @@ impl ThreadWatcher {
}
pub fn stop(mut self) -> Result<()> {
info!("waiting for {} to finish ...", self.name);
log::info!("waiting for {} to finish ...", self.name);
let name = self.name;
self.bomb.defuse();
let res = self
@ -56,8 +57,8 @@ impl ThreadWatcher {
.join()
.map_err(|_| format_err!("ThreadWatcher {} died", name));
match &res {
Ok(()) => info!("... {} terminated with ok", name),
Err(_) => error!("... {} terminated with err", name),
Ok(()) => log::info!("... {} terminated with ok", name),
Err(_) => log::error!("... {} terminated with err", name),
}
res
}

View file

@ -25,9 +25,9 @@ pub fn roots_loader() -> (Worker<PathBuf, (PathBuf, Vec<FileEvent>)>, ThreadWatc
|input_receiver, output_sender| {
input_receiver
.map(|path| {
debug!("loading {} ...", path.as_path().display());
log::debug!("loading {} ...", path.as_path().display());
let events = load_root(path.as_path());
debug!("... loaded {}", path.as_path().display());
log::debug!("... loaded {}", path.as_path().display());
(path, events)
})
.for_each(|it| output_sender.send(it))
@ -41,7 +41,7 @@ fn load_root(path: &Path) -> Vec<FileEvent> {
let entry = match entry {
Ok(entry) => entry,
Err(e) => {
warn!("watcher error: {}", e);
log::warn!("watcher error: {}", e);
continue;
}
};
@ -55,7 +55,7 @@ fn load_root(path: &Path) -> Vec<FileEvent> {
let text = match fs::read_to_string(path) {
Ok(text) => text,
Err(e) => {
warn!("watcher error: {}", e);
log::warn!("watcher error: {}", e);
continue;
}
};

View file

@ -1,6 +1,3 @@
#[macro_use]
extern crate crossbeam_channel;
mod support;
use ra_lsp_server::req::{Runnables, RunnablesParams};

View file

@ -6,7 +6,7 @@ use std::{
time::Duration,
};
use crossbeam_channel::{after, Receiver};
use crossbeam_channel::{after, select, Receiver};
use flexi_logger::Logger;
use gen_lsp_server::{RawMessage, RawNotification, RawRequest};
use languageserver_types::{