Allow targeting a specific function with analysis-stats

This can be useful for debugging.
This commit is contained in:
Florian Diebold 2019-05-07 12:09:10 +02:00
parent 4083caa233
commit 880ef25a9e
2 changed files with 12 additions and 4 deletions

View File

@ -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() {

View File

@ -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!(),
}