mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
Add with-proc-macro in bench ,stats and diagnositcs
This commit is contained in:
parent
aa887d7ab4
commit
22e33f308a
6 changed files with 49 additions and 13 deletions
|
@ -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<String> = 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!(
|
||||
|
|
|
@ -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()?,
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<SourceRootId, PackageRoot>)> {
|
||||
let root = std::env::current_dir()?.join(root);
|
||||
let ws = ProjectWorkspace::discover(
|
||||
|
@ -69,7 +70,11 @@ pub(crate) fn load_cargo(
|
|||
})
|
||||
.collect::<FxHashMap<_, _>>();
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue