1825: add quiet mode to analysis-stats r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-09-12 08:50:38 +00:00 committed by GitHub
commit d614f463de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 116 additions and 82 deletions

View file

@ -4,9 +4,14 @@ use ra_db::SourceDatabase;
use ra_hir::{Crate, HasBodySource, HasSource, HirDisplay, ImplItem, ModuleDef, Ty, TypeWalk};
use ra_syntax::AstNode;
use crate::Result;
use crate::{Result, Verbosity};
pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -> Result<()> {
pub fn run(
verbosity: Verbosity,
memory_usage: bool,
path: &Path,
only: Option<&str>,
) -> Result<()> {
let db_load_time = Instant::now();
let (mut host, roots) = ra_batch::load_cargo(path)?;
let db = host.raw_database();
@ -55,10 +60,14 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -
println!("Item Collection: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage());
let inference_time = Instant::now();
let bar = indicatif::ProgressBar::with_draw_target(
funcs.len() as u64,
indicatif::ProgressDrawTarget::stderr_nohz(),
);
let bar = match verbosity {
Verbosity::Verbose | Verbosity::Normal => indicatif::ProgressBar::with_draw_target(
funcs.len() as u64,
indicatif::ProgressDrawTarget::stderr_nohz(),
),
Verbosity::Quiet => indicatif::ProgressBar::hidden(),
};
bar.set_style(
indicatif::ProgressStyle::default_bar().template("{wide_bar} {pos}/{len}\n{msg}"),
);
@ -70,7 +79,7 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -
for f in funcs {
let name = f.name(db);
let mut msg = format!("processing: {}", name);
if verbose {
if verbosity.is_verbose() {
let src = f.source(db);
let original_file = src.file_id.original_file(db);
let path = db.file_relative_path(original_file);
@ -103,7 +112,7 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -
}
if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr_id) {
num_type_mismatches += 1;
if verbose {
if verbosity.is_verbose() {
let src = f.expr_source(db, expr_id);
if let Some(src) = src {
// FIXME: it might be nice to have a function (on Analysis?) that goes from Source<T> -> (LineCol, LineCol) directly

View file

@ -1,72 +1,73 @@
pub const GLOBAL_HELP: &str = "ra-cli
USAGE:
ra_cli <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
SUBCOMMANDS:
analysis-bench
analysis-stats
highlight
parse
symbols";
pub const ANALYSIS_BENCH_HELP: &str = "ra_cli-analysis-bench
USAGE:
ra_cli analysis-bench [FLAGS] [OPTIONS] [PATH]
FLAGS:
-h, --help Prints help information
-v, --verbose
OPTIONS:
--complete <PATH:LINE:COLUMN> Compute completions at this location
--highlight <PATH> Hightlight this file
ARGS:
<PATH> Project to analyse";
pub const ANALYSIS_STATS_HELP: &str = "ra-cli-analysis-stats
USAGE:
ra_cli analysis-stats [FLAGS] [OPTIONS] [PATH]
FLAGS:
-h, --help Prints help information
--memory-usage
-v, --verbose
OPTIONS:
-o <ONLY>
ARGS:
<PATH>";
pub const HIGHLIGHT_HELP: &str = "ra-cli-highlight
USAGE:
ra_cli highlight [FLAGS]
FLAGS:
-h, --help Prints help information
-r, --rainbow";
pub const SYMBOLS_HELP: &str = "ra-cli-symbols
USAGE:
ra_cli highlight [FLAGS]
FLAGS:
-h, --help Prints help inforamtion";
pub const PARSE_HELP: &str = "ra-cli-parse
USAGE:
ra_cli parse [FLAGS]
FLAGS:
-h, --help Prints help inforamtion
--no-dump";
pub const GLOBAL_HELP: &str = "ra-cli
USAGE:
ra_cli <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
SUBCOMMANDS:
analysis-bench
analysis-stats
highlight
parse
symbols";
pub const ANALYSIS_BENCH_HELP: &str = "ra_cli-analysis-bench
USAGE:
ra_cli analysis-bench [FLAGS] [OPTIONS] [PATH]
FLAGS:
-h, --help Prints help information
-v, --verbose
OPTIONS:
--complete <PATH:LINE:COLUMN> Compute completions at this location
--highlight <PATH> Hightlight this file
ARGS:
<PATH> Project to analyse";
pub const ANALYSIS_STATS_HELP: &str = "ra-cli-analysis-stats
USAGE:
ra_cli analysis-stats [FLAGS] [OPTIONS] [PATH]
FLAGS:
-h, --help Prints help information
--memory-usage
-v, --verbose
-q, --quiet
OPTIONS:
-o <ONLY>
ARGS:
<PATH>";
pub const HIGHLIGHT_HELP: &str = "ra-cli-highlight
USAGE:
ra_cli highlight [FLAGS]
FLAGS:
-h, --help Prints help information
-r, --rainbow";
pub const SYMBOLS_HELP: &str = "ra-cli-symbols
USAGE:
ra_cli highlight [FLAGS]
FLAGS:
-h, --help Prints help inforamtion";
pub const PARSE_HELP: &str = "ra-cli-parse
USAGE:
ra_cli parse [FLAGS]
FLAGS:
-h, --help Prints help inforamtion
--no-dump";

View file

@ -12,6 +12,22 @@ use ra_syntax::{AstNode, SourceFile};
type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>;
#[derive(Clone, Copy)]
pub enum Verbosity {
Verbose,
Normal,
Quiet,
}
impl Verbosity {
fn is_verbose(&self) -> bool {
match self {
Verbosity::Verbose => true,
_ => false,
}
}
}
fn main() -> Result<()> {
Logger::with_env().start()?;
@ -67,7 +83,15 @@ fn main() -> Result<()> {
eprintln!("{}", help::ANALYSIS_STATS_HELP);
return Ok(());
}
let verbose = matches.contains(["-v", "--verbose"]);
let verbosity = match (
matches.contains(["-v", "--verbose"]),
matches.contains(["-q", "--quiet"]),
) {
(false, false) => Verbosity::Normal,
(false, true) => Verbosity::Quiet,
(true, false) => Verbosity::Verbose,
(true, true) => Err("Invalid flags: -q conflicts with -v")?,
};
let memory_usage = matches.contains("--memory-usage");
let only = matches.value_from_str(["-o", "--only"])?.map(|v: String| v.to_owned());
let path = {
@ -79,7 +103,7 @@ fn main() -> Result<()> {
trailing.pop().unwrap()
};
analysis_stats::run(
verbose,
verbosity,
memory_usage,
path.as_ref(),
only.as_ref().map(String::as_ref),