ra_ap_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 optional --source-stats
67
68 optional -o, --only path: String
70 optional --with-deps
72 optional --no-sysroot
74 optional --no-test
76
77 optional --disable-build-scripts
79 optional --disable-proc-macros
81 optional --proc-macro-srv path: PathBuf
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
131 cmd unresolved-references {
133 required path: PathBuf
135
136 optional --disable-build-scripts
138 optional --disable-proc-macros
140 optional --proc-macro-srv path: PathBuf
142 }
143
144 cmd ssr {
145 repeated rule: SsrRule
147 }
148
149 cmd search {
150 repeated pattern: SsrPattern
152 optional --debug snippet: String
154 }
155
156 cmd lsif {
157 required path: PathBuf
158
159 optional --exclude-vendored-libraries
161 }
162
163 cmd scip {
164 required path: PathBuf
165
166 optional --output path: PathBuf
168
169 optional --config-path config_path: PathBuf
171
172 optional --exclude-vendored-libraries
174 }
175 }
176}
177
178#[derive(Debug)]
182pub struct RustAnalyzer {
183 pub verbose: u32,
184 pub quiet: bool,
185 pub log_file: Option<PathBuf>,
186 pub no_log_buffering: bool,
187 pub wait_dbg: bool,
188 pub subcommand: RustAnalyzerCmd,
189}
190
191#[derive(Debug)]
192pub enum RustAnalyzerCmd {
193 LspServer(LspServer),
194 Parse(Parse),
195 Symbols(Symbols),
196 Highlight(Highlight),
197 AnalysisStats(AnalysisStats),
198 RunTests(RunTests),
199 RustcTests(RustcTests),
200 Diagnostics(Diagnostics),
201 UnresolvedReferences(UnresolvedReferences),
202 Ssr(Ssr),
203 Search(Search),
204 Lsif(Lsif),
205 Scip(Scip),
206}
207
208#[derive(Debug)]
209pub struct LspServer {
210 pub version: bool,
211 pub print_config_schema: bool,
212}
213
214#[derive(Debug)]
215pub struct Parse {
216 pub no_dump: bool,
217}
218
219#[derive(Debug)]
220pub struct Symbols;
221
222#[derive(Debug)]
223pub struct Highlight {
224 pub rainbow: bool,
225}
226
227#[derive(Debug)]
228pub struct AnalysisStats {
229 pub path: PathBuf,
230
231 pub output: Option<OutputFormat>,
232 pub randomize: bool,
233 pub parallel: bool,
234 pub source_stats: bool,
235 pub only: Option<String>,
236 pub with_deps: bool,
237 pub no_sysroot: bool,
238 pub no_test: bool,
239 pub disable_build_scripts: bool,
240 pub disable_proc_macros: bool,
241 pub proc_macro_srv: Option<PathBuf>,
242 pub skip_lowering: bool,
243 pub skip_inference: bool,
244 pub skip_mir_stats: bool,
245 pub skip_data_layout: bool,
246 pub skip_const_eval: bool,
247 pub run_all_ide_things: bool,
248 pub run_term_search: bool,
249 pub validate_term_search: bool,
250}
251
252#[derive(Debug)]
253pub struct RunTests {
254 pub path: PathBuf,
255}
256
257#[derive(Debug)]
258pub struct RustcTests {
259 pub rustc_repo: PathBuf,
260
261 pub filter: Option<String>,
262}
263
264#[derive(Debug)]
265pub struct Diagnostics {
266 pub path: PathBuf,
267
268 pub disable_build_scripts: bool,
269 pub disable_proc_macros: bool,
270 pub proc_macro_srv: Option<PathBuf>,
271}
272
273#[derive(Debug)]
274pub struct UnresolvedReferences {
275 pub path: PathBuf,
276
277 pub disable_build_scripts: bool,
278 pub disable_proc_macros: bool,
279 pub proc_macro_srv: Option<PathBuf>,
280}
281
282#[derive(Debug)]
283pub struct Ssr {
284 pub rule: Vec<SsrRule>,
285}
286
287#[derive(Debug)]
288pub struct Search {
289 pub pattern: Vec<SsrPattern>,
290
291 pub debug: Option<String>,
292}
293
294#[derive(Debug)]
295pub struct Lsif {
296 pub path: PathBuf,
297
298 pub exclude_vendored_libraries: bool,
299}
300
301#[derive(Debug)]
302pub struct Scip {
303 pub path: PathBuf,
304
305 pub output: Option<PathBuf>,
306 pub config_path: Option<PathBuf>,
307 pub exclude_vendored_libraries: bool,
308}
309
310impl RustAnalyzer {
311 #[allow(dead_code)]
312 pub fn from_env_or_exit() -> Self {
313 Self::from_env_or_exit_()
314 }
315
316 #[allow(dead_code)]
317 pub fn from_env() -> xflags::Result<Self> {
318 Self::from_env_()
319 }
320
321 #[allow(dead_code)]
322 pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
323 Self::from_vec_(args)
324 }
325}
326#[derive(Debug, PartialEq, Eq)]
329pub enum OutputFormat {
330 Csv,
331}
332
333impl RustAnalyzer {
334 pub fn verbosity(&self) -> Verbosity {
335 if self.quiet {
336 return Verbosity::Quiet;
337 }
338 match self.verbose {
339 0 => Verbosity::Normal,
340 1 => Verbosity::Verbose,
341 _ => Verbosity::Spammy,
342 }
343 }
344}
345
346impl FromStr for OutputFormat {
347 type Err = String;
348
349 fn from_str(s: &str) -> Result<Self, Self::Err> {
350 match s {
351 "csv" => Ok(Self::Csv),
352 _ => Err(format!("unknown output format `{s}`")),
353 }
354 }
355}