2018-08-10 07:07:43 -05:00
|
|
|
#[macro_use]
|
|
|
|
extern crate failure;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
extern crate serde;
|
|
|
|
extern crate serde_json;
|
|
|
|
extern crate languageserver_types;
|
|
|
|
extern crate drop_bomb;
|
2018-08-10 09:49:45 -05:00
|
|
|
#[macro_use]
|
2018-08-10 07:07:43 -05:00
|
|
|
extern crate crossbeam_channel;
|
2018-08-10 09:49:45 -05:00
|
|
|
extern crate threadpool;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2018-08-10 16:55:32 -05:00
|
|
|
extern crate url_serde;
|
2018-08-10 09:49:45 -05:00
|
|
|
extern crate flexi_logger;
|
2018-08-13 05:46:05 -05:00
|
|
|
extern crate walkdir;
|
2018-08-10 07:07:43 -05:00
|
|
|
extern crate libeditor;
|
|
|
|
extern crate libanalysis;
|
2018-08-11 06:44:12 -05:00
|
|
|
extern crate libsyntax2;
|
2018-09-01 09:40:45 -05:00
|
|
|
extern crate gen_lsp_server;
|
2018-08-15 09:24:20 -05:00
|
|
|
extern crate im;
|
2018-08-28 10:22:52 -05:00
|
|
|
extern crate relative_path;
|
2018-08-10 07:07:43 -05:00
|
|
|
|
|
|
|
mod caps;
|
|
|
|
mod req;
|
2018-08-12 13:02:56 -05:00
|
|
|
mod conv;
|
2018-08-12 14:08:14 -05:00
|
|
|
mod main_loop;
|
2018-08-13 05:46:05 -05:00
|
|
|
mod vfs;
|
2018-08-15 09:24:20 -05:00
|
|
|
mod path_map;
|
2018-08-17 11:54:08 -05:00
|
|
|
mod server_world;
|
2018-08-13 05:46:05 -05:00
|
|
|
|
2018-08-12 18:38:34 -05:00
|
|
|
use flexi_logger::{Logger, Duplicate};
|
2018-09-01 09:40:45 -05:00
|
|
|
use gen_lsp_server::{run_server, stdio_transport};
|
2018-08-10 07:07:43 -05:00
|
|
|
|
|
|
|
pub type Result<T> = ::std::result::Result<T, ::failure::Error>;
|
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
2018-08-27 16:42:13 -05:00
|
|
|
Logger::with_env_or_str("m=error")
|
2018-08-12 18:38:34 -05:00
|
|
|
.duplicate_to_stderr(Duplicate::All)
|
2018-08-10 09:49:45 -05:00
|
|
|
.log_to_file()
|
|
|
|
.directory("log")
|
|
|
|
.start()?;
|
2018-08-10 14:55:42 -05:00
|
|
|
info!("lifecycle: server started");
|
2018-08-10 09:49:45 -05:00
|
|
|
match ::std::panic::catch_unwind(|| main_inner()) {
|
|
|
|
Ok(res) => {
|
2018-08-10 14:55:42 -05:00
|
|
|
info!("lifecycle: terminating process with {:?}", res);
|
2018-08-10 09:49:45 -05:00
|
|
|
res
|
|
|
|
}
|
|
|
|
Err(_) => {
|
|
|
|
error!("server panicked");
|
|
|
|
bail!("server panicked")
|
2018-08-10 10:01:59 -05:00
|
|
|
}
|
2018-08-10 09:49:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main_inner() -> Result<()> {
|
2018-09-01 09:40:45 -05:00
|
|
|
let (receiver, sender, threads) = stdio_transport();
|
2018-09-01 10:03:57 -05:00
|
|
|
let root = ::std::env::current_dir()?;
|
|
|
|
run_server(
|
|
|
|
caps::server_capabilities(),
|
|
|
|
|r, s| main_loop::main_loop(root, r, s),
|
|
|
|
receiver,
|
|
|
|
sender,
|
|
|
|
)?;
|
2018-08-10 09:49:45 -05:00
|
|
|
info!("shutting down IO...");
|
2018-09-01 09:40:45 -05:00
|
|
|
threads.join()?;
|
2018-08-10 09:49:45 -05:00
|
|
|
info!("... IO is down");
|
2018-09-01 09:40:45 -05:00
|
|
|
Ok(())
|
2018-08-10 09:49:45 -05:00
|
|
|
}
|