diff options
Diffstat (limited to 'crates/ra_cli/src/main.rs')
-rw-r--r-- | crates/ra_cli/src/main.rs | 88 |
1 files changed, 57 insertions, 31 deletions
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index f4eb0bd3c..66258c860 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs | |||
@@ -5,7 +5,7 @@ mod analysis_stats; | |||
5 | mod analysis_bench; | 5 | mod analysis_bench; |
6 | mod progress_report; | 6 | mod progress_report; |
7 | 7 | ||
8 | use std::{error::Error, fmt::Write, io::Read, path::PathBuf}; | 8 | use std::{error::Error, fmt::Write, io::Read, path::PathBuf, str::FromStr}; |
9 | 9 | ||
10 | use pico_args::Arguments; | 10 | use pico_args::Arguments; |
11 | use ra_ide::{file_structure, Analysis}; | 11 | use ra_ide::{file_structure, Analysis}; |
@@ -51,14 +51,37 @@ fn main() -> Result<()> { | |||
51 | randomize, | 51 | randomize, |
52 | )?; | 52 | )?; |
53 | } | 53 | } |
54 | Command::Bench { verbosity, path, op } => { | 54 | Command::Bench { verbosity, path, what } => { |
55 | analysis_bench::run(verbosity, path.as_ref(), op)?; | 55 | analysis_bench::run(verbosity, path.as_ref(), what)?; |
56 | } | 56 | } |
57 | } | 57 | } |
58 | 58 | ||
59 | Ok(()) | 59 | Ok(()) |
60 | } | 60 | } |
61 | 61 | ||
62 | enum Command { | ||
63 | Parse { | ||
64 | no_dump: bool, | ||
65 | }, | ||
66 | Symbols, | ||
67 | Highlight { | ||
68 | rainbow: bool, | ||
69 | }, | ||
70 | Stats { | ||
71 | verbosity: Verbosity, | ||
72 | randomize: bool, | ||
73 | memory_usage: bool, | ||
74 | only: Option<String>, | ||
75 | with_deps: bool, | ||
76 | path: PathBuf, | ||
77 | }, | ||
78 | Bench { | ||
79 | verbosity: Verbosity, | ||
80 | path: PathBuf, | ||
81 | what: BenchWhat, | ||
82 | }, | ||
83 | } | ||
84 | |||
62 | #[derive(Clone, Copy)] | 85 | #[derive(Clone, Copy)] |
63 | pub enum Verbosity { | 86 | pub enum Verbosity { |
64 | Spammy, | 87 | Spammy, |
@@ -82,27 +105,30 @@ impl Verbosity { | |||
82 | } | 105 | } |
83 | } | 106 | } |
84 | 107 | ||
85 | enum Command { | 108 | enum BenchWhat { |
86 | Parse { | 109 | Highlight { path: PathBuf }, |
87 | no_dump: bool, | 110 | Complete(Position), |
88 | }, | 111 | GotoDef(Position), |
89 | Symbols, | 112 | } |
90 | Highlight { | 113 | |
91 | rainbow: bool, | 114 | pub(crate) struct Position { |
92 | }, | 115 | path: PathBuf, |
93 | Stats { | 116 | line: u32, |
94 | verbosity: Verbosity, | 117 | column: u32, |
95 | randomize: bool, | 118 | } |
96 | memory_usage: bool, | 119 | |
97 | only: Option<String>, | 120 | impl FromStr for Position { |
98 | with_deps: bool, | 121 | type Err = Box<dyn std::error::Error + Send + Sync>; |
99 | path: PathBuf, | 122 | fn from_str(s: &str) -> Result<Self> { |
100 | }, | 123 | let (path_line, column) = rsplit_at_char(s, ':')?; |
101 | Bench { | 124 | let (path, line) = rsplit_at_char(path_line, ':')?; |
102 | verbosity: Verbosity, | 125 | Ok(Position { path: path.into(), line: line.parse()?, column: column.parse()? }) |
103 | path: PathBuf, | 126 | } |
104 | op: analysis_bench::Op, | 127 | } |
105 | }, | 128 | |
129 | fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> { | ||
130 | let idx = s.rfind(':').ok_or_else(|| format!("no `{}` in {}", c, s))?; | ||
131 | Ok((&s[..idx], &s[idx + 1..])) | ||
106 | } | 132 | } |
107 | 133 | ||
108 | struct HelpPrinted; | 134 | struct HelpPrinted; |
@@ -248,17 +274,17 @@ ARGS: | |||
248 | 274 | ||
249 | let path: PathBuf = matches.opt_value_from_str("--path")?.unwrap_or_default(); | 275 | let path: PathBuf = matches.opt_value_from_str("--path")?.unwrap_or_default(); |
250 | let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?; | 276 | let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?; |
251 | let complete_path: Option<String> = matches.opt_value_from_str("--complete")?; | 277 | let complete_path: Option<Position> = matches.opt_value_from_str("--complete")?; |
252 | let goto_def_path: Option<String> = matches.opt_value_from_str("--goto-def")?; | 278 | let goto_def_path: Option<Position> = matches.opt_value_from_str("--goto-def")?; |
253 | let op = match (highlight_path, complete_path, goto_def_path) { | 279 | let what = match (highlight_path, complete_path, goto_def_path) { |
254 | (Some(path), None, None) => analysis_bench::Op::Highlight { path: path.into() }, | 280 | (Some(path), None, None) => BenchWhat::Highlight { path: path.into() }, |
255 | (None, Some(position), None) => analysis_bench::Op::Complete(position.parse()?), | 281 | (None, Some(position), None) => BenchWhat::Complete(position), |
256 | (None, None, Some(position)) => analysis_bench::Op::GotoDef(position.parse()?), | 282 | (None, None, Some(position)) => BenchWhat::GotoDef(position), |
257 | _ => panic!( | 283 | _ => panic!( |
258 | "exactly one of `--highlight`, `--complete` or `--goto-def` must be set" | 284 | "exactly one of `--highlight`, `--complete` or `--goto-def` must be set" |
259 | ), | 285 | ), |
260 | }; | 286 | }; |
261 | Command::Bench { verbosity, path, op } | 287 | Command::Bench { verbosity, path, what } |
262 | } | 288 | } |
263 | _ => { | 289 | _ => { |
264 | eprintln!( | 290 | eprintln!( |