aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/bin/args.rs22
-rw-r--r--crates/rust-analyzer/src/bin/main.rs16
-rw-r--r--crates/rust-analyzer/src/cli/analysis_bench.rs3
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs3
-rw-r--r--crates/rust-analyzer/src/cli/diagnostics.rs9
-rw-r--r--crates/rust-analyzer/src/cli/load_cargo.rs9
6 files changed, 49 insertions, 13 deletions
diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs
index f5981588a..ec93e9e4e 100644
--- a/crates/rust-analyzer/src/bin/args.rs
+++ b/crates/rust-analyzer/src/bin/args.rs
@@ -29,15 +29,18 @@ pub(crate) enum Command {
29 with_deps: bool, 29 with_deps: bool,
30 path: PathBuf, 30 path: PathBuf,
31 load_output_dirs: bool, 31 load_output_dirs: bool,
32 with_proc_macro: bool,
32 }, 33 },
33 Bench { 34 Bench {
34 path: PathBuf, 35 path: PathBuf,
35 what: BenchWhat, 36 what: BenchWhat,
36 load_output_dirs: bool, 37 load_output_dirs: bool,
38 with_proc_macro: bool,
37 }, 39 },
38 Diagnostics { 40 Diagnostics {
39 path: PathBuf, 41 path: PathBuf,
40 load_output_dirs: bool, 42 load_output_dirs: bool,
43 with_proc_macro: bool,
41 /// Include files which are not modules. In rust-analyzer 44 /// Include files which are not modules. In rust-analyzer
42 /// this would include the parser test files. 45 /// this would include the parser test files.
43 all: bool, 46 all: bool,
@@ -148,6 +151,7 @@ FLAGS:
148 -h, --help Prints help information 151 -h, --help Prints help information
149 --memory-usage 152 --memory-usage
150 --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis 153 --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
154 --with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
151 -v, --verbose 155 -v, --verbose
152 -q, --quiet 156 -q, --quiet
153 157
@@ -165,6 +169,7 @@ ARGS:
165 let only: Option<String> = matches.opt_value_from_str(["-o", "--only"])?; 169 let only: Option<String> = matches.opt_value_from_str(["-o", "--only"])?;
166 let with_deps: bool = matches.contains("--with-deps"); 170 let with_deps: bool = matches.contains("--with-deps");
167 let load_output_dirs = matches.contains("--load-output-dirs"); 171 let load_output_dirs = matches.contains("--load-output-dirs");
172 let with_proc_macro = matches.contains("--with-proc-macro");
168 let path = { 173 let path = {
169 let mut trailing = matches.free()?; 174 let mut trailing = matches.free()?;
170 if trailing.len() != 1 { 175 if trailing.len() != 1 {
@@ -173,7 +178,15 @@ ARGS:
173 trailing.pop().unwrap().into() 178 trailing.pop().unwrap().into()
174 }; 179 };
175 180
176 Command::Stats { randomize, memory_usage, only, with_deps, path, load_output_dirs } 181 Command::Stats {
182 randomize,
183 memory_usage,
184 only,
185 with_deps,
186 path,
187 load_output_dirs,
188 with_proc_macro,
189 }
177 } 190 }
178 "analysis-bench" => { 191 "analysis-bench" => {
179 if matches.contains(["-h", "--help"]) { 192 if matches.contains(["-h", "--help"]) {
@@ -187,6 +200,7 @@ USAGE:
187FLAGS: 200FLAGS:
188 -h, --help Prints help information 201 -h, --help Prints help information
189 --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis 202 --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
203 --with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
190 -v, --verbose 204 -v, --verbose
191 205
192OPTIONS: 206OPTIONS:
@@ -214,7 +228,8 @@ ARGS:
214 ), 228 ),
215 }; 229 };
216 let load_output_dirs = matches.contains("--load-output-dirs"); 230 let load_output_dirs = matches.contains("--load-output-dirs");
217 Command::Bench { path, what, load_output_dirs } 231 let with_proc_macro = matches.contains("--with-proc-macro");
232 Command::Bench { path, what, load_output_dirs, with_proc_macro }
218 } 233 }
219 "diagnostics" => { 234 "diagnostics" => {
220 if matches.contains(["-h", "--help"]) { 235 if matches.contains(["-h", "--help"]) {
@@ -237,6 +252,7 @@ ARGS:
237 } 252 }
238 253
239 let load_output_dirs = matches.contains("--load-output-dirs"); 254 let load_output_dirs = matches.contains("--load-output-dirs");
255 let with_proc_macro = matches.contains("--with-proc-macro");
240 let all = matches.contains("--all"); 256 let all = matches.contains("--all");
241 let path = { 257 let path = {
242 let mut trailing = matches.free()?; 258 let mut trailing = matches.free()?;
@@ -246,7 +262,7 @@ ARGS:
246 trailing.pop().unwrap().into() 262 trailing.pop().unwrap().into()
247 }; 263 };
248 264
249 Command::Diagnostics { path, load_output_dirs, all } 265 Command::Diagnostics { path, load_output_dirs, with_proc_macro, all }
250 } 266 }
251 _ => { 267 _ => {
252 eprintln!( 268 eprintln!(
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs
index 7cfc44f01..5f614a013 100644
--- a/crates/rust-analyzer/src/bin/main.rs
+++ b/crates/rust-analyzer/src/bin/main.rs
@@ -25,6 +25,7 @@ fn main() -> Result<()> {
25 with_deps, 25 with_deps,
26 path, 26 path,
27 load_output_dirs, 27 load_output_dirs,
28 with_proc_macro,
28 } => cli::analysis_stats( 29 } => cli::analysis_stats(
29 args.verbosity, 30 args.verbosity,
30 memory_usage, 31 memory_usage,
@@ -33,14 +34,21 @@ fn main() -> Result<()> {
33 with_deps, 34 with_deps,
34 randomize, 35 randomize,
35 load_output_dirs, 36 load_output_dirs,
37 with_proc_macro,
36 )?, 38 )?,
37 39
38 args::Command::Bench { path, what, load_output_dirs } => { 40 args::Command::Bench { path, what, load_output_dirs, with_proc_macro } => {
39 cli::analysis_bench(args.verbosity, path.as_ref(), what, load_output_dirs)? 41 cli::analysis_bench(
42 args.verbosity,
43 path.as_ref(),
44 what,
45 load_output_dirs,
46 with_proc_macro,
47 )?
40 } 48 }
41 49
42 args::Command::Diagnostics { path, load_output_dirs, all } => { 50 args::Command::Diagnostics { path, load_output_dirs, with_proc_macro, all } => {
43 cli::diagnostics(path.as_ref(), load_output_dirs, all)? 51 cli::diagnostics(path.as_ref(), load_output_dirs, with_proc_macro, all)?
44 } 52 }
45 53
46 args::Command::RunServer => run_server()?, 54 args::Command::RunServer => run_server()?,
diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs
index 7667873d5..6147ae207 100644
--- a/crates/rust-analyzer/src/cli/analysis_bench.rs
+++ b/crates/rust-analyzer/src/cli/analysis_bench.rs
@@ -47,12 +47,13 @@ pub fn analysis_bench(
47 path: &Path, 47 path: &Path,
48 what: BenchWhat, 48 what: BenchWhat,
49 load_output_dirs: bool, 49 load_output_dirs: bool,
50 with_proc_macro: bool,
50) -> Result<()> { 51) -> Result<()> {
51 ra_prof::init(); 52 ra_prof::init();
52 53
53 let start = Instant::now(); 54 let start = Instant::now();
54 eprint!("loading: "); 55 eprint!("loading: ");
55 let (mut host, roots) = load_cargo(path, load_output_dirs)?; 56 let (mut host, roots) = load_cargo(path, load_output_dirs, with_proc_macro)?;
56 let db = host.raw_database(); 57 let db = host.raw_database();
57 eprintln!("{:?}\n", start.elapsed()); 58 eprintln!("{:?}\n", start.elapsed());
58 59
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index e9ee0b888..d442cbd63 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -25,9 +25,10 @@ pub fn analysis_stats(
25 with_deps: bool, 25 with_deps: bool,
26 randomize: bool, 26 randomize: bool,
27 load_output_dirs: bool, 27 load_output_dirs: bool,
28 with_proc_macro: bool,
28) -> Result<()> { 29) -> Result<()> {
29 let db_load_time = Instant::now(); 30 let db_load_time = Instant::now();
30 let (mut host, roots) = load_cargo(path, load_output_dirs)?; 31 let (mut host, roots) = load_cargo(path, load_output_dirs, with_proc_macro)?;
31 let db = host.raw_database(); 32 let db = host.raw_database();
32 println!("Database loaded, {} roots, {:?}", roots.len(), db_load_time.elapsed()); 33 println!("Database loaded, {} roots, {:?}", roots.len(), db_load_time.elapsed());
33 let analysis_time = Instant::now(); 34 let analysis_time = Instant::now();
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs
index 92664b415..60daefa3e 100644
--- a/crates/rust-analyzer/src/cli/diagnostics.rs
+++ b/crates/rust-analyzer/src/cli/diagnostics.rs
@@ -9,8 +9,13 @@ use std::{collections::HashSet, path::Path};
9use crate::cli::{load_cargo::load_cargo, Result}; 9use crate::cli::{load_cargo::load_cargo, Result};
10use hir::Semantics; 10use hir::Semantics;
11 11
12pub fn diagnostics(path: &Path, load_output_dirs: bool, all: bool) -> Result<()> { 12pub fn diagnostics(
13 let (host, roots) = load_cargo(path, load_output_dirs)?; 13 path: &Path,
14 load_output_dirs: bool,
15 with_proc_macro: bool,
16 all: bool,
17) -> Result<()> {
18 let (host, roots) = load_cargo(path, load_output_dirs, with_proc_macro)?;
14 let db = host.raw_database(); 19 let db = host.raw_database();
15 let analysis = host.analysis(); 20 let analysis = host.analysis();
16 let semantics = Semantics::new(db); 21 let semantics = Semantics::new(db);
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs
index 43062ea10..f70d92c7f 100644
--- a/crates/rust-analyzer/src/cli/load_cargo.rs
+++ b/crates/rust-analyzer/src/cli/load_cargo.rs
@@ -25,6 +25,7 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId {
25pub(crate) fn load_cargo( 25pub(crate) fn load_cargo(
26 root: &Path, 26 root: &Path,
27 load_out_dirs_from_check: bool, 27 load_out_dirs_from_check: bool,
28 with_proc_macro: bool,
28) -> Result<(AnalysisHost, FxHashMap<SourceRootId, PackageRoot>)> { 29) -> Result<(AnalysisHost, FxHashMap<SourceRootId, PackageRoot>)> {
29 let root = std::env::current_dir()?.join(root); 30 let root = std::env::current_dir()?.join(root);
30 let ws = ProjectWorkspace::discover( 31 let ws = ProjectWorkspace::discover(
@@ -69,7 +70,11 @@ pub(crate) fn load_cargo(
69 }) 70 })
70 .collect::<FxHashMap<_, _>>(); 71 .collect::<FxHashMap<_, _>>();
71 72
72 let proc_macro_client = ProcMacroClient::dummy(); 73 let proc_macro_client = if with_proc_macro {
74 ProcMacroClient::dummy()
75 } else {
76 ProcMacroClient::extern_process(Path::new("ra_proc_macro_srv")).unwrap()
77 };
73 let host = load(&source_roots, ws, &mut vfs, receiver, extern_dirs, &proc_macro_client); 78 let host = load(&source_roots, ws, &mut vfs, receiver, extern_dirs, &proc_macro_client);
74 Ok((host, source_roots)) 79 Ok((host, source_roots))
75} 80}
@@ -175,7 +180,7 @@ mod tests {
175 #[test] 180 #[test]
176 fn test_loading_rust_analyzer() { 181 fn test_loading_rust_analyzer() {
177 let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap(); 182 let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap();
178 let (host, _roots) = load_cargo(path, false).unwrap(); 183 let (host, _roots) = load_cargo(path, false, false).unwrap();
179 let n_crates = Crate::all(host.raw_database()).len(); 184 let n_crates = Crate::all(host.raw_database()).len();
180 // RA has quite a few crates, but the exact count doesn't matter 185 // RA has quite a few crates, but the exact count doesn't matter
181 assert!(n_crates > 20); 186 assert!(n_crates > 20);