2018-12-21 22:39:59 +03:00
|
|
|
use serde::Deserialize;
|
2018-10-15 17:44:23 -04:00
|
|
|
use flexi_logger::{Duplicate, Logger};
|
2018-09-01 17:40:45 +03:00
|
|
|
use gen_lsp_server::{run_server, stdio_transport};
|
2018-12-21 22:39:59 +03:00
|
|
|
|
2018-09-16 12:54:24 +03:00
|
|
|
use ra_lsp_server::Result;
|
2018-08-10 15:07:43 +03:00
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
2018-09-08 09:18:42 +03:00
|
|
|
::std::env::set_var("RUST_BACKTRACE", "short");
|
2018-12-17 17:22:30 -05:00
|
|
|
let logger = Logger::with_env_or_str("error").duplicate_to_stderr(Duplicate::All);
|
|
|
|
match ::std::env::var("RA_INTERNAL_MODE") {
|
|
|
|
Ok(ref v) if v == "1" => logger.log_to_file().directory("log").start()?,
|
|
|
|
_ => logger.start()?,
|
|
|
|
};
|
2018-12-06 21:03:39 +03:00
|
|
|
log::info!("lifecycle: server started");
|
2018-10-17 19:25:37 -04:00
|
|
|
match ::std::panic::catch_unwind(main_inner) {
|
2018-08-10 17:49:45 +03:00
|
|
|
Ok(res) => {
|
2018-12-06 21:03:39 +03:00
|
|
|
log::info!("lifecycle: terminating process with {:?}", res);
|
2018-08-10 17:49:45 +03:00
|
|
|
res
|
|
|
|
}
|
|
|
|
Err(_) => {
|
2018-12-06 21:03:39 +03:00
|
|
|
log::error!("server panicked");
|
|
|
|
failure::bail!("server panicked")
|
2018-08-10 18:01:59 +03:00
|
|
|
}
|
2018-08-10 17:49:45 +03:00
|
|
|
}
|
|
|
|
}
|
2018-11-08 18:43:02 +03:00
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct InitializationOptions {
|
2018-12-21 17:00:31 +00:00
|
|
|
// Whether the client supports our custom highlighting publishing decorations.
|
2018-12-23 11:10:12 +00:00
|
|
|
// This is different to the highlightingOn setting, which is whether the user
|
|
|
|
// wants our custom highlighting to be used.
|
2018-12-21 17:00:31 +00:00
|
|
|
publish_decorations: Option<bool>,
|
2018-11-08 18:43:02 +03:00
|
|
|
}
|
|
|
|
|
2018-08-10 17:49:45 +03:00
|
|
|
fn main_inner() -> Result<()> {
|
2018-09-01 17:40:45 +03:00
|
|
|
let (receiver, sender, threads) = stdio_transport();
|
2018-09-05 21:38:43 +03:00
|
|
|
let cwd = ::std::env::current_dir()?;
|
2018-09-01 18:03:57 +03:00
|
|
|
run_server(
|
2018-09-16 12:54:24 +03:00
|
|
|
ra_lsp_server::server_capabilities(),
|
2018-10-09 12:55:23 +03:00
|
|
|
receiver,
|
|
|
|
sender,
|
2018-09-05 21:38:43 +03:00
|
|
|
|params, r, s| {
|
2018-10-15 17:44:23 -04:00
|
|
|
let root = params
|
|
|
|
.root_uri
|
2018-09-05 21:38:43 +03:00
|
|
|
.and_then(|it| it.to_file_path().ok())
|
|
|
|
.unwrap_or(cwd);
|
2018-12-21 17:00:31 +00:00
|
|
|
let supports_decorations = params
|
2018-11-08 18:43:02 +03:00
|
|
|
.initialization_options
|
|
|
|
.and_then(|v| InitializationOptions::deserialize(v).ok())
|
2018-12-21 17:00:31 +00:00
|
|
|
.and_then(|it| it.publish_decorations)
|
2018-11-08 18:43:02 +03:00
|
|
|
== Some(true);
|
2018-12-21 17:00:31 +00:00
|
|
|
ra_lsp_server::main_loop(false, root, supports_decorations, r, s)
|
2018-09-05 21:38:43 +03:00
|
|
|
},
|
2018-09-01 18:03:57 +03:00
|
|
|
)?;
|
2018-12-06 21:03:39 +03:00
|
|
|
log::info!("shutting down IO...");
|
2018-09-01 17:40:45 +03:00
|
|
|
threads.join()?;
|
2018-12-06 21:03:39 +03:00
|
|
|
log::info!("... IO is down");
|
2018-09-01 17:40:45 +03:00
|
|
|
Ok(())
|
2018-08-10 17:49:45 +03:00
|
|
|
}
|