aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/bin/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rust-analyzer/src/bin/main.rs')
-rw-r--r--crates/rust-analyzer/src/bin/main.rs37
1 files changed, 22 insertions, 15 deletions
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs
index 99e3f7173..45204d1a3 100644
--- a/crates/rust-analyzer/src/bin/main.rs
+++ b/crates/rust-analyzer/src/bin/main.rs
@@ -3,6 +3,8 @@
3//! Based on cli flags, either spawns an LSP server, or runs a batch analysis 3//! Based on cli flags, either spawns an LSP server, or runs a batch analysis
4mod args; 4mod args;
5 5
6use std::convert::TryFrom;
7
6use lsp_server::Connection; 8use lsp_server::Connection;
7use rust_analyzer::{ 9use rust_analyzer::{
8 cli, 10 cli,
@@ -10,9 +12,11 @@ use rust_analyzer::{
10 from_json, Result, 12 from_json, Result,
11}; 13};
12 14
13use crate::args::HelpPrinted; 15use ra_db::AbsPathBuf;
14use ra_project_model::ProjectManifest; 16use ra_project_model::ProjectManifest;
15 17
18use crate::args::HelpPrinted;
19
16fn main() -> Result<()> { 20fn main() -> Result<()> {
17 setup_logging()?; 21 setup_logging()?;
18 let args = match args::Args::parse()? { 22 let args = match args::Args::parse()? {
@@ -20,6 +24,9 @@ fn main() -> Result<()> {
20 Err(HelpPrinted) => return Ok(()), 24 Err(HelpPrinted) => return Ok(()),
21 }; 25 };
22 match args.command { 26 match args.command {
27 args::Command::RunServer => run_server()?,
28 args::Command::ProcMacro => ra_proc_macro_srv::cli::run()?,
29
23 args::Command::Parse { no_dump } => cli::parse(no_dump)?, 30 args::Command::Parse { no_dump } => cli::parse(no_dump)?,
24 args::Command::Symbols => cli::symbols()?, 31 args::Command::Symbols => cli::symbols()?,
25 args::Command::Highlight { rainbow } => cli::highlight(rainbow)?, 32 args::Command::Highlight { rainbow } => cli::highlight(rainbow)?,
@@ -41,7 +48,6 @@ fn main() -> Result<()> {
41 load_output_dirs, 48 load_output_dirs,
42 with_proc_macro, 49 with_proc_macro,
43 )?, 50 )?,
44
45 args::Command::Bench { path, what, load_output_dirs, with_proc_macro } => { 51 args::Command::Bench { path, what, load_output_dirs, with_proc_macro } => {
46 cli::analysis_bench( 52 cli::analysis_bench(
47 args.verbosity, 53 args.verbosity,
@@ -51,13 +57,9 @@ fn main() -> Result<()> {
51 with_proc_macro, 57 with_proc_macro,
52 )? 58 )?
53 } 59 }
54
55 args::Command::Diagnostics { path, load_output_dirs, with_proc_macro, all } => { 60 args::Command::Diagnostics { path, load_output_dirs, with_proc_macro, all } => {
56 cli::diagnostics(path.as_ref(), load_output_dirs, with_proc_macro, all)? 61 cli::diagnostics(path.as_ref(), load_output_dirs, with_proc_macro, all)?
57 } 62 }
58
59 args::Command::ProcMacro => run_proc_macro_srv()?,
60 args::Command::RunServer => run_server()?,
61 args::Command::Version => println!("rust-analyzer {}", env!("REV")), 63 args::Command::Version => println!("rust-analyzer {}", env!("REV")),
62 } 64 }
63 Ok(()) 65 Ok(())
@@ -70,11 +72,6 @@ fn setup_logging() -> Result<()> {
70 Ok(()) 72 Ok(())
71} 73}
72 74
73fn run_proc_macro_srv() -> Result<()> {
74 ra_proc_macro_srv::cli::run()?;
75 Ok(())
76}
77
78fn run_server() -> Result<()> { 75fn run_server() -> Result<()> {
79 log::info!("lifecycle: server started"); 76 log::info!("lifecycle: server started");
80 77
@@ -103,14 +100,23 @@ fn run_server() -> Result<()> {
103 } 100 }
104 101
105 let config = { 102 let config = {
106 let mut config = Config::default(); 103 let root_path = match initialize_params
104 .root_uri
105 .and_then(|it| it.to_file_path().ok())
106 .and_then(|it| AbsPathBuf::try_from(it).ok())
107 {
108 Some(it) => it,
109 None => {
110 let cwd = std::env::current_dir()?;
111 AbsPathBuf::assert(cwd)
112 }
113 };
114
115 let mut config = Config::new(root_path);
107 if let Some(value) = &initialize_params.initialization_options { 116 if let Some(value) = &initialize_params.initialization_options {
108 config.update(value); 117 config.update(value);
109 } 118 }
110 config.update_caps(&initialize_params.capabilities); 119 config.update_caps(&initialize_params.capabilities);
111 let cwd = std::env::current_dir()?;
112 config.root_path =
113 initialize_params.root_uri.and_then(|it| it.to_file_path().ok()).unwrap_or(cwd);
114 120
115 if config.linked_projects.is_empty() { 121 if config.linked_projects.is_empty() {
116 let workspace_roots = initialize_params 122 let workspace_roots = initialize_params
@@ -119,6 +125,7 @@ fn run_server() -> Result<()> {
119 workspaces 125 workspaces
120 .into_iter() 126 .into_iter()
121 .filter_map(|it| it.uri.to_file_path().ok()) 127 .filter_map(|it| it.uri.to_file_path().ok())
128 .filter_map(|it| AbsPathBuf::try_from(it).ok())
122 .collect::<Vec<_>>() 129 .collect::<Vec<_>>()
123 }) 130 })
124 .filter(|workspaces| !workspaces.is_empty()) 131 .filter(|workspaces| !workspaces.is_empty())