mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
modernize more
This commit is contained in:
parent
e477b87455
commit
f6e8b376d1
10 changed files with 42 additions and 56 deletions
|
@ -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 caps;
|
||||||
mod conv;
|
mod conv;
|
||||||
mod main_loop;
|
mod main_loop;
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
#[macro_use]
|
use serde_derive::Deserialize;
|
||||||
extern crate log;
|
use serde::Deserialize as _D;
|
||||||
#[macro_use]
|
|
||||||
extern crate failure;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
use serde::Deserialize;
|
|
||||||
use flexi_logger::{Duplicate, Logger};
|
use flexi_logger::{Duplicate, Logger};
|
||||||
use gen_lsp_server::{run_server, stdio_transport};
|
use gen_lsp_server::{run_server, stdio_transport};
|
||||||
use ra_lsp_server::Result;
|
use ra_lsp_server::Result;
|
||||||
|
@ -17,15 +11,15 @@ fn main() -> Result<()> {
|
||||||
.log_to_file()
|
.log_to_file()
|
||||||
.directory("log")
|
.directory("log")
|
||||||
.start()?;
|
.start()?;
|
||||||
info!("lifecycle: server started");
|
log::info!("lifecycle: server started");
|
||||||
match ::std::panic::catch_unwind(main_inner) {
|
match ::std::panic::catch_unwind(main_inner) {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
info!("lifecycle: terminating process with {:?}", res);
|
log::info!("lifecycle: terminating process with {:?}", res);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
error!("server panicked");
|
log::error!("server panicked");
|
||||||
bail!("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)
|
ra_lsp_server::main_loop(false, root, publish_decorations, r, s)
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
info!("shutting down IO...");
|
log::info!("shutting down IO...");
|
||||||
threads.join()?;
|
threads.join()?;
|
||||||
info!("... IO is down");
|
log::info!("... IO is down");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ mod subscriptions;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crossbeam_channel::{unbounded, Receiver, Sender};
|
use crossbeam_channel::{unbounded, select, Receiver, Sender};
|
||||||
use gen_lsp_server::{
|
use gen_lsp_server::{
|
||||||
handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse,
|
handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse,
|
||||||
};
|
};
|
||||||
|
@ -12,6 +12,8 @@ use ra_analysis::{Canceled, FileId, LibraryData};
|
||||||
use rayon::{self, ThreadPool};
|
use rayon::{self, ThreadPool};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
|
use failure::{format_err, bail};
|
||||||
|
use failure_derive::Fail;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
main_loop::subscriptions::Subscriptions,
|
main_loop::subscriptions::Subscriptions,
|
||||||
|
@ -54,14 +56,14 @@ pub fn main_loop(
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let pool = rayon::ThreadPoolBuilder::new()
|
let pool = rayon::ThreadPoolBuilder::new()
|
||||||
.num_threads(4)
|
.num_threads(4)
|
||||||
.panic_handler(|_| error!("thread panicked :("))
|
.panic_handler(|_| log::error!("thread panicked :("))
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let (task_sender, task_receiver) = unbounded::<Task>();
|
let (task_sender, task_receiver) = unbounded::<Task>();
|
||||||
let (fs_worker, fs_watcher) = vfs::roots_loader();
|
let (fs_worker, fs_watcher) = vfs::roots_loader();
|
||||||
let (ws_worker, ws_watcher) = workspace_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 state = ServerWorldState::default();
|
||||||
|
|
||||||
let mut pending_requests = FxHashSet::default();
|
let mut pending_requests = FxHashSet::default();
|
||||||
|
@ -82,12 +84,12 @@ pub fn main_loop(
|
||||||
&mut subs,
|
&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));
|
task_receiver.for_each(|task| on_task(task, msg_sender, &mut pending_requests));
|
||||||
info!("...tasks have finished");
|
log::info!("...tasks have finished");
|
||||||
info!("joining threadpool...");
|
log::info!("joining threadpool...");
|
||||||
drop(pool);
|
drop(pool);
|
||||||
info!("...threadpool has finished");
|
log::info!("...threadpool has finished");
|
||||||
|
|
||||||
let fs_res = fs_watcher.stop();
|
let fs_res = fs_watcher.stop();
|
||||||
let ws_res = ws_watcher.stop();
|
let ws_res = ws_watcher.stop();
|
||||||
|
@ -126,7 +128,7 @@ fn main_loop_inner(
|
||||||
Ws(Result<CargoWorkspace>),
|
Ws(Result<CargoWorkspace>),
|
||||||
Lib(LibraryData),
|
Lib(LibraryData),
|
||||||
}
|
}
|
||||||
trace!("selecting");
|
log::trace!("selecting");
|
||||||
let event = select! {
|
let event = select! {
|
||||||
recv(msg_receiver, msg) => match msg {
|
recv(msg_receiver, msg) => match msg {
|
||||||
Some(msg) => Event::Msg(msg),
|
Some(msg) => Event::Msg(msg),
|
||||||
|
@ -147,7 +149,7 @@ fn main_loop_inner(
|
||||||
match event {
|
match event {
|
||||||
Event::Task(task) => on_task(task, msg_sender, pending_requests),
|
Event::Task(task) => on_task(task, msg_sender, pending_requests),
|
||||||
Event::Fs(root, events) => {
|
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 {
|
if root == ws_root {
|
||||||
state.apply_fs_changes(events);
|
state.apply_fs_changes(events);
|
||||||
} else {
|
} else {
|
||||||
|
@ -155,9 +157,9 @@ fn main_loop_inner(
|
||||||
let sender = libdata_sender.clone();
|
let sender = libdata_sender.clone();
|
||||||
pool.spawn(move || {
|
pool.spawn(move || {
|
||||||
let start = ::std::time::Instant::now();
|
let start = ::std::time::Instant::now();
|
||||||
info!("indexing {} ... ", root.display());
|
log::info!("indexing {} ... ", root.display());
|
||||||
let data = LibraryData::prepare(files, resolver);
|
let data = LibraryData::prepare(files, resolver);
|
||||||
info!("indexed {:?} {}", start.elapsed(), root.display());
|
log::info!("indexed {:?} {}", start.elapsed(), root.display());
|
||||||
sender.send(data);
|
sender.send(data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -195,14 +197,14 @@ fn main_loop_inner(
|
||||||
.map(|(_idx, root)| root);
|
.map(|(_idx, root)| root);
|
||||||
|
|
||||||
for root in unique {
|
for root in unique {
|
||||||
debug!("sending root, {}", root.display());
|
log::debug!("sending root, {}", root.display());
|
||||||
fs_worker.send(root.to_owned());
|
fs_worker.send(root.to_owned());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.set_workspaces(workspaces);
|
state.set_workspaces(workspaces);
|
||||||
state_changed = true;
|
state_changed = true;
|
||||||
}
|
}
|
||||||
Err(e) => warn!("loading workspace failed: {}", e),
|
Err(e) => log::warn!("loading workspace failed: {}", e),
|
||||||
},
|
},
|
||||||
Event::Lib(lib) => {
|
Event::Lib(lib) => {
|
||||||
feedback(internal_mode, "library loaded", msg_sender);
|
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)? {
|
match on_request(state, pending_requests, pool, &task_sender, req)? {
|
||||||
None => (),
|
None => (),
|
||||||
Some(req) => {
|
Some(req) => {
|
||||||
error!("unknown request: {:?}", req);
|
log::error!("unknown request: {:?}", req);
|
||||||
let resp = RawResponse::err(
|
let resp = RawResponse::err(
|
||||||
req.id,
|
req.id,
|
||||||
ErrorCode::MethodNotFound as i32,
|
ErrorCode::MethodNotFound as i32,
|
||||||
|
@ -231,7 +233,7 @@ fn main_loop_inner(
|
||||||
on_notification(msg_sender, state, pending_requests, subs, not)?;
|
on_notification(msg_sender, state, pending_requests, subs, not)?;
|
||||||
state_changed = true;
|
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,
|
Err(not) => not,
|
||||||
};
|
};
|
||||||
error!("unhandled notification: {:?}", not);
|
log::error!("unhandled notification: {:?}", not);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,7 +457,7 @@ fn update_file_notifications_on_threadpool(
|
||||||
match handlers::publish_diagnostics(&world, file_id) {
|
match handlers::publish_diagnostics(&world, file_id) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if !is_canceled(&e) {
|
if !is_canceled(&e) {
|
||||||
error!("failed to compute diagnostics: {:?}", e);
|
log::error!("failed to compute diagnostics: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(params) => {
|
Ok(params) => {
|
||||||
|
@ -467,7 +469,7 @@ fn update_file_notifications_on_threadpool(
|
||||||
match handlers::publish_decorations(&world, file_id) {
|
match handlers::publish_decorations(&world, file_id) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if !is_canceled(&e) {
|
if !is_canceled(&e) {
|
||||||
error!("failed to compute decorations: {:?}", e);
|
log::error!("failed to compute decorations: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(params) => {
|
Ok(params) => {
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
use serde_derive::Serialize;
|
||||||
use cargo_metadata::{metadata_run, CargoOpt};
|
use cargo_metadata::{metadata_run, CargoOpt};
|
||||||
use ra_syntax::SmolStr;
|
use ra_syntax::SmolStr;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
|
use failure::{format_err, bail};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
thread_watcher::{ThreadWatcher, Worker},
|
|
||||||
Result,
|
Result,
|
||||||
|
thread_watcher::{ThreadWatcher, Worker},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use serde_derive::{Serialize, Deserialize};
|
||||||
use languageserver_types::{Location, Position, Range, TextDocumentIdentifier, Url};
|
use languageserver_types::{Location, Position, Range, TextDocumentIdentifier, Url};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use url_serde;
|
use url_serde;
|
||||||
|
|
|
@ -9,6 +9,7 @@ use ra_analysis::{
|
||||||
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FileResolver, LibraryData,
|
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FileResolver, LibraryData,
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
use failure::{bail, format_err};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
path_map::{PathMap, Root},
|
path_map::{PathMap, Root},
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::thread;
|
||||||
|
|
||||||
use crossbeam_channel::{bounded, unbounded, Receiver, Sender};
|
use crossbeam_channel::{bounded, unbounded, Receiver, Sender};
|
||||||
use drop_bomb::DropBomb;
|
use drop_bomb::DropBomb;
|
||||||
|
use failure::format_err;
|
||||||
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ impl ThreadWatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stop(mut self) -> Result<()> {
|
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;
|
let name = self.name;
|
||||||
self.bomb.defuse();
|
self.bomb.defuse();
|
||||||
let res = self
|
let res = self
|
||||||
|
@ -56,8 +57,8 @@ impl ThreadWatcher {
|
||||||
.join()
|
.join()
|
||||||
.map_err(|_| format_err!("ThreadWatcher {} died", name));
|
.map_err(|_| format_err!("ThreadWatcher {} died", name));
|
||||||
match &res {
|
match &res {
|
||||||
Ok(()) => info!("... {} terminated with ok", name),
|
Ok(()) => log::info!("... {} terminated with ok", name),
|
||||||
Err(_) => error!("... {} terminated with err", name),
|
Err(_) => log::error!("... {} terminated with err", name),
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,9 @@ pub fn roots_loader() -> (Worker<PathBuf, (PathBuf, Vec<FileEvent>)>, ThreadWatc
|
||||||
|input_receiver, output_sender| {
|
|input_receiver, output_sender| {
|
||||||
input_receiver
|
input_receiver
|
||||||
.map(|path| {
|
.map(|path| {
|
||||||
debug!("loading {} ...", path.as_path().display());
|
log::debug!("loading {} ...", path.as_path().display());
|
||||||
let events = load_root(path.as_path());
|
let events = load_root(path.as_path());
|
||||||
debug!("... loaded {}", path.as_path().display());
|
log::debug!("... loaded {}", path.as_path().display());
|
||||||
(path, events)
|
(path, events)
|
||||||
})
|
})
|
||||||
.for_each(|it| output_sender.send(it))
|
.for_each(|it| output_sender.send(it))
|
||||||
|
@ -41,7 +41,7 @@ fn load_root(path: &Path) -> Vec<FileEvent> {
|
||||||
let entry = match entry {
|
let entry = match entry {
|
||||||
Ok(entry) => entry,
|
Ok(entry) => entry,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("watcher error: {}", e);
|
log::warn!("watcher error: {}", e);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -55,7 +55,7 @@ fn load_root(path: &Path) -> Vec<FileEvent> {
|
||||||
let text = match fs::read_to_string(path) {
|
let text = match fs::read_to_string(path) {
|
||||||
Ok(text) => text,
|
Ok(text) => text,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("watcher error: {}", e);
|
log::warn!("watcher error: {}", e);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
#[macro_use]
|
|
||||||
extern crate crossbeam_channel;
|
|
||||||
|
|
||||||
mod support;
|
mod support;
|
||||||
|
|
||||||
use ra_lsp_server::req::{Runnables, RunnablesParams};
|
use ra_lsp_server::req::{Runnables, RunnablesParams};
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::{
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crossbeam_channel::{after, Receiver};
|
use crossbeam_channel::{after, select, Receiver};
|
||||||
use flexi_logger::Logger;
|
use flexi_logger::Logger;
|
||||||
use gen_lsp_server::{RawMessage, RawNotification, RawRequest};
|
use gen_lsp_server::{RawMessage, RawNotification, RawRequest};
|
||||||
use languageserver_types::{
|
use languageserver_types::{
|
||||||
|
|
Loading…
Reference in a new issue