aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/bin/args.rs175
1 files changed, 69 insertions, 106 deletions
diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs
index b724ae454..41ce5cae9 100644
--- a/crates/rust-analyzer/src/bin/args.rs
+++ b/crates/rust-analyzer/src/bin/args.rs
@@ -5,7 +5,7 @@
5 5
6use std::{env, fmt::Write, path::PathBuf}; 6use std::{env, fmt::Write, path::PathBuf};
7 7
8use anyhow::{bail, Result}; 8use anyhow::{bail, format_err, Result};
9use pico_args::Arguments; 9use pico_args::Arguments;
10use rust_analyzer::cli::{AnalysisStatsCmd, BenchCmd, BenchWhat, Position, Verbosity}; 10use rust_analyzer::cli::{AnalysisStatsCmd, BenchCmd, BenchWhat, Position, Verbosity};
11use ssr::{SsrPattern, SsrRule}; 11use ssr::{SsrPattern, SsrRule};
@@ -96,8 +96,6 @@ diagnostics <PATH>
96 96
97ssr [RULE...] 97ssr [RULE...]
98 <RULE> A structured search replace rule (`$a.foo($b) ==> bar($a, $b)`) 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 99
102search [PATTERN..] 100search [PATTERN..]
103 <PATTERN> A structured search replace pattern (`$a.foo($b)`) 101 <PATTERN> A structured search replace pattern (`$a.foo($b)`)
@@ -145,116 +143,81 @@ impl Args {
145 } 143 }
146 }; 144 };
147 let command = match subcommand.as_str() { 145 let command = match subcommand.as_str() {
148 "parse" => { 146 "parse" => Command::Parse { no_dump: matches.contains("--no-dump") },
149 let no_dump = matches.contains("--no-dump"); 147 "symbols" => Command::Symbols,
150 matches.finish().or_else(handle_extra_flags)?; 148 "highlight" => Command::Highlight { rainbow: matches.contains("--rainbow") },
151 Command::Parse { no_dump } 149 "analysis-stats" => Command::AnalysisStats(AnalysisStatsCmd {
152 } 150 randomize: matches.contains("--randomize"),
153 "symbols" => { 151 parallel: matches.contains("--parallel"),
154 matches.finish().or_else(handle_extra_flags)?; 152 memory_usage: matches.contains("--memory-usage"),
155 Command::Symbols 153 only: matches.opt_value_from_str(["-o", "--only"])?,
156 } 154 with_deps: matches.contains("--with-deps"),
157 "highlight" => { 155 load_output_dirs: matches.contains("--load-output-dirs"),
158 let rainbow = matches.contains("--rainbow"); 156 with_proc_macro: matches.contains("--with-proc-macro"),
159 matches.finish().or_else(handle_extra_flags)?; 157 path: matches
160 Command::Highlight { rainbow } 158 .free_from_str()?
161 } 159 .ok_or_else(|| format_err!("expected positional argument"))?,
162 "analysis-stats" => { 160 }),
163 let randomize = matches.contains("--randomize"); 161 "analysis-bench" => Command::Bench(BenchCmd {
164 let parallel = matches.contains("--parallel"); 162 what: {
165 let memory_usage = matches.contains("--memory-usage"); 163 let highlight_path: Option<String> =
166 let only: Option<String> = matches.opt_value_from_str(["-o", "--only"])?; 164 matches.opt_value_from_str("--highlight")?;
167 let with_deps: bool = matches.contains("--with-deps"); 165 let complete_path: Option<Position> =
168 let load_output_dirs = matches.contains("--load-output-dirs"); 166 matches.opt_value_from_str("--complete")?;
169 let with_proc_macro = matches.contains("--with-proc-macro"); 167 let goto_def_path: Option<Position> =
170 let path = { 168 matches.opt_value_from_str("--goto-def")?;
171 let mut trailing = matches.free()?; 169 match (highlight_path, complete_path, goto_def_path) {
172 if trailing.len() != 1 { 170 (Some(path), None, None) => {
173 bail!("Invalid flags"); 171 let path = env::current_dir().unwrap().join(path);
174 } 172 BenchWhat::Highlight { path: AbsPathBuf::assert(path) }
175 trailing.pop().unwrap().into() 173 }
176 }; 174 (None, Some(position), None) => BenchWhat::Complete(position),
177 175 (None, None, Some(position)) => BenchWhat::GotoDef(position),
178 Command::AnalysisStats(AnalysisStatsCmd { 176 _ => panic!(
179 randomize, 177 "exactly one of `--highlight`, `--complete` or `--goto-def` must be set"
180 parallel, 178 ),
181 memory_usage, 179 }
182 only, 180 },
183 with_deps, 181 memory_usage: matches.contains("--memory-usage"),
184 path, 182 load_output_dirs: matches.contains("--load-output-dirs"),
185 load_output_dirs, 183 with_proc_macro: matches.contains("--with-proc-macro"),
186 with_proc_macro, 184 path: matches
187 }) 185 .free_from_str()?
188 } 186 .ok_or_else(|| format_err!("expected positional argument"))?,
189 "analysis-bench" => { 187 }),
190 let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?; 188 "diagnostics" => Command::Diagnostics {
191 let complete_path: Option<Position> = matches.opt_value_from_str("--complete")?; 189 load_output_dirs: matches.contains("--load-output-dirs"),
192 let goto_def_path: Option<Position> = matches.opt_value_from_str("--goto-def")?; 190 with_proc_macro: matches.contains("--with-proc-macro"),
193 let what = match (highlight_path, complete_path, goto_def_path) { 191 path: matches
194 (Some(path), None, None) => { 192 .free_from_str()?
195 let path = env::current_dir().unwrap().join(path); 193 .ok_or_else(|| format_err!("expected positional argument"))?,
196 BenchWhat::Highlight { path: AbsPathBuf::assert(path) } 194 },
197 } 195 "proc-macro" => Command::ProcMacro,
198 (None, Some(position), None) => BenchWhat::Complete(position), 196 "ssr" => Command::Ssr {
199 (None, None, Some(position)) => BenchWhat::GotoDef(position), 197 rules: {
200 _ => panic!( 198 let mut acc = Vec::new();
201 "exactly one of `--highlight`, `--complete` or `--goto-def` must be set" 199 while let Some(rule) = matches.free_from_str()? {
202 ), 200 acc.push(rule);
203 };
204 let memory_usage = matches.contains("--memory-usage");
205 let load_output_dirs = matches.contains("--load-output-dirs");
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 } 201 }
213 trailing.pop().unwrap().into() 202 acc
214 }; 203 },
215 204 },
216 Command::Bench(BenchCmd { 205 "search" => Command::StructuredSearch {
217 memory_usage, 206 debug_snippet: matches.opt_value_from_str("--debug")?,
218 path, 207 patterns: {
219 what, 208 let mut acc = Vec::new();
220 load_output_dirs, 209 while let Some(rule) = matches.free_from_str()? {
221 with_proc_macro, 210 acc.push(rule);
222 })
223 }
224 "diagnostics" => {
225 let load_output_dirs = matches.contains("--load-output-dirs");
226 let with_proc_macro = matches.contains("--with-proc-macro");
227 let path = {
228 let mut trailing = matches.free()?;
229 if trailing.len() != 1 {
230 bail!("Invalid flags");
231 } 211 }
232 trailing.pop().unwrap().into() 212 acc
233 }; 213 },
234 214 },
235 Command::Diagnostics { path, load_output_dirs, with_proc_macro }
236 }
237 "proc-macro" => Command::ProcMacro,
238 "ssr" => {
239 let mut rules = Vec::new();
240 while let Some(rule) = matches.free_from_str()? {
241 rules.push(rule);
242 }
243 Command::Ssr { rules }
244 }
245 "search" => {
246 let debug_snippet = matches.opt_value_from_str("--debug")?;
247 let mut patterns = Vec::new();
248 while let Some(rule) = matches.free_from_str()? {
249 patterns.push(rule);
250 }
251 Command::StructuredSearch { patterns, debug_snippet }
252 }
253 _ => { 215 _ => {
254 eprintln!("{}", HELP); 216 eprintln!("{}", HELP);
255 return Ok(Args { verbosity, log_file: None, command: Command::Help }); 217 return Ok(Args { verbosity, log_file: None, command: Command::Help });
256 } 218 }
257 }; 219 };
220 matches.finish().or_else(handle_extra_flags)?;
258 Ok(Args { verbosity, log_file, command }) 221 Ok(Args { verbosity, log_file, command })
259 } 222 }
260} 223}