aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/bin/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src/bin/main.rs')
-rw-r--r--crates/ra_lsp_server/src/bin/main.rs98
1 files changed, 0 insertions, 98 deletions
diff --git a/crates/ra_lsp_server/src/bin/main.rs b/crates/ra_lsp_server/src/bin/main.rs
deleted file mode 100644
index 69e709a25..000000000
--- a/crates/ra_lsp_server/src/bin/main.rs
+++ /dev/null
@@ -1,98 +0,0 @@
1//! Driver for rust-analyzer.
2//!
3//! Based on cli flags, either spawns an LSP server, or runs a batch analysis
4mod args;
5
6use lsp_server::Connection;
7use ra_prof;
8use rust_analyzer::{cli, from_json, show_message, Result, ServerConfig};
9
10use crate::args::HelpPrinted;
11
12fn main() -> Result<()> {
13 setup_logging()?;
14 let args = match args::Args::parse()? {
15 Ok(it) => it,
16 Err(HelpPrinted) => return Ok(()),
17 };
18 match args.command {
19 args::Command::Parse { no_dump } => cli::parse(no_dump)?,
20 args::Command::Symbols => cli::symbols()?,
21 args::Command::Highlight { rainbow } => cli::highlight(rainbow)?,
22 args::Command::Stats { randomize, memory_usage, only, with_deps, path } => {
23 cli::analysis_stats(
24 args.verbosity,
25 memory_usage,
26 path.as_ref(),
27 only.as_ref().map(String::as_ref),
28 with_deps,
29 randomize,
30 )?
31 }
32
33 args::Command::Bench { path, what } => {
34 cli::analysis_bench(args.verbosity, path.as_ref(), what)?
35 }
36
37 args::Command::RunServer => run_server()?,
38 args::Command::Version => println!("rust-analyzer {}", env!("REV")),
39 }
40 Ok(())
41}
42
43fn setup_logging() -> Result<()> {
44 std::env::set_var("RUST_BACKTRACE", "short");
45 env_logger::try_init()?;
46 ra_prof::init();
47 Ok(())
48}
49
50fn run_server() -> Result<()> {
51 log::info!("lifecycle: server started");
52
53 let (connection, io_threads) = Connection::stdio();
54 let server_capabilities = serde_json::to_value(rust_analyzer::server_capabilities()).unwrap();
55
56 let initialize_params = connection.initialize(server_capabilities)?;
57 let initialize_params =
58 from_json::<lsp_types::InitializeParams>("InitializeParams", initialize_params)?;
59
60 if let Some(client_info) = initialize_params.client_info {
61 log::info!("Client '{}' {}", client_info.name, client_info.version.unwrap_or_default());
62 }
63
64 let cwd = std::env::current_dir()?;
65 let root = initialize_params.root_uri.and_then(|it| it.to_file_path().ok()).unwrap_or(cwd);
66
67 let workspace_roots = initialize_params
68 .workspace_folders
69 .map(|workspaces| {
70 workspaces.into_iter().filter_map(|it| it.uri.to_file_path().ok()).collect::<Vec<_>>()
71 })
72 .filter(|workspaces| !workspaces.is_empty())
73 .unwrap_or_else(|| vec![root]);
74
75 let server_config = initialize_params
76 .initialization_options
77 .and_then(|v| {
78 from_json::<ServerConfig>("config", v)
79 .map_err(|e| {
80 log::error!("{}", e);
81 show_message(lsp_types::MessageType::Error, e.to_string(), &connection.sender);
82 })
83 .ok()
84 })
85 .unwrap_or_default();
86
87 rust_analyzer::main_loop(
88 workspace_roots,
89 initialize_params.capabilities,
90 server_config,
91 connection,
92 )?;
93
94 log::info!("shutting down IO...");
95 io_threads.join()?;
96 log::info!("... IO is down");
97 Ok(())
98}