aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-08-26 11:52:42 +0100
committerAleksey Kladov <[email protected]>2020-08-26 12:20:46 +0100
commitbb50614d8871f55ad4f0306cba289681a29c14ef (patch)
tree04850608609f12b67ae5018ae00861e7a950ba2b /crates
parenta53c6f6feef231ecfb4e66d0e446e4148e816a2c (diff)
Simplify help
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/bin/args.rs312
-rw-r--r--crates/rust-analyzer/src/bin/main.rs4
-rw-r--r--crates/rust-analyzer/src/cli/diagnostics.rs7
3 files changed, 99 insertions, 224 deletions
diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs
index 45dc62ea7..b724ae454 100644
--- a/crates/rust-analyzer/src/bin/args.rs
+++ b/crates/rust-analyzer/src/bin/args.rs
@@ -18,36 +18,93 @@ pub(crate) struct Args {
18} 18}
19 19
20pub(crate) enum Command { 20pub(crate) enum Command {
21 Parse { 21 Parse { no_dump: bool },
22 no_dump: bool,
23 },
24 Symbols, 22 Symbols,
25 Highlight { 23 Highlight { rainbow: bool },
26 rainbow: bool,
27 },
28 AnalysisStats(AnalysisStatsCmd), 24 AnalysisStats(AnalysisStatsCmd),
29 Bench(BenchCmd), 25 Bench(BenchCmd),
30 Diagnostics { 26 Diagnostics { path: PathBuf, load_output_dirs: bool, with_proc_macro: bool },
31 path: PathBuf, 27 Ssr { rules: Vec<SsrRule> },
32 load_output_dirs: bool, 28 StructuredSearch { debug_snippet: Option<String>, patterns: Vec<SsrPattern> },
33 with_proc_macro: bool,
34 /// Include files which are not modules. In rust-analyzer
35 /// this would include the parser test files.
36 all: bool,
37 },
38 Ssr {
39 rules: Vec<SsrRule>,
40 },
41 StructuredSearch {
42 debug_snippet: Option<String>,
43 patterns: Vec<SsrPattern>,
44 },
45 ProcMacro, 29 ProcMacro,
46 RunServer, 30 RunServer,
47 Version, 31 Version,
48 Help, 32 Help,
49} 33}
50 34
35const HELP: &str = "\
36rust-analyzer
37
38USAGE:
39 rust-analyzer [FLAGS] [COMMAND] [COMMAND_OPTIONS]
40
41FLAGS:
42 --version Print version
43 -h, --help Print this help
44
45 -v, --verbose
46 -vv, --spammy
47 -q, --quiet Set verbosity
48
49 --log-file <PATH> Log to the specified filed instead of stderr
50
51ENVIRONMENTAL VARIABLES:
52 RA_LOG Set log filter in env_logger format
53 RA_PROFILE Enable hierarchical profiler
54
55COMMANDS:
56
57not specified Launch LSP server
58
59parse < main.rs Parse tree
60 --no-dump Suppress printing
61
62symbols < main.rs Parse input an print the list of symbols
63
64highlight < main.rs Highlight input as html
65 --rainbow Enable rainbow highlighting of identifiers
66
67analysis-stats <PATH> Batch typecheck project and print summary statistics
68 <PATH> Directory with Cargo.toml
69 --randomize Randomize order in which crates, modules, and items are processed
70 --parallel Run type inference in parallel
71 --memory-usage Collect memory usage statistics
72 -o, --only <PATH> Only analyze items matching this path
73 --with-deps Also analyze all dependencies
74 --load-output-dirs
75 Load OUT_DIR values by running `cargo check` before analysis
76 --with-proc-macro Use proc-macro-srv for proc-macro expanding
77
78analysis-bench <PATH> Benchmark specific analysis operation
79 <PATH> Directory with Cargo.toml
80 --highlight <PATH>
81 Compute syntax highlighting for this file
82 --complete <PATH:LINE:COLUMN>
83 Compute completions at this location
84 --goto-def <PATH:LINE:COLUMN>
85 Compute goto definition at this location
86 --memory-usage Collect memory usage statistics
87 --load-output-dirs
88 Load OUT_DIR values by running `cargo check` before analysis
89 --with-proc-macro Use proc-macro-srv for proc-macro expanding
90
91diagnostics <PATH>
92 <PATH> Directory with Cargo.toml
93 --load-output-dirs
94 Load OUT_DIR values by running `cargo check` before analysis
95 --with-proc-macro Use proc-macro-srv for proc-macro expanding
96
97ssr [RULE...]
98 <RULE> A structured search replace rule (`$a.foo($b) ==> bar($a, $b)`)
99 --debug <snippet> Prints debug information for any nodes with source exactly
100 equal to <snippet>
101
102search [PATTERN..]
103 <PATTERN> A structured search replace pattern (`$a.foo($b)`)
104 --debug <snippet> Prints debug information for any nodes with source exactly
105 equal to <snippet>
106";
107
51impl Args { 108impl Args {
52 pub(crate) fn parse() -> Result<Args> { 109 pub(crate) fn parse() -> Result<Args> {
53 let mut matches = Arguments::from_env(); 110 let mut matches = Arguments::from_env();
@@ -75,108 +132,34 @@ impl Args {
75 }; 132 };
76 let log_file = matches.opt_value_from_str("--log-file")?; 133 let log_file = matches.opt_value_from_str("--log-file")?;
77 134
78 let help = Ok(Args { verbosity, log_file: None, command: Command::Help }); 135 if matches.contains(["-h", "--help"]) {
136 eprintln!("{}", HELP);
137 return Ok(Args { verbosity, log_file: None, command: Command::Help });
138 }
139
79 let subcommand = match matches.subcommand()? { 140 let subcommand = match matches.subcommand()? {
80 Some(it) => it, 141 Some(it) => it,
81 None => { 142 None => {
82 if matches.contains(["-h", "--help"]) {
83 print_subcommands();
84 return help;
85 }
86 matches.finish().or_else(handle_extra_flags)?; 143 matches.finish().or_else(handle_extra_flags)?;
87 return Ok(Args { verbosity, log_file, command: Command::RunServer }); 144 return Ok(Args { verbosity, log_file, command: Command::RunServer });
88 } 145 }
89 }; 146 };
90 let command = match subcommand.as_str() { 147 let command = match subcommand.as_str() {
91 "parse" => { 148 "parse" => {
92 if matches.contains(["-h", "--help"]) {
93 eprintln!(
94 "\
95rust-analyzer parse
96
97USAGE:
98 rust-analyzer parse [FLAGS]
99
100FLAGS:
101 -h, --help Prints help information
102 --no-dump"
103 );
104 return help;
105 }
106
107 let no_dump = matches.contains("--no-dump"); 149 let no_dump = matches.contains("--no-dump");
108 matches.finish().or_else(handle_extra_flags)?; 150 matches.finish().or_else(handle_extra_flags)?;
109 Command::Parse { no_dump } 151 Command::Parse { no_dump }
110 } 152 }
111 "symbols" => { 153 "symbols" => {
112 if matches.contains(["-h", "--help"]) {
113 eprintln!(
114 "\
115rust-analyzer symbols
116
117USAGE:
118 rust-analyzer highlight [FLAGS]
119
120FLAGS:
121 -h, --help Prints help inforamtion"
122 );
123 return help;
124 }
125
126 matches.finish().or_else(handle_extra_flags)?; 154 matches.finish().or_else(handle_extra_flags)?;
127
128 Command::Symbols 155 Command::Symbols
129 } 156 }
130 "highlight" => { 157 "highlight" => {
131 if matches.contains(["-h", "--help"]) { 158 let rainbow = matches.contains("--rainbow");
132 eprintln!(
133 "\
134rust-analyzer highlight
135
136USAGE:
137 rust-analyzer highlight [FLAGS]
138
139FLAGS:
140 -h, --help Prints help information
141 -r, --rainbow"
142 );
143 return help;
144 }
145
146 let rainbow = matches.contains(["-r", "--rainbow"]);
147 matches.finish().or_else(handle_extra_flags)?; 159 matches.finish().or_else(handle_extra_flags)?;
148 Command::Highlight { rainbow } 160 Command::Highlight { rainbow }
149 } 161 }
150 "analysis-stats" => { 162 "analysis-stats" => {
151 if matches.contains(["-h", "--help"]) {
152 eprintln!(
153 "\
154rust-analyzer analysis-stats
155
156USAGE:
157 rust-analyzer analysis-stats [FLAGS] [OPTIONS] [PATH]
158
159FLAGS:
160 -o, --only Only analyze items matching this path
161 -h, --help Prints help information
162 --memory-usage Collect memory usage statistics
163 --randomize Randomize order in which crates, modules, and items are processed
164 --parallel Run type inference in parallel
165 --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
166 --with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
167 --with-deps Also analyze all dependencies
168 -v, --verbose
169 -q, --quiet
170
171OPTIONS:
172 -o <ONLY>
173
174ARGS:
175 <PATH>"
176 );
177 return help;
178 }
179
180 let randomize = matches.contains("--randomize"); 163 let randomize = matches.contains("--randomize");
181 let parallel = matches.contains("--parallel"); 164 let parallel = matches.contains("--parallel");
182 let memory_usage = matches.contains("--memory-usage"); 165 let memory_usage = matches.contains("--memory-usage");
@@ -204,34 +187,6 @@ ARGS:
204 }) 187 })
205 } 188 }
206 "analysis-bench" => { 189 "analysis-bench" => {
207 if matches.contains(["-h", "--help"]) {
208 eprintln!(
209 "\
210rust-analyzer analysis-bench
211
212USAGE:
213 rust-analyzer analysis-bench [FLAGS] [OPTIONS]
214
215FLAGS:
216 -h, --help Prints help information
217 --memory-usage Collect memory usage statistics
218 --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
219 --with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
220 -v, --verbose
221
222OPTIONS:
223 --project <PATH> Path to directory with Cargo.toml
224 --complete <PATH:LINE:COLUMN> Compute completions at this location
225 --goto-def <PATH:LINE:COLUMN> Compute goto definition at this location
226 --highlight <PATH> Hightlight this file
227
228ARGS:
229 <PATH> Project to analyse"
230 );
231 return help;
232 }
233
234 let path: PathBuf = matches.opt_value_from_str("--project")?.unwrap_or_default();
235 let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?; 190 let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?;
236 let complete_path: Option<Position> = matches.opt_value_from_str("--complete")?; 191 let complete_path: Option<Position> = matches.opt_value_from_str("--complete")?;
237 let goto_def_path: Option<Position> = matches.opt_value_from_str("--goto-def")?; 192 let goto_def_path: Option<Position> = matches.opt_value_from_str("--goto-def")?;
@@ -249,6 +204,15 @@ ARGS:
249 let memory_usage = matches.contains("--memory-usage"); 204 let memory_usage = matches.contains("--memory-usage");
250 let load_output_dirs = matches.contains("--load-output-dirs"); 205 let load_output_dirs = matches.contains("--load-output-dirs");
251 let with_proc_macro = matches.contains("--with-proc-macro"); 206 let with_proc_macro = matches.contains("--with-proc-macro");
207
208 let path = {
209 let mut trailing = matches.free()?;
210 if trailing.len() != 1 {
211 bail!("Invalid flags");
212 }
213 trailing.pop().unwrap().into()
214 };
215
252 Command::Bench(BenchCmd { 216 Command::Bench(BenchCmd {
253 memory_usage, 217 memory_usage,
254 path, 218 path,
@@ -258,28 +222,8 @@ ARGS:
258 }) 222 })
259 } 223 }
260 "diagnostics" => { 224 "diagnostics" => {
261 if matches.contains(["-h", "--help"]) {
262 eprintln!(
263 "\
264rust-analyzer diagnostics
265
266USAGE:
267 rust-analyzer diagnostics [FLAGS] [PATH]
268
269FLAGS:
270 -h, --help Prints help information
271 --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
272 --all Include all files rather than only modules
273
274ARGS:
275 <PATH>"
276 );
277 return help;
278 }
279
280 let load_output_dirs = matches.contains("--load-output-dirs"); 225 let load_output_dirs = matches.contains("--load-output-dirs");
281 let with_proc_macro = matches.contains("--with-proc-macro"); 226 let with_proc_macro = matches.contains("--with-proc-macro");
282 let all = matches.contains("--all");
283 let path = { 227 let path = {
284 let mut trailing = matches.free()?; 228 let mut trailing = matches.free()?;
285 if trailing.len() != 1 { 229 if trailing.len() != 1 {
@@ -288,30 +232,10 @@ ARGS:
288 trailing.pop().unwrap().into() 232 trailing.pop().unwrap().into()
289 }; 233 };
290 234
291 Command::Diagnostics { path, load_output_dirs, with_proc_macro, all } 235 Command::Diagnostics { path, load_output_dirs, with_proc_macro }
292 } 236 }
293 "proc-macro" => Command::ProcMacro, 237 "proc-macro" => Command::ProcMacro,
294 "ssr" => { 238 "ssr" => {
295 if matches.contains(["-h", "--help"]) {
296 eprintln!(
297 "\
298rust-analyzer ssr
299
300USAGE:
301 rust-analyzer ssr [FLAGS] [RULE...]
302
303EXAMPLE:
304 rust-analyzer ssr '$a.foo($b) ==> bar($a, $b)'
305
306FLAGS:
307 --debug <snippet> Prints debug information for any nodes with source exactly equal to <snippet>
308 -h, --help Prints help information
309
310ARGS:
311 <RULE> A structured search replace rule"
312 );
313 return help;
314 }
315 let mut rules = Vec::new(); 239 let mut rules = Vec::new();
316 while let Some(rule) = matches.free_from_str()? { 240 while let Some(rule) = matches.free_from_str()? {
317 rules.push(rule); 241 rules.push(rule);
@@ -319,26 +243,6 @@ ARGS:
319 Command::Ssr { rules } 243 Command::Ssr { rules }
320 } 244 }
321 "search" => { 245 "search" => {
322 if matches.contains(["-h", "--help"]) {
323 eprintln!(
324 "\
325rust-analyzer search
326
327USAGE:
328 rust-analyzer search [FLAGS] [PATTERN...]
329
330EXAMPLE:
331 rust-analyzer search '$a.foo($b)'
332
333FLAGS:
334 --debug <snippet> Prints debug information for any nodes with source exactly equal to <snippet>
335 -h, --help Prints help information
336
337ARGS:
338 <PATTERN> A structured search pattern"
339 );
340 return help;
341 }
342 let debug_snippet = matches.opt_value_from_str("--debug")?; 246 let debug_snippet = matches.opt_value_from_str("--debug")?;
343 let mut patterns = Vec::new(); 247 let mut patterns = Vec::new();
344 while let Some(rule) = matches.free_from_str()? { 248 while let Some(rule) = matches.free_from_str()? {
@@ -347,38 +251,14 @@ ARGS:
347 Command::StructuredSearch { patterns, debug_snippet } 251 Command::StructuredSearch { patterns, debug_snippet }
348 } 252 }
349 _ => { 253 _ => {
350 print_subcommands(); 254 eprintln!("{}", HELP);
351 return help; 255 return Ok(Args { verbosity, log_file: None, command: Command::Help });
352 } 256 }
353 }; 257 };
354 Ok(Args { verbosity, log_file, command }) 258 Ok(Args { verbosity, log_file, command })
355 } 259 }
356} 260}
357 261
358fn print_subcommands() {
359 eprintln!(
360 "\
361rust-analyzer
362
363USAGE:
364 rust-analyzer <SUBCOMMAND>
365
366FLAGS:
367 -h, --help Prints help information
368
369SUBCOMMANDS:
370 analysis-bench
371 analysis-stats
372 highlight
373 diagnostics
374 proc-macro
375 parse
376 search
377 ssr
378 symbols"
379 )
380}
381
382fn handle_extra_flags(e: pico_args::Error) -> Result<()> { 262fn handle_extra_flags(e: pico_args::Error) -> Result<()> {
383 if let pico_args::Error::UnusedArgsLeft(flags) = e { 263 if let pico_args::Error::UnusedArgsLeft(flags) = e {
384 let mut invalid_flags = String::new(); 264 let mut invalid_flags = String::new();
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs
index 266768970..ba4402ade 100644
--- a/crates/rust-analyzer/src/bin/main.rs
+++ b/crates/rust-analyzer/src/bin/main.rs
@@ -38,8 +38,8 @@ fn try_main() -> Result<()> {
38 args::Command::Highlight { rainbow } => cli::highlight(rainbow)?, 38 args::Command::Highlight { rainbow } => cli::highlight(rainbow)?,
39 args::Command::AnalysisStats(cmd) => cmd.run(args.verbosity)?, 39 args::Command::AnalysisStats(cmd) => cmd.run(args.verbosity)?,
40 args::Command::Bench(cmd) => cmd.run(args.verbosity)?, 40 args::Command::Bench(cmd) => cmd.run(args.verbosity)?,
41 args::Command::Diagnostics { path, load_output_dirs, with_proc_macro, all } => { 41 args::Command::Diagnostics { path, load_output_dirs, with_proc_macro } => {
42 cli::diagnostics(path.as_ref(), load_output_dirs, with_proc_macro, all)? 42 cli::diagnostics(path.as_ref(), load_output_dirs, with_proc_macro)?
43 } 43 }
44 args::Command::Ssr { rules } => { 44 args::Command::Ssr { rules } => {
45 cli::apply_ssr_rules(rules)?; 45 cli::apply_ssr_rules(rules)?;
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs
index c424aa6e2..f3b6c900e 100644
--- a/crates/rust-analyzer/src/cli/diagnostics.rs
+++ b/crates/rust-analyzer/src/cli/diagnostics.rs
@@ -12,12 +12,7 @@ use ide::{DiagnosticsConfig, Severity};
12 12
13use crate::cli::{load_cargo::load_cargo, Result}; 13use crate::cli::{load_cargo::load_cargo, Result};
14 14
15pub fn diagnostics( 15pub fn diagnostics(path: &Path, load_output_dirs: bool, with_proc_macro: bool) -> Result<()> {
16 path: &Path,
17 load_output_dirs: bool,
18 with_proc_macro: bool,
19 _all: bool,
20) -> Result<()> {
21 let (host, _vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?; 16 let (host, _vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?;
22 let db = host.raw_database(); 17 let db = host.raw_database();
23 let analysis = host.analysis(); 18 let analysis = host.analysis();