From 880ef25a9e9fe3071181d27c6d8ea672bf76d680 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Tue, 7 May 2019 12:09:10 +0200 Subject: Allow targeting a specific function with analysis-stats This can be useful for debugging. --- crates/ra_cli/src/analysis_stats.rs | 9 +++++++-- crates/ra_cli/src/main.rs | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs index 4516ed660..86ee0cb63 100644 --- a/crates/ra_cli/src/analysis_stats.rs +++ b/crates/ra_cli/src/analysis_stats.rs @@ -7,7 +7,7 @@ use ra_syntax::AstNode; use crate::Result; -pub fn run(verbose: bool) -> Result<()> { +pub fn run(verbose: bool, only: Option<&str>) -> Result<()> { let db_load_time = Instant::now(); let (db, roots) = BatchDatabase::load_cargo(".")?; println!("Database loaded, {} roots, {:?}", roots.len(), db_load_time.elapsed()); @@ -57,14 +57,19 @@ pub fn run(verbose: bool) -> Result<()> { let mut num_exprs_unknown = 0; let mut num_exprs_partially_unknown = 0; for f in funcs { + let name = f.name(&db); if verbose { let (file_id, source) = f.source(&db); let original_file = file_id.original_file(&db); let path = db.file_relative_path(original_file); let syntax_range = source.syntax().range(); - let name = f.name(&db); println!("{} ({:?} {})", name, path, syntax_range); } + if let Some(only_name) = only { + if name.to_string() != only_name { + continue; + } + } let body = f.body(&db); let inference_result = f.infer(&db); for (expr_id, _) in body.exprs() { diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index 45555be6e..11790d2e7 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs @@ -23,7 +23,9 @@ fn main() -> Result<()> { .subcommand(SubCommand::with_name("parse").arg(Arg::with_name("no-dump").long("--no-dump"))) .subcommand(SubCommand::with_name("symbols")) .subcommand( - SubCommand::with_name("analysis-stats").arg(Arg::with_name("verbose").short("v")), + SubCommand::with_name("analysis-stats") + .arg(Arg::with_name("verbose").short("v")) + .arg(Arg::with_name("only").short("o").takes_value(true)), ) .get_matches(); match matches.subcommand() { @@ -51,7 +53,8 @@ fn main() -> Result<()> { } ("analysis-stats", Some(matches)) => { let verbose = matches.is_present("verbose"); - analysis_stats::run(verbose)?; + let only = matches.value_of("only"); + analysis_stats::run(verbose, only)?; } _ => unreachable!(), } -- cgit v1.2.3