rust/crates/ra_lsp_server/src/main.rs

91 lines
2.8 KiB
Rust
Raw Normal View History

2018-08-10 07:07:43 -05:00
#[macro_use]
2018-08-10 09:49:45 -05:00
extern crate log;
2018-09-01 10:16:08 -05:00
#[macro_use]
extern crate failure;
2018-11-08 09:43:02 -06:00
extern crate serde_derive;
extern crate serde;
2018-08-10 09:49:45 -05:00
extern crate flexi_logger;
2018-09-01 09:40:45 -05:00
extern crate gen_lsp_server;
2018-09-16 04:54:24 -05:00
extern crate ra_lsp_server;
2018-08-13 05:46:05 -05:00
2018-11-08 09:43:02 -06:00
use serde::Deserialize;
use flexi_logger::{Duplicate, Logger};
2018-09-01 09:40:45 -05:00
use gen_lsp_server::{run_server, stdio_transport};
2018-09-16 04:54:24 -05:00
use ra_lsp_server::Result;
2018-08-10 07:07:43 -05:00
fn main() -> Result<()> {
2018-09-08 01:18:42 -05:00
::std::env::set_var("RUST_BACKTRACE", "short");
Logger::with_env_or_str("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-10-17 18:25:37 -05:00
match ::std::panic::catch_unwind(main_inner) {
2018-08-10 09:49:45 -05:00
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
}
}
2018-11-08 09:43:02 -06:00
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct InitializationOptions {
publish_decorations: bool,
}
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-05 13:38:43 -05:00
let cwd = ::std::env::current_dir()?;
2018-09-01 10:03:57 -05:00
run_server(
2018-09-16 04:54:24 -05:00
ra_lsp_server::server_capabilities(),
2018-10-09 04:55:23 -05:00
receiver,
sender,
2018-09-05 13:38:43 -05:00
|params, r, s| {
let root = params
.root_uri
2018-09-05 13:38:43 -05:00
.and_then(|it| it.to_file_path().ok())
.unwrap_or(cwd);
2018-11-08 09:43:02 -06: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 13:38:43 -05:00
},
2018-09-01 10:03:57 -05:00
)?;
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
}
2018-11-08 08:40:04 -06:00
/*
(let ((backend (eglot-xref-backend)))
2018-11-08 09:43:02 -06:00
(mapcar
2018-11-08 08:40:04 -06:00
(lambda (xref)
(let ((loc (xref-item-location xref)))
(propertize
(concat
(when (xref-file-location-p loc)
(with-slots (file line column) loc
2018-11-08 09:43:02 -06:00
(format "%s:%s:%s:"
2018-11-08 08:40:04 -06:00
(propertize (file-relative-name file)
'face 'compilation-info)
(propertize (format "%s" line)
'face 'compilation-line
)
column)))
(xref-item-summary xref))
'xref xref)))
(xref-backend-apropos backend "Analysis"))
)
*/