diff options
Diffstat (limited to 'crates/rust-analyzer/src/bin/main.rs')
-rw-r--r-- | crates/rust-analyzer/src/bin/main.rs | 84 |
1 files changed, 57 insertions, 27 deletions
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index e82fd57de..408892eab 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs | |||
@@ -3,8 +3,16 @@ | |||
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 |
4 | mod args; | 4 | mod args; |
5 | 5 | ||
6 | use std::convert::TryFrom; | ||
7 | |||
6 | use lsp_server::Connection; | 8 | use lsp_server::Connection; |
7 | use rust_analyzer::{cli, config::Config, from_json, Result}; | 9 | use ra_project_model::ProjectManifest; |
10 | use rust_analyzer::{ | ||
11 | cli, | ||
12 | config::{Config, LinkedProject}, | ||
13 | from_json, Result, | ||
14 | }; | ||
15 | use vfs::AbsPathBuf; | ||
8 | 16 | ||
9 | use crate::args::HelpPrinted; | 17 | use crate::args::HelpPrinted; |
10 | 18 | ||
@@ -15,11 +23,15 @@ fn main() -> Result<()> { | |||
15 | Err(HelpPrinted) => return Ok(()), | 23 | Err(HelpPrinted) => return Ok(()), |
16 | }; | 24 | }; |
17 | match args.command { | 25 | match args.command { |
26 | args::Command::RunServer => run_server()?, | ||
27 | args::Command::ProcMacro => ra_proc_macro_srv::cli::run()?, | ||
28 | |||
18 | args::Command::Parse { no_dump } => cli::parse(no_dump)?, | 29 | args::Command::Parse { no_dump } => cli::parse(no_dump)?, |
19 | args::Command::Symbols => cli::symbols()?, | 30 | args::Command::Symbols => cli::symbols()?, |
20 | args::Command::Highlight { rainbow } => cli::highlight(rainbow)?, | 31 | args::Command::Highlight { rainbow } => cli::highlight(rainbow)?, |
21 | args::Command::Stats { | 32 | args::Command::Stats { |
22 | randomize, | 33 | randomize, |
34 | parallel, | ||
23 | memory_usage, | 35 | memory_usage, |
24 | only, | 36 | only, |
25 | with_deps, | 37 | with_deps, |
@@ -33,26 +45,29 @@ fn main() -> Result<()> { | |||
33 | only.as_ref().map(String::as_ref), | 45 | only.as_ref().map(String::as_ref), |
34 | with_deps, | 46 | with_deps, |
35 | randomize, | 47 | randomize, |
48 | parallel, | ||
36 | load_output_dirs, | 49 | load_output_dirs, |
37 | with_proc_macro, | 50 | with_proc_macro, |
38 | )?, | 51 | )?, |
39 | 52 | args::Command::Bench { memory_usage, path, what, load_output_dirs, with_proc_macro } => { | |
40 | args::Command::Bench { path, what, load_output_dirs, with_proc_macro } => { | ||
41 | cli::analysis_bench( | 53 | cli::analysis_bench( |
42 | args.verbosity, | 54 | args.verbosity, |
43 | path.as_ref(), | 55 | path.as_ref(), |
44 | what, | 56 | what, |
57 | memory_usage, | ||
45 | load_output_dirs, | 58 | load_output_dirs, |
46 | with_proc_macro, | 59 | with_proc_macro, |
47 | )? | 60 | )? |
48 | } | 61 | } |
49 | |||
50 | args::Command::Diagnostics { path, load_output_dirs, with_proc_macro, all } => { | 62 | args::Command::Diagnostics { path, load_output_dirs, with_proc_macro, all } => { |
51 | cli::diagnostics(path.as_ref(), load_output_dirs, with_proc_macro, all)? | 63 | cli::diagnostics(path.as_ref(), load_output_dirs, with_proc_macro, all)? |
52 | } | 64 | } |
53 | 65 | args::Command::Ssr { rules } => { | |
54 | args::Command::ProcMacro => run_proc_macro_srv()?, | 66 | cli::apply_ssr_rules(rules)?; |
55 | args::Command::RunServer => run_server()?, | 67 | } |
68 | args::Command::StructuredSearch { patterns, debug_snippet } => { | ||
69 | cli::search_for_patterns(patterns, debug_snippet)?; | ||
70 | } | ||
56 | args::Command::Version => println!("rust-analyzer {}", env!("REV")), | 71 | args::Command::Version => println!("rust-analyzer {}", env!("REV")), |
57 | } | 72 | } |
58 | Ok(()) | 73 | Ok(()) |
@@ -65,11 +80,6 @@ fn setup_logging() -> Result<()> { | |||
65 | Ok(()) | 80 | Ok(()) |
66 | } | 81 | } |
67 | 82 | ||
68 | fn run_proc_macro_srv() -> Result<()> { | ||
69 | ra_proc_macro_srv::cli::run()?; | ||
70 | Ok(()) | ||
71 | } | ||
72 | |||
73 | fn run_server() -> Result<()> { | 83 | fn run_server() -> Result<()> { |
74 | log::info!("lifecycle: server started"); | 84 | log::info!("lifecycle: server started"); |
75 | 85 | ||
@@ -97,28 +107,48 @@ fn run_server() -> Result<()> { | |||
97 | log::info!("Client '{}' {}", client_info.name, client_info.version.unwrap_or_default()); | 107 | log::info!("Client '{}' {}", client_info.name, client_info.version.unwrap_or_default()); |
98 | } | 108 | } |
99 | 109 | ||
100 | let cwd = std::env::current_dir()?; | ||
101 | let root = initialize_params.root_uri.and_then(|it| it.to_file_path().ok()).unwrap_or(cwd); | ||
102 | |||
103 | let workspace_roots = initialize_params | ||
104 | .workspace_folders | ||
105 | .map(|workspaces| { | ||
106 | workspaces.into_iter().filter_map(|it| it.uri.to_file_path().ok()).collect::<Vec<_>>() | ||
107 | }) | ||
108 | .filter(|workspaces| !workspaces.is_empty()) | ||
109 | .unwrap_or_else(|| vec![root]); | ||
110 | |||
111 | let config = { | 110 | let config = { |
112 | let mut config = Config::default(); | 111 | let root_path = match initialize_params |
113 | if let Some(value) = &initialize_params.initialization_options { | 112 | .root_uri |
114 | config.update(value); | 113 | .and_then(|it| it.to_file_path().ok()) |
114 | .and_then(|it| AbsPathBuf::try_from(it).ok()) | ||
115 | { | ||
116 | Some(it) => it, | ||
117 | None => { | ||
118 | let cwd = std::env::current_dir()?; | ||
119 | AbsPathBuf::assert(cwd) | ||
120 | } | ||
121 | }; | ||
122 | |||
123 | let mut config = Config::new(root_path); | ||
124 | if let Some(json) = initialize_params.initialization_options { | ||
125 | config.update(json); | ||
115 | } | 126 | } |
116 | config.update_caps(&initialize_params.capabilities); | 127 | config.update_caps(&initialize_params.capabilities); |
117 | 128 | ||
129 | if config.linked_projects.is_empty() { | ||
130 | let workspace_roots = initialize_params | ||
131 | .workspace_folders | ||
132 | .map(|workspaces| { | ||
133 | workspaces | ||
134 | .into_iter() | ||
135 | .filter_map(|it| it.uri.to_file_path().ok()) | ||
136 | .filter_map(|it| AbsPathBuf::try_from(it).ok()) | ||
137 | .collect::<Vec<_>>() | ||
138 | }) | ||
139 | .filter(|workspaces| !workspaces.is_empty()) | ||
140 | .unwrap_or_else(|| vec![config.root_path.clone()]); | ||
141 | |||
142 | config.linked_projects = ProjectManifest::discover_all(&workspace_roots) | ||
143 | .into_iter() | ||
144 | .map(LinkedProject::from) | ||
145 | .collect(); | ||
146 | } | ||
147 | |||
118 | config | 148 | config |
119 | }; | 149 | }; |
120 | 150 | ||
121 | rust_analyzer::main_loop(workspace_roots, config, connection)?; | 151 | rust_analyzer::main_loop(config, connection)?; |
122 | 152 | ||
123 | log::info!("shutting down IO..."); | 153 | log::info!("shutting down IO..."); |
124 | io_threads.join()?; | 154 | io_threads.join()?; |