aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_cli
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_cli')
-rw-r--r--crates/ra_cli/src/analysis_stats.rs25
-rw-r--r--crates/ra_cli/src/help.rs145
-rw-r--r--crates/ra_cli/src/main.rs28
3 files changed, 116 insertions, 82 deletions
diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs
index 1fad5b233..8f4ce42da 100644
--- a/crates/ra_cli/src/analysis_stats.rs
+++ b/crates/ra_cli/src/analysis_stats.rs
@@ -4,9 +4,14 @@ use ra_db::SourceDatabase;
4use ra_hir::{Crate, HasBodySource, HasSource, HirDisplay, ImplItem, ModuleDef, Ty, TypeWalk}; 4use ra_hir::{Crate, HasBodySource, HasSource, HirDisplay, ImplItem, ModuleDef, Ty, TypeWalk};
5use ra_syntax::AstNode; 5use ra_syntax::AstNode;
6 6
7use crate::Result; 7use crate::{Result, Verbosity};
8 8
9pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -> Result<()> { 9pub fn run(
10 verbosity: Verbosity,
11 memory_usage: bool,
12 path: &Path,
13 only: Option<&str>,
14) -> Result<()> {
10 let db_load_time = Instant::now(); 15 let db_load_time = Instant::now();
11 let (mut host, roots) = ra_batch::load_cargo(path)?; 16 let (mut host, roots) = ra_batch::load_cargo(path)?;
12 let db = host.raw_database(); 17 let db = host.raw_database();
@@ -55,10 +60,14 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -
55 println!("Item Collection: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); 60 println!("Item Collection: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage());
56 61
57 let inference_time = Instant::now(); 62 let inference_time = Instant::now();
58 let bar = indicatif::ProgressBar::with_draw_target( 63 let bar = match verbosity {
59 funcs.len() as u64, 64 Verbosity::Verbose | Verbosity::Normal => indicatif::ProgressBar::with_draw_target(
60 indicatif::ProgressDrawTarget::stderr_nohz(), 65 funcs.len() as u64,
61 ); 66 indicatif::ProgressDrawTarget::stderr_nohz(),
67 ),
68 Verbosity::Quiet => indicatif::ProgressBar::hidden(),
69 };
70
62 bar.set_style( 71 bar.set_style(
63 indicatif::ProgressStyle::default_bar().template("{wide_bar} {pos}/{len}\n{msg}"), 72 indicatif::ProgressStyle::default_bar().template("{wide_bar} {pos}/{len}\n{msg}"),
64 ); 73 );
@@ -70,7 +79,7 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -
70 for f in funcs { 79 for f in funcs {
71 let name = f.name(db); 80 let name = f.name(db);
72 let mut msg = format!("processing: {}", name); 81 let mut msg = format!("processing: {}", name);
73 if verbose { 82 if verbosity.is_verbose() {
74 let src = f.source(db); 83 let src = f.source(db);
75 let original_file = src.file_id.original_file(db); 84 let original_file = src.file_id.original_file(db);
76 let path = db.file_relative_path(original_file); 85 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>) -
103 } 112 }
104 if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr_id) { 113 if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr_id) {
105 num_type_mismatches += 1; 114 num_type_mismatches += 1;
106 if verbose { 115 if verbosity.is_verbose() {
107 let src = f.expr_source(db, expr_id); 116 let src = f.expr_source(db, expr_id);
108 if let Some(src) = src { 117 if let Some(src) = src {
109 // FIXME: it might be nice to have a function (on Analysis?) that goes from Source<T> -> (LineCol, LineCol) directly 118 // FIXME: it might be nice to have a function (on Analysis?) that goes from Source<T> -> (LineCol, LineCol) directly
diff --git a/crates/ra_cli/src/help.rs b/crates/ra_cli/src/help.rs
index 5171578f0..2a74b8733 100644
--- a/crates/ra_cli/src/help.rs
+++ b/crates/ra_cli/src/help.rs
@@ -1,72 +1,73 @@
1pub const GLOBAL_HELP: &str = "ra-cli 1pub const GLOBAL_HELP: &str = "ra-cli
2 2
3USAGE: 3USAGE:
4 ra_cli <SUBCOMMAND> 4 ra_cli <SUBCOMMAND>
5 5
6FLAGS: 6FLAGS:
7 -h, --help Prints help information 7 -h, --help Prints help information
8 8
9SUBCOMMANDS: 9SUBCOMMANDS:
10 analysis-bench 10 analysis-bench
11 analysis-stats 11 analysis-stats
12 highlight 12 highlight
13 parse 13 parse
14 symbols"; 14 symbols";
15 15
16pub const ANALYSIS_BENCH_HELP: &str = "ra_cli-analysis-bench 16pub const ANALYSIS_BENCH_HELP: &str = "ra_cli-analysis-bench
17 17
18USAGE: 18USAGE:
19 ra_cli analysis-bench [FLAGS] [OPTIONS] [PATH] 19 ra_cli analysis-bench [FLAGS] [OPTIONS] [PATH]
20 20
21FLAGS: 21FLAGS:
22 -h, --help Prints help information 22 -h, --help Prints help information
23 -v, --verbose 23 -v, --verbose
24 24
25OPTIONS: 25OPTIONS:
26 --complete <PATH:LINE:COLUMN> Compute completions at this location 26 --complete <PATH:LINE:COLUMN> Compute completions at this location
27 --highlight <PATH> Hightlight this file 27 --highlight <PATH> Hightlight this file
28 28
29ARGS: 29ARGS:
30 <PATH> Project to analyse"; 30 <PATH> Project to analyse";
31 31
32pub const ANALYSIS_STATS_HELP: &str = "ra-cli-analysis-stats 32pub const ANALYSIS_STATS_HELP: &str = "ra-cli-analysis-stats
33 33
34USAGE: 34USAGE:
35 ra_cli analysis-stats [FLAGS] [OPTIONS] [PATH] 35 ra_cli analysis-stats [FLAGS] [OPTIONS] [PATH]
36 36
37FLAGS: 37FLAGS:
38 -h, --help Prints help information 38 -h, --help Prints help information
39 --memory-usage 39 --memory-usage
40 -v, --verbose 40 -v, --verbose
41 41 -q, --quiet
42OPTIONS: 42
43 -o <ONLY> 43OPTIONS:
44 44 -o <ONLY>
45ARGS: 45
46 <PATH>"; 46ARGS:
47 47 <PATH>";
48pub const HIGHLIGHT_HELP: &str = "ra-cli-highlight 48
49 49pub const HIGHLIGHT_HELP: &str = "ra-cli-highlight
50USAGE: 50
51 ra_cli highlight [FLAGS] 51USAGE:
52 52 ra_cli highlight [FLAGS]
53FLAGS: 53
54 -h, --help Prints help information 54FLAGS:
55 -r, --rainbow"; 55 -h, --help Prints help information
56 56 -r, --rainbow";
57pub const SYMBOLS_HELP: &str = "ra-cli-symbols 57
58 58pub const SYMBOLS_HELP: &str = "ra-cli-symbols
59USAGE: 59
60 ra_cli highlight [FLAGS] 60USAGE:
61 61 ra_cli highlight [FLAGS]
62FLAGS: 62
63 -h, --help Prints help inforamtion"; 63FLAGS:
64 64 -h, --help Prints help inforamtion";
65pub const PARSE_HELP: &str = "ra-cli-parse 65
66 66pub const PARSE_HELP: &str = "ra-cli-parse
67USAGE: 67
68 ra_cli parse [FLAGS] 68USAGE:
69 69 ra_cli parse [FLAGS]
70FLAGS: 70
71 -h, --help Prints help inforamtion 71FLAGS:
72 --no-dump"; 72 -h, --help Prints help inforamtion
73 --no-dump";
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs
index 23bb83ff1..ca9275cd4 100644
--- a/crates/ra_cli/src/main.rs
+++ b/crates/ra_cli/src/main.rs
@@ -12,6 +12,22 @@ use ra_syntax::{AstNode, SourceFile};
12 12
13type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>; 13type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>;
14 14
15#[derive(Clone, Copy)]
16pub enum Verbosity {
17 Verbose,
18 Normal,
19 Quiet,
20}
21
22impl Verbosity {
23 fn is_verbose(&self) -> bool {
24 match self {
25 Verbosity::Verbose => true,
26 _ => false,
27 }
28 }
29}
30
15fn main() -> Result<()> { 31fn main() -> Result<()> {
16 Logger::with_env().start()?; 32 Logger::with_env().start()?;
17 33
@@ -67,7 +83,15 @@ fn main() -> Result<()> {
67 eprintln!("{}", help::ANALYSIS_STATS_HELP); 83 eprintln!("{}", help::ANALYSIS_STATS_HELP);
68 return Ok(()); 84 return Ok(());
69 } 85 }
70 let verbose = matches.contains(["-v", "--verbose"]); 86 let verbosity = match (
87 matches.contains(["-v", "--verbose"]),
88 matches.contains(["-q", "--quiet"]),
89 ) {
90 (false, false) => Verbosity::Normal,
91 (false, true) => Verbosity::Quiet,
92 (true, false) => Verbosity::Verbose,
93 (true, true) => Err("Invalid flags: -q conflicts with -v")?,
94 };
71 let memory_usage = matches.contains("--memory-usage"); 95 let memory_usage = matches.contains("--memory-usage");
72 let only = matches.value_from_str(["-o", "--only"])?.map(|v: String| v.to_owned()); 96 let only = matches.value_from_str(["-o", "--only"])?.map(|v: String| v.to_owned());
73 let path = { 97 let path = {
@@ -79,7 +103,7 @@ fn main() -> Result<()> {
79 trailing.pop().unwrap() 103 trailing.pop().unwrap()
80 }; 104 };
81 analysis_stats::run( 105 analysis_stats::run(
82 verbose, 106 verbosity,
83 memory_usage, 107 memory_usage,
84 path.as_ref(), 108 path.as_ref(),
85 only.as_ref().map(String::as_ref), 109 only.as_ref().map(String::as_ref),