]> git.proxmox.com Git - rustc.git/blame - src/tools/rust-analyzer/crates/rust-analyzer/src/cli/flags.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / src / tools / rust-analyzer / crates / rust-analyzer / src / cli / flags.rs
CommitLineData
064997fb
FG
1//! Grammar for the command-line arguments.
2#![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 /// LSP server for the Rust programming language.
f2b60f7d
FG
13 ///
14 /// Subcommands and their flags do not provide any stability guarantees and may be removed or
15 /// changed without notice. Top-level flags that are not are marked as [Unstable] provide
16 /// backwards-compatibility and may be relied on.
064997fb
FG
17 cmd rust-analyzer {
18 /// Verbosity level, can be repeated multiple times.
19 repeated -v, --verbose
20 /// Verbosity level.
21 optional -q, --quiet
22
23 /// Log to the specified file instead of stderr.
24 optional --log-file path: PathBuf
25 /// Flush log records to the file immediately.
26 optional --no-log-buffering
27
f2b60f7d 28 /// [Unstable] Wait until a debugger is attached to (requires debug build).
064997fb
FG
29 optional --wait-dbg
30
31 default cmd lsp-server {
32 /// Print version.
33 optional --version
064997fb
FG
34
35 /// Dump a LSP config JSON schema.
36 optional --print-config-schema
37 }
38
39 /// Parse stdin.
40 cmd parse {
41 /// Suppress printing.
42 optional --no-dump
43 }
44
45 /// Parse stdin and print the list of symbols.
46 cmd symbols {}
47
48 /// Highlight stdin as html.
49 cmd highlight {
50 /// Enable rainbow highlighting of identifiers.
51 optional --rainbow
52 }
53
54 /// Batch typecheck project and print summary statistics
2b03887a 55 cmd analysis-stats {
064997fb
FG
56 /// Directory with Cargo.toml.
57 required path: PathBuf
2b03887a 58
064997fb
FG
59 optional --output format: OutputFormat
60
61 /// Randomize order in which crates, modules, and items are processed.
62 optional --randomize
63 /// Run type inference in parallel.
64 optional --parallel
65 /// Collect memory usage statistics.
66 optional --memory-usage
67 /// Print the total length of all source and macro files (whitespace is not counted).
68 optional --source-stats
69
70 /// Only analyze items matching this path.
71 optional -o, --only path: String
72 /// Also analyze all dependencies.
73 optional --with-deps
74 /// Don't load sysroot crates (`std`, `core` & friends).
75 optional --no-sysroot
76
77 /// Don't run build scripts or load `OUT_DIR` values by running `cargo check` before analysis.
78 optional --disable-build-scripts
79 /// Don't use expand proc macros.
80 optional --disable-proc-macros
81 /// Only resolve names, don't run type inference.
82 optional --skip-inference
83 }
84
2b03887a 85 cmd diagnostics {
064997fb
FG
86 /// Directory with Cargo.toml.
87 required path: PathBuf
2b03887a 88
064997fb
FG
89 /// Don't run build scripts or load `OUT_DIR` values by running `cargo check` before analysis.
90 optional --disable-build-scripts
91 /// Don't use expand proc macros.
92 optional --disable-proc-macros
93 }
94
2b03887a 95 cmd ssr {
064997fb
FG
96 /// A structured search replace rule (`$a.foo($b) ==> bar($a, $b)`)
97 repeated rule: SsrRule
2b03887a 98 }
064997fb 99
2b03887a 100 cmd search {
064997fb
FG
101 /// A structured search replace pattern (`$a.foo($b)`)
102 repeated pattern: SsrPattern
064997fb
FG
103 /// Prints debug information for any nodes with source exactly equal to snippet.
104 optional --debug snippet: String
105 }
106
107 cmd proc-macro {}
108
2b03887a 109 cmd lsif {
064997fb 110 required path: PathBuf
2b03887a 111 }
f2b60f7d 112
2b03887a 113 cmd scip {
f2b60f7d 114 required path: PathBuf
2b03887a 115 }
064997fb
FG
116 }
117}
118
119// generated start
120// The following code is generated by `xflags` macro.
121// Run `env UPDATE_XFLAGS=1 cargo build` to regenerate.
122#[derive(Debug)]
123pub struct RustAnalyzer {
124 pub verbose: u32,
125 pub quiet: bool,
126 pub log_file: Option<PathBuf>,
127 pub no_log_buffering: bool,
128 pub wait_dbg: bool,
129 pub subcommand: RustAnalyzerCmd,
130}
131
132#[derive(Debug)]
133pub enum RustAnalyzerCmd {
134 LspServer(LspServer),
135 Parse(Parse),
136 Symbols(Symbols),
137 Highlight(Highlight),
138 AnalysisStats(AnalysisStats),
139 Diagnostics(Diagnostics),
140 Ssr(Ssr),
141 Search(Search),
142 ProcMacro(ProcMacro),
143 Lsif(Lsif),
f2b60f7d 144 Scip(Scip),
064997fb
FG
145}
146
147#[derive(Debug)]
148pub struct LspServer {
149 pub version: bool,
064997fb
FG
150 pub print_config_schema: bool,
151}
152
153#[derive(Debug)]
154pub struct Parse {
155 pub no_dump: bool,
156}
157
158#[derive(Debug)]
159pub struct Symbols;
160
161#[derive(Debug)]
162pub struct Highlight {
163 pub rainbow: bool,
164}
165
166#[derive(Debug)]
167pub struct AnalysisStats {
168 pub path: PathBuf,
169
170 pub output: Option<OutputFormat>,
171 pub randomize: bool,
172 pub parallel: bool,
173 pub memory_usage: bool,
174 pub source_stats: bool,
175 pub only: Option<String>,
176 pub with_deps: bool,
177 pub no_sysroot: bool,
178 pub disable_build_scripts: bool,
179 pub disable_proc_macros: bool,
180 pub skip_inference: bool,
181}
182
183#[derive(Debug)]
184pub struct Diagnostics {
185 pub path: PathBuf,
186
187 pub disable_build_scripts: bool,
188 pub disable_proc_macros: bool,
189}
190
191#[derive(Debug)]
192pub struct Ssr {
193 pub rule: Vec<SsrRule>,
194}
195
196#[derive(Debug)]
197pub struct Search {
198 pub pattern: Vec<SsrPattern>,
199
200 pub debug: Option<String>,
201}
202
203#[derive(Debug)]
204pub struct ProcMacro;
205
206#[derive(Debug)]
207pub struct Lsif {
208 pub path: PathBuf,
209}
210
f2b60f7d
FG
211#[derive(Debug)]
212pub struct Scip {
213 pub path: PathBuf,
214}
215
064997fb 216impl RustAnalyzer {
2b03887a
FG
217 #[allow(dead_code)]
218 pub fn from_env_or_exit() -> Self {
219 Self::from_env_or_exit_()
220 }
064997fb
FG
221
222 #[allow(dead_code)]
223 pub fn from_env() -> xflags::Result<Self> {
224 Self::from_env_()
225 }
226
227 #[allow(dead_code)]
228 pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
229 Self::from_vec_(args)
230 }
231}
232// generated end
233
234#[derive(Debug, PartialEq, Eq)]
235pub enum OutputFormat {
236 Csv,
237}
238
239impl RustAnalyzer {
240 pub fn verbosity(&self) -> Verbosity {
241 if self.quiet {
242 return Verbosity::Quiet;
243 }
244 match self.verbose {
245 0 => Verbosity::Normal,
246 1 => Verbosity::Verbose,
247 _ => Verbosity::Spammy,
248 }
249 }
250}
251
252impl FromStr for OutputFormat {
253 type Err = String;
254
255 fn from_str(s: &str) -> Result<Self, Self::Err> {
256 match s {
257 "csv" => Ok(Self::Csv),
f25598a0 258 _ => Err(format!("unknown output format `{s}`")),
064997fb
FG
259 }
260 }
261}