mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
cleanup main loop
This commit is contained in:
parent
f90a886301
commit
4e3f5cc729
8 changed files with 172 additions and 221 deletions
|
@ -5,37 +5,37 @@ use ra_lsp_server::{show_message, Result, ServerConfig};
|
|||
use ra_prof;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
setup_logging()?;
|
||||
run_server()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn setup_logging() -> Result<()> {
|
||||
std::env::set_var("RUST_BACKTRACE", "short");
|
||||
|
||||
let logger = Logger::with_env_or_str("error").duplicate_to_stderr(Duplicate::All);
|
||||
match std::env::var("RA_LOG_DIR") {
|
||||
Ok(ref v) if v == "1" => logger.log_to_file().directory("log").start()?,
|
||||
_ => logger.start()?,
|
||||
};
|
||||
|
||||
ra_prof::set_filter(match std::env::var("RA_PROFILE") {
|
||||
Ok(spec) => ra_prof::Filter::from_spec(&spec),
|
||||
Err(_) => ra_prof::Filter::disabled(),
|
||||
});
|
||||
log::info!("lifecycle: server started");
|
||||
match std::panic::catch_unwind(main_inner) {
|
||||
Ok(res) => {
|
||||
log::info!("lifecycle: terminating process with {:?}", res);
|
||||
res
|
||||
}
|
||||
Err(_) => {
|
||||
log::error!("server panicked");
|
||||
Err("server panicked")?
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main_inner() -> Result<()> {
|
||||
let cwd = std::env::current_dir()?;
|
||||
fn run_server() -> Result<()> {
|
||||
log::info!("lifecycle: server started");
|
||||
|
||||
let (connection, io_threads) = Connection::stdio();
|
||||
let server_capabilities = serde_json::to_value(ra_lsp_server::server_capabilities()).unwrap();
|
||||
|
||||
let initialize_params = connection.initialize(server_capabilities)?;
|
||||
let initialize_params: lsp_types::InitializeParams = serde_json::from_value(initialize_params)?;
|
||||
|
||||
let cwd = std::env::current_dir()?;
|
||||
let root = initialize_params.root_uri.and_then(|it| it.to_file_path().ok()).unwrap_or(cwd);
|
||||
|
||||
let workspace_roots = initialize_params
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue