1#![allow(unreachable_pub)]
3use std::{path::PathBuf, str::FromStr};
4
5use ide_ssr::{SsrPattern, SsrRule};
6
7use crate::cli::Verbosity;
8
9xflags::xflags! {
10 src "./src/cli/flags.rs"
11
12 cmd rust-analyzer {
18 repeated -v, --verbose
20 optional -q, --quiet
22
23 optional --log-file path: PathBuf
25 optional --no-log-buffering
27
28 optional --wait-dbg
30
31 default cmd lsp-server {
32 optional -V, --version
34
35 optional --print-config-schema
37 }
38
39 cmd parse {
41 optional --no-dump
43 }
44
45 cmd symbols {}
47
48 cmd highlight {
50 optional --rainbow
52 }
53
54 cmd analysis-stats {
56 required path: PathBuf
58
59 optional --output format: OutputFormat
60
61 optional --randomize
63 optional --parallel
65
66 optional -o, --only path: String
68 optional --with-deps
70 optional --no-sysroot
72 optional --no-test
74
75 optional --disable-build-scripts
77 optional --disable-proc-macros
79 optional --proc-macro-srv path: PathBuf
81 optional --skip-lang-items
83 optional --skip-lowering
85 optional --skip-inference
87 optional --skip-mir-stats
89 optional --skip-data-layout
91 optional --skip-const-eval
93 optional --run-all-ide-things
97 optional --run-term-search
99 optional --validate-term-search
102 }
103
104 cmd run-tests {
106 required path: PathBuf
108 }
109
110 cmd rustc-tests {
112 required rustc_repo: PathBuf
114
115 optional --filter path: String
117 }
118
119 cmd diagnostics {
120 required path: PathBuf
122
123 optional --disable-build-scripts
125 optional --disable-proc-macros
127 optional --proc-macro-srv path: PathBuf
129
130 optional --severity severity: Severity
132 }
133
134 cmd unresolved-references {
136 required path: PathBuf
138
139 optional --disable-build-scripts
141 optional --disable-proc-macros
143 optional --proc-macro-srv path: PathBuf
145 }
146
147 cmd prime-caches {
149 required path: PathBuf
151
152 optional --disable-build-scripts
154 optional --disable-proc-macros
156 optional --proc-macro-srv path: PathBuf
158 optional --num-threads num_threads: usize
160 }
161
162 cmd ssr {
163 repeated rule: SsrRule
165 }
166
167 cmd search {
168 repeated pattern: SsrPattern
170 optional --debug snippet: String
172 }
173
174 cmd lsif {
175 required path: PathBuf
176
177 optional --exclude-vendored-libraries
179 }
180
181 cmd scip {
182 required path: PathBuf
183
184 optional --output path: PathBuf
186
187 optional --config-path config_path: PathBuf
189
190 optional --exclude-vendored-libraries
192 }
193 }
194}
195
196#[derive(Debug)]
200pub struct RustAnalyzer {
201 pub verbose: u32,
202 pub quiet: bool,
203 pub log_file: Option<PathBuf>,
204 pub no_log_buffering: bool,
205 pub wait_dbg: bool,
206 pub subcommand: RustAnalyzerCmd,
207}
208
209#[derive(Debug)]
210pub enum RustAnalyzerCmd {
211 LspServer(LspServer),
212 Parse(Parse),
213 Symbols(Symbols),
214 Highlight(Highlight),
215 AnalysisStats(AnalysisStats),
216 RunTests(RunTests),
217 RustcTests(RustcTests),
218 Diagnostics(Diagnostics),
219 UnresolvedReferences(UnresolvedReferences),
220 PrimeCaches(PrimeCaches),
221 Ssr(Ssr),
222 Search(Search),
223 Lsif(Lsif),
224 Scip(Scip),
225}
226
227#[derive(Debug)]
228pub struct LspServer {
229 pub version: bool,
230 pub print_config_schema: bool,
231}
232
233#[derive(Debug)]
234pub struct Parse {
235 pub no_dump: bool,
236}
237
238#[derive(Debug)]
239pub struct Symbols;
240
241#[derive(Debug)]
242pub struct Highlight {
243 pub rainbow: bool,
244}
245
246#[derive(Debug)]
247pub struct AnalysisStats {
248 pub path: PathBuf,
249
250 pub output: Option<OutputFormat>,
251 pub randomize: bool,
252 pub parallel: bool,
253 pub only: Option<String>,
254 pub with_deps: bool,
255 pub no_sysroot: bool,
256 pub no_test: bool,
257 pub disable_build_scripts: bool,
258 pub disable_proc_macros: bool,
259 pub proc_macro_srv: Option<PathBuf>,
260 pub skip_lowering: bool,
261 pub skip_lang_items: bool,
262 pub skip_inference: bool,
263 pub skip_mir_stats: bool,
264 pub skip_data_layout: bool,
265 pub skip_const_eval: bool,
266 pub run_all_ide_things: bool,
267 pub run_term_search: bool,
268 pub validate_term_search: bool,
269}
270
271#[derive(Debug)]
272pub struct RunTests {
273 pub path: PathBuf,
274}
275
276#[derive(Debug)]
277pub struct RustcTests {
278 pub rustc_repo: PathBuf,
279
280 pub filter: Option<String>,
281}
282
283#[derive(Debug)]
284pub struct Diagnostics {
285 pub path: PathBuf,
286
287 pub disable_build_scripts: bool,
288 pub disable_proc_macros: bool,
289 pub proc_macro_srv: Option<PathBuf>,
290 pub severity: Option<Severity>,
291}
292
293#[derive(Debug)]
294pub struct UnresolvedReferences {
295 pub path: PathBuf,
296
297 pub disable_build_scripts: bool,
298 pub disable_proc_macros: bool,
299 pub proc_macro_srv: Option<PathBuf>,
300}
301
302#[derive(Debug)]
303pub struct PrimeCaches {
304 pub path: PathBuf,
305
306 pub disable_build_scripts: bool,
307 pub disable_proc_macros: bool,
308 pub proc_macro_srv: Option<PathBuf>,
309 pub num_threads: Option<usize>,
310}
311
312#[derive(Debug)]
313pub struct Ssr {
314 pub rule: Vec<SsrRule>,
315}
316
317#[derive(Debug)]
318pub struct Search {
319 pub pattern: Vec<SsrPattern>,
320
321 pub debug: Option<String>,
322}
323
324#[derive(Debug)]
325pub struct Lsif {
326 pub path: PathBuf,
327
328 pub exclude_vendored_libraries: bool,
329}
330
331#[derive(Debug)]
332pub struct Scip {
333 pub path: PathBuf,
334
335 pub output: Option<PathBuf>,
336 pub config_path: Option<PathBuf>,
337 pub exclude_vendored_libraries: bool,
338}
339
340impl RustAnalyzer {
341 #[allow(dead_code)]
342 pub fn from_env_or_exit() -> Self {
343 Self::from_env_or_exit_()
344 }
345
346 #[allow(dead_code)]
347 pub fn from_env() -> xflags::Result<Self> {
348 Self::from_env_()
349 }
350
351 #[allow(dead_code)]
352 pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
353 Self::from_vec_(args)
354 }
355}
356#[derive(Debug, PartialEq, Eq)]
359pub enum OutputFormat {
360 Csv,
361}
362
363impl RustAnalyzer {
364 pub fn verbosity(&self) -> Verbosity {
365 if self.quiet {
366 return Verbosity::Quiet;
367 }
368 match self.verbose {
369 0 => Verbosity::Normal,
370 1 => Verbosity::Verbose,
371 _ => Verbosity::Spammy,
372 }
373 }
374}
375
376impl FromStr for OutputFormat {
377 type Err = String;
378
379 fn from_str(s: &str) -> Result<Self, Self::Err> {
380 match s {
381 "csv" => Ok(Self::Csv),
382 _ => Err(format!("unknown output format `{s}`")),
383 }
384 }
385}
386
387#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
388pub enum Severity {
389 Weak,
390 Warning,
391 Error,
392}
393
394impl FromStr for Severity {
395 type Err = String;
396
397 fn from_str(s: &str) -> Result<Self, Self::Err> {
398 match &*s.to_ascii_lowercase() {
399 "weak" => Ok(Self::Weak),
400 "warning" => Ok(Self::Warning),
401 "error" => Ok(Self::Error),
402 _ => Err(format!("unknown severity `{s}`")),
403 }
404 }
405}