rust_analyzer/cli/
flags.rs1#![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-lowering
83 optional --skip-inference
85 optional --skip-mir-stats
87 optional --skip-data-layout
89 optional --skip-const-eval
91 optional --run-all-ide-things
95 optional --run-term-search
97 optional --validate-term-search
100 }
101
102 cmd run-tests {
104 required path: PathBuf
106 }
107
108 cmd rustc-tests {
110 required rustc_repo: PathBuf
112
113 optional --filter path: String
115 }
116
117 cmd diagnostics {
118 required path: PathBuf
120
121 optional --disable-build-scripts
123 optional --disable-proc-macros
125 optional --proc-macro-srv path: PathBuf
127 }
128
129 cmd unresolved-references {
131 required path: PathBuf
133
134 optional --disable-build-scripts
136 optional --disable-proc-macros
138 optional --proc-macro-srv path: PathBuf
140 }
141
142 cmd prime-caches {
144 required path: PathBuf
146
147 optional --disable-build-scripts
149 optional --disable-proc-macros
151 optional --proc-macro-srv path: PathBuf
153 optional --num-threads num_threads: usize
155 }
156
157 cmd ssr {
158 repeated rule: SsrRule
160 }
161
162 cmd search {
163 repeated pattern: SsrPattern
165 optional --debug snippet: String
167 }
168
169 cmd lsif {
170 required path: PathBuf
171
172 optional --exclude-vendored-libraries
174 }
175
176 cmd scip {
177 required path: PathBuf
178
179 optional --output path: PathBuf
181
182 optional --config-path config_path: PathBuf
184
185 optional --exclude-vendored-libraries
187 }
188 }
189}
190
191#[derive(Debug)]
195pub struct RustAnalyzer {
196 pub verbose: u32,
197 pub quiet: bool,
198 pub log_file: Option<PathBuf>,
199 pub no_log_buffering: bool,
200 pub wait_dbg: bool,
201 pub subcommand: RustAnalyzerCmd,
202}
203
204#[derive(Debug)]
205pub enum RustAnalyzerCmd {
206 LspServer(LspServer),
207 Parse(Parse),
208 Symbols(Symbols),
209 Highlight(Highlight),
210 AnalysisStats(AnalysisStats),
211 RunTests(RunTests),
212 RustcTests(RustcTests),
213 Diagnostics(Diagnostics),
214 UnresolvedReferences(UnresolvedReferences),
215 PrimeCaches(PrimeCaches),
216 Ssr(Ssr),
217 Search(Search),
218 Lsif(Lsif),
219 Scip(Scip),
220}
221
222#[derive(Debug)]
223pub struct LspServer {
224 pub version: bool,
225 pub print_config_schema: bool,
226}
227
228#[derive(Debug)]
229pub struct Parse {
230 pub no_dump: bool,
231}
232
233#[derive(Debug)]
234pub struct Symbols;
235
236#[derive(Debug)]
237pub struct Highlight {
238 pub rainbow: bool,
239}
240
241#[derive(Debug)]
242pub struct AnalysisStats {
243 pub path: PathBuf,
244
245 pub output: Option<OutputFormat>,
246 pub randomize: bool,
247 pub parallel: bool,
248 pub only: Option<String>,
249 pub with_deps: bool,
250 pub no_sysroot: bool,
251 pub no_test: bool,
252 pub disable_build_scripts: bool,
253 pub disable_proc_macros: bool,
254 pub proc_macro_srv: Option<PathBuf>,
255 pub skip_lowering: bool,
256 pub skip_inference: bool,
257 pub skip_mir_stats: bool,
258 pub skip_data_layout: bool,
259 pub skip_const_eval: bool,
260 pub run_all_ide_things: bool,
261 pub run_term_search: bool,
262 pub validate_term_search: bool,
263}
264
265#[derive(Debug)]
266pub struct RunTests {
267 pub path: PathBuf,
268}
269
270#[derive(Debug)]
271pub struct RustcTests {
272 pub rustc_repo: PathBuf,
273
274 pub filter: Option<String>,
275}
276
277#[derive(Debug)]
278pub struct Diagnostics {
279 pub path: PathBuf,
280
281 pub disable_build_scripts: bool,
282 pub disable_proc_macros: bool,
283 pub proc_macro_srv: Option<PathBuf>,
284}
285
286#[derive(Debug)]
287pub struct UnresolvedReferences {
288 pub path: PathBuf,
289
290 pub disable_build_scripts: bool,
291 pub disable_proc_macros: bool,
292 pub proc_macro_srv: Option<PathBuf>,
293}
294
295#[derive(Debug)]
296pub struct PrimeCaches {
297 pub path: PathBuf,
298
299 pub disable_build_scripts: bool,
300 pub disable_proc_macros: bool,
301 pub proc_macro_srv: Option<PathBuf>,
302 pub num_threads: Option<usize>,
303}
304
305#[derive(Debug)]
306pub struct Ssr {
307 pub rule: Vec<SsrRule>,
308}
309
310#[derive(Debug)]
311pub struct Search {
312 pub pattern: Vec<SsrPattern>,
313
314 pub debug: Option<String>,
315}
316
317#[derive(Debug)]
318pub struct Lsif {
319 pub path: PathBuf,
320
321 pub exclude_vendored_libraries: bool,
322}
323
324#[derive(Debug)]
325pub struct Scip {
326 pub path: PathBuf,
327
328 pub output: Option<PathBuf>,
329 pub config_path: Option<PathBuf>,
330 pub exclude_vendored_libraries: bool,
331}
332
333impl RustAnalyzer {
334 #[allow(dead_code)]
335 pub fn from_env_or_exit() -> Self {
336 Self::from_env_or_exit_()
337 }
338
339 #[allow(dead_code)]
340 pub fn from_env() -> xflags::Result<Self> {
341 Self::from_env_()
342 }
343
344 #[allow(dead_code)]
345 pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
346 Self::from_vec_(args)
347 }
348}
349#[derive(Debug, PartialEq, Eq)]
352pub enum OutputFormat {
353 Csv,
354}
355
356impl RustAnalyzer {
357 pub fn verbosity(&self) -> Verbosity {
358 if self.quiet {
359 return Verbosity::Quiet;
360 }
361 match self.verbose {
362 0 => Verbosity::Normal,
363 1 => Verbosity::Verbose,
364 _ => Verbosity::Spammy,
365 }
366 }
367}
368
369impl FromStr for OutputFormat {
370 type Err = String;
371
372 fn from_str(s: &str) -> Result<Self, Self::Err> {
373 match s {
374 "csv" => Ok(Self::Csv),
375 _ => Err(format!("unknown output format `{s}`")),
376 }
377 }
378}