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