2018-08-10 14:07:43 +02:00
|
|
|
#[macro_use]
|
2018-08-10 16:49:45 +02:00
|
|
|
extern crate log;
|
2018-09-01 17:16:08 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate failure;
|
2018-12-02 10:27:30 +01:00
|
|
|
#[macro_use]
|
2018-11-08 16:43:02 +01:00
|
|
|
extern crate serde_derive;
|
2018-08-13 12:46:05 +02:00
|
|
|
|
2018-11-08 16:43:02 +01:00
|
|
|
use serde::Deserialize;
|
2018-10-15 23:44:23 +02:00
|
|
|
use flexi_logger::{Duplicate, Logger};
|
2018-09-01 16:40:45 +02:00
|
|
|
use gen_lsp_server::{run_server, stdio_transport};
|
2018-09-16 11:54:24 +02:00
|
|
|
use ra_lsp_server::Result;
|
2018-08-10 14:07:43 +02:00
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
2018-09-08 08:18:42 +02:00
|
|
|
::std::env::set_var("RUST_BACKTRACE", "short");
|
|
|
|
Logger::with_env_or_str("error")
|
2018-08-13 01:38:34 +02:00
|
|
|
.duplicate_to_stderr(Duplicate::All)
|
2018-08-10 16:49:45 +02:00
|
|
|
.log_to_file()
|
|
|
|
.directory("log")
|
|
|
|
.start()?;
|
2018-08-10 21:55:42 +02:00
|
|
|
info!("lifecycle: server started");
|
2018-10-18 01:25:37 +02:00
|
|
|
match ::std::panic::catch_unwind(main_inner) {
|
2018-08-10 16:49:45 +02:00
|
|
|
Ok(res) => {
|
2018-08-10 21:55:42 +02:00
|
|
|
info!("lifecycle: terminating process with {:?}", res);
|
2018-08-10 16:49:45 +02:00
|
|
|
res
|
|
|
|
}
|
|
|
|
Err(_) => {
|
|
|
|
error!("server panicked");
|
|
|
|
bail!("server panicked")
|
2018-08-10 17:01:59 +02:00
|
|
|
}
|
2018-08-10 16:49:45 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-08 16:43:02 +01:00
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct InitializationOptions {
|
|
|
|
publish_decorations: bool,
|
|
|
|
}
|
|
|
|
|
2018-08-10 16:49:45 +02:00
|
|
|
fn main_inner() -> Result<()> {
|
2018-09-01 16:40:45 +02:00
|
|
|
let (receiver, sender, threads) = stdio_transport();
|
2018-09-05 20:38:43 +02:00
|
|
|
let cwd = ::std::env::current_dir()?;
|
2018-09-01 17:03:57 +02:00
|
|
|
run_server(
|
2018-09-16 11:54:24 +02:00
|
|
|
ra_lsp_server::server_capabilities(),
|
2018-10-09 11:55:23 +02:00
|
|
|
receiver,
|
|
|
|
sender,
|
2018-09-05 20:38:43 +02:00
|
|
|
|params, r, s| {
|
2018-10-15 23:44:23 +02:00
|
|
|
let root = params
|
|
|
|
.root_uri
|
2018-09-05 20:38:43 +02:00
|
|
|
.and_then(|it| it.to_file_path().ok())
|
|
|
|
.unwrap_or(cwd);
|
2018-11-08 16:43:02 +01:00
|
|
|
let publish_decorations = params
|
|
|
|
.initialization_options
|
|
|
|
.and_then(|v| InitializationOptions::deserialize(v).ok())
|
|
|
|
.map(|it| it.publish_decorations)
|
|
|
|
== Some(true);
|
|
|
|
ra_lsp_server::main_loop(false, root, publish_decorations, r, s)
|
2018-09-05 20:38:43 +02:00
|
|
|
},
|
2018-09-01 17:03:57 +02:00
|
|
|
)?;
|
2018-08-10 16:49:45 +02:00
|
|
|
info!("shutting down IO...");
|
2018-09-01 16:40:45 +02:00
|
|
|
threads.join()?;
|
2018-08-10 16:49:45 +02:00
|
|
|
info!("... IO is down");
|
2018-09-01 16:40:45 +02:00
|
|
|
Ok(())
|
2018-08-10 16:49:45 +02:00
|
|
|
}
|