aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src/main.rs')
-rw-r--r--crates/ra_lsp_server/src/main.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs
index 88504bb89..d40fed947 100644
--- a/crates/ra_lsp_server/src/main.rs
+++ b/crates/ra_lsp_server/src/main.rs
@@ -5,37 +5,37 @@ use ra_lsp_server::{show_message, Result, ServerConfig};
5use ra_prof; 5use ra_prof;
6 6
7fn main() -> Result<()> { 7fn main() -> Result<()> {
8 setup_logging()?;
9 run_server()?;
10 Ok(())
11}
12
13fn setup_logging() -> Result<()> {
8 std::env::set_var("RUST_BACKTRACE", "short"); 14 std::env::set_var("RUST_BACKTRACE", "short");
15
9 let logger = Logger::with_env_or_str("error").duplicate_to_stderr(Duplicate::All); 16 let logger = Logger::with_env_or_str("error").duplicate_to_stderr(Duplicate::All);
10 match std::env::var("RA_LOG_DIR") { 17 match std::env::var("RA_LOG_DIR") {
11 Ok(ref v) if v == "1" => logger.log_to_file().directory("log").start()?, 18 Ok(ref v) if v == "1" => logger.log_to_file().directory("log").start()?,
12 _ => logger.start()?, 19 _ => logger.start()?,
13 }; 20 };
21
14 ra_prof::set_filter(match std::env::var("RA_PROFILE") { 22 ra_prof::set_filter(match std::env::var("RA_PROFILE") {
15 Ok(spec) => ra_prof::Filter::from_spec(&spec), 23 Ok(spec) => ra_prof::Filter::from_spec(&spec),
16 Err(_) => ra_prof::Filter::disabled(), 24 Err(_) => ra_prof::Filter::disabled(),
17 }); 25 });
18 log::info!("lifecycle: server started"); 26 Ok(())
19 match std::panic::catch_unwind(main_inner) {
20 Ok(res) => {
21 log::info!("lifecycle: terminating process with {:?}", res);
22 res
23 }
24 Err(_) => {
25 log::error!("server panicked");
26 Err("server panicked")?
27 }
28 }
29} 27}
30 28
31fn main_inner() -> Result<()> { 29fn run_server() -> Result<()> {
32 let cwd = std::env::current_dir()?; 30 log::info!("lifecycle: server started");
31
33 let (connection, io_threads) = Connection::stdio(); 32 let (connection, io_threads) = Connection::stdio();
34 let server_capabilities = serde_json::to_value(ra_lsp_server::server_capabilities()).unwrap(); 33 let server_capabilities = serde_json::to_value(ra_lsp_server::server_capabilities()).unwrap();
35 34
36 let initialize_params = connection.initialize(server_capabilities)?; 35 let initialize_params = connection.initialize(server_capabilities)?;
37 let initialize_params: lsp_types::InitializeParams = serde_json::from_value(initialize_params)?; 36 let initialize_params: lsp_types::InitializeParams = serde_json::from_value(initialize_params)?;
38 37
38 let cwd = std::env::current_dir()?;
39 let root = initialize_params.root_uri.and_then(|it| it.to_file_path().ok()).unwrap_or(cwd); 39 let root = initialize_params.root_uri.and_then(|it| it.to_file_path().ok()).unwrap_or(cwd);
40 40
41 let workspace_roots = initialize_params 41 let workspace_roots = initialize_params