From 22e33f308a7dfe924bf2d10f9041e91cec1349a0 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 12 Apr 2020 18:25:31 +0800 Subject: Add with-proc-macro in bench ,stats and diagnositcs --- crates/rust-analyzer/src/bin/args.rs | 22 +++++++++++++++++++--- crates/rust-analyzer/src/bin/main.rs | 16 ++++++++++++---- crates/rust-analyzer/src/cli/analysis_bench.rs | 3 ++- crates/rust-analyzer/src/cli/analysis_stats.rs | 3 ++- crates/rust-analyzer/src/cli/diagnostics.rs | 9 +++++++-- crates/rust-analyzer/src/cli/load_cargo.rs | 9 +++++++-- 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 { with_deps: bool, path: PathBuf, load_output_dirs: bool, + with_proc_macro: bool, }, Bench { path: PathBuf, what: BenchWhat, load_output_dirs: bool, + with_proc_macro: bool, }, Diagnostics { path: PathBuf, load_output_dirs: bool, + with_proc_macro: bool, /// Include files which are not modules. In rust-analyzer /// this would include the parser test files. all: bool, @@ -148,6 +151,7 @@ FLAGS: -h, --help Prints help information --memory-usage --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis + --with-proc-macro Use ra-proc-macro-srv for proc-macro expanding -v, --verbose -q, --quiet @@ -165,6 +169,7 @@ ARGS: let only: Option = matches.opt_value_from_str(["-o", "--only"])?; let with_deps: bool = matches.contains("--with-deps"); let load_output_dirs = matches.contains("--load-output-dirs"); + let with_proc_macro = matches.contains("--with-proc-macro"); let path = { let mut trailing = matches.free()?; if trailing.len() != 1 { @@ -173,7 +178,15 @@ ARGS: trailing.pop().unwrap().into() }; - Command::Stats { randomize, memory_usage, only, with_deps, path, load_output_dirs } + Command::Stats { + randomize, + memory_usage, + only, + with_deps, + path, + load_output_dirs, + with_proc_macro, + } } "analysis-bench" => { if matches.contains(["-h", "--help"]) { @@ -187,6 +200,7 @@ USAGE: FLAGS: -h, --help Prints help information --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis + --with-proc-macro Use ra-proc-macro-srv for proc-macro expanding -v, --verbose OPTIONS: @@ -214,7 +228,8 @@ ARGS: ), }; let load_output_dirs = matches.contains("--load-output-dirs"); - Command::Bench { path, what, load_output_dirs } + let with_proc_macro = matches.contains("--with-proc-macro"); + Command::Bench { path, what, load_output_dirs, with_proc_macro } } "diagnostics" => { if matches.contains(["-h", "--help"]) { @@ -237,6 +252,7 @@ ARGS: } let load_output_dirs = matches.contains("--load-output-dirs"); + let with_proc_macro = matches.contains("--with-proc-macro"); let all = matches.contains("--all"); let path = { let mut trailing = matches.free()?; @@ -246,7 +262,7 @@ ARGS: trailing.pop().unwrap().into() }; - Command::Diagnostics { path, load_output_dirs, all } + Command::Diagnostics { path, load_output_dirs, with_proc_macro, all } } _ => { 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<()> { with_deps, path, load_output_dirs, + with_proc_macro, } => cli::analysis_stats( args.verbosity, memory_usage, @@ -33,14 +34,21 @@ fn main() -> Result<()> { with_deps, randomize, load_output_dirs, + with_proc_macro, )?, - args::Command::Bench { path, what, load_output_dirs } => { - cli::analysis_bench(args.verbosity, path.as_ref(), what, load_output_dirs)? + args::Command::Bench { path, what, load_output_dirs, with_proc_macro } => { + cli::analysis_bench( + args.verbosity, + path.as_ref(), + what, + load_output_dirs, + with_proc_macro, + )? } - args::Command::Diagnostics { path, load_output_dirs, all } => { - cli::diagnostics(path.as_ref(), load_output_dirs, all)? + args::Command::Diagnostics { path, load_output_dirs, with_proc_macro, all } => { + cli::diagnostics(path.as_ref(), load_output_dirs, with_proc_macro, all)? } 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( path: &Path, what: BenchWhat, load_output_dirs: bool, + with_proc_macro: bool, ) -> Result<()> { ra_prof::init(); let start = Instant::now(); eprint!("loading: "); - let (mut host, roots) = load_cargo(path, load_output_dirs)?; + let (mut host, roots) = load_cargo(path, load_output_dirs, with_proc_macro)?; let db = host.raw_database(); eprintln!("{:?}\n", start.elapsed()); 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( with_deps: bool, randomize: bool, load_output_dirs: bool, + with_proc_macro: bool, ) -> Result<()> { let db_load_time = Instant::now(); - let (mut host, roots) = load_cargo(path, load_output_dirs)?; + let (mut host, roots) = load_cargo(path, load_output_dirs, with_proc_macro)?; let db = host.raw_database(); println!("Database loaded, {} roots, {:?}", roots.len(), db_load_time.elapsed()); 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}; use crate::cli::{load_cargo::load_cargo, Result}; use hir::Semantics; -pub fn diagnostics(path: &Path, load_output_dirs: bool, all: bool) -> Result<()> { - let (host, roots) = load_cargo(path, load_output_dirs)?; +pub fn diagnostics( + path: &Path, + load_output_dirs: bool, + with_proc_macro: bool, + all: bool, +) -> Result<()> { + let (host, roots) = load_cargo(path, load_output_dirs, with_proc_macro)?; let db = host.raw_database(); let analysis = host.analysis(); 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 { pub(crate) fn load_cargo( root: &Path, load_out_dirs_from_check: bool, + with_proc_macro: bool, ) -> Result<(AnalysisHost, FxHashMap)> { let root = std::env::current_dir()?.join(root); let ws = ProjectWorkspace::discover( @@ -69,7 +70,11 @@ pub(crate) fn load_cargo( }) .collect::>(); - let proc_macro_client = ProcMacroClient::dummy(); + let proc_macro_client = if with_proc_macro { + ProcMacroClient::dummy() + } else { + ProcMacroClient::extern_process(Path::new("ra_proc_macro_srv")).unwrap() + }; let host = load(&source_roots, ws, &mut vfs, receiver, extern_dirs, &proc_macro_client); Ok((host, source_roots)) } @@ -175,7 +180,7 @@ mod tests { #[test] fn test_loading_rust_analyzer() { let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap(); - let (host, _roots) = load_cargo(path, false).unwrap(); + let (host, _roots) = load_cargo(path, false, false).unwrap(); let n_crates = Crate::all(host.raw_database()).len(); // RA has quite a few crates, but the exact count doesn't matter assert!(n_crates > 20); -- cgit v1.2.3