diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_cli/src/analysis_stats.rs | 25 | ||||
-rw-r--r-- | crates/ra_cli/src/help.rs | 145 | ||||
-rw-r--r-- | crates/ra_cli/src/main.rs | 28 |
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; | |||
4 | use ra_hir::{Crate, HasBodySource, HasSource, HirDisplay, ImplItem, ModuleDef, Ty, TypeWalk}; | 4 | use ra_hir::{Crate, HasBodySource, HasSource, HirDisplay, ImplItem, ModuleDef, Ty, TypeWalk}; |
5 | use ra_syntax::AstNode; | 5 | use ra_syntax::AstNode; |
6 | 6 | ||
7 | use crate::Result; | 7 | use crate::{Result, Verbosity}; |
8 | 8 | ||
9 | pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -> Result<()> { | 9 | pub 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 @@ | |||
1 | pub const GLOBAL_HELP: &str = "ra-cli | 1 | pub const GLOBAL_HELP: &str = "ra-cli |
2 | 2 | ||
3 | USAGE: | 3 | USAGE: |
4 | ra_cli <SUBCOMMAND> | 4 | ra_cli <SUBCOMMAND> |
5 | 5 | ||
6 | FLAGS: | 6 | FLAGS: |
7 | -h, --help Prints help information | 7 | -h, --help Prints help information |
8 | 8 | ||
9 | SUBCOMMANDS: | 9 | SUBCOMMANDS: |
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 | ||
16 | pub const ANALYSIS_BENCH_HELP: &str = "ra_cli-analysis-bench | 16 | pub const ANALYSIS_BENCH_HELP: &str = "ra_cli-analysis-bench |
17 | 17 | ||
18 | USAGE: | 18 | USAGE: |
19 | ra_cli analysis-bench [FLAGS] [OPTIONS] [PATH] | 19 | ra_cli analysis-bench [FLAGS] [OPTIONS] [PATH] |
20 | 20 | ||
21 | FLAGS: | 21 | FLAGS: |
22 | -h, --help Prints help information | 22 | -h, --help Prints help information |
23 | -v, --verbose | 23 | -v, --verbose |
24 | 24 | ||
25 | OPTIONS: | 25 | OPTIONS: |
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 | ||
29 | ARGS: | 29 | ARGS: |
30 | <PATH> Project to analyse"; | 30 | <PATH> Project to analyse"; |
31 | 31 | ||
32 | pub const ANALYSIS_STATS_HELP: &str = "ra-cli-analysis-stats | 32 | pub const ANALYSIS_STATS_HELP: &str = "ra-cli-analysis-stats |
33 | 33 | ||
34 | USAGE: | 34 | USAGE: |
35 | ra_cli analysis-stats [FLAGS] [OPTIONS] [PATH] | 35 | ra_cli analysis-stats [FLAGS] [OPTIONS] [PATH] |
36 | 36 | ||
37 | FLAGS: | 37 | FLAGS: |
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 | |
42 | OPTIONS: | 42 | |
43 | -o <ONLY> | 43 | OPTIONS: |
44 | 44 | -o <ONLY> | |
45 | ARGS: | 45 | |
46 | <PATH>"; | 46 | ARGS: |
47 | 47 | <PATH>"; | |
48 | pub const HIGHLIGHT_HELP: &str = "ra-cli-highlight | 48 | |
49 | 49 | pub const HIGHLIGHT_HELP: &str = "ra-cli-highlight | |
50 | USAGE: | 50 | |
51 | ra_cli highlight [FLAGS] | 51 | USAGE: |
52 | 52 | ra_cli highlight [FLAGS] | |
53 | FLAGS: | 53 | |
54 | -h, --help Prints help information | 54 | FLAGS: |
55 | -r, --rainbow"; | 55 | -h, --help Prints help information |
56 | 56 | -r, --rainbow"; | |
57 | pub const SYMBOLS_HELP: &str = "ra-cli-symbols | 57 | |
58 | 58 | pub const SYMBOLS_HELP: &str = "ra-cli-symbols | |
59 | USAGE: | 59 | |
60 | ra_cli highlight [FLAGS] | 60 | USAGE: |
61 | 61 | ra_cli highlight [FLAGS] | |
62 | FLAGS: | 62 | |
63 | -h, --help Prints help inforamtion"; | 63 | FLAGS: |
64 | 64 | -h, --help Prints help inforamtion"; | |
65 | pub const PARSE_HELP: &str = "ra-cli-parse | 65 | |
66 | 66 | pub const PARSE_HELP: &str = "ra-cli-parse | |
67 | USAGE: | 67 | |
68 | ra_cli parse [FLAGS] | 68 | USAGE: |
69 | 69 | ra_cli parse [FLAGS] | |
70 | FLAGS: | 70 | |
71 | -h, --help Prints help inforamtion | 71 | FLAGS: |
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 | ||
13 | type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>; | 13 | type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>; |
14 | 14 | ||
15 | #[derive(Clone, Copy)] | ||
16 | pub enum Verbosity { | ||
17 | Verbose, | ||
18 | Normal, | ||
19 | Quiet, | ||
20 | } | ||
21 | |||
22 | impl Verbosity { | ||
23 | fn is_verbose(&self) -> bool { | ||
24 | match self { | ||
25 | Verbosity::Verbose => true, | ||
26 | _ => false, | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | |||
15 | fn main() -> Result<()> { | 31 | fn 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), |