1 //! Grammar for the command-line arguments.
2 #![allow(unreachable_pub)]
3 use std::{path::PathBuf, str::FromStr};
5 use ide_ssr::{SsrPattern, SsrRule};
7 use crate::cli::Verbosity;
10 src "./src/cli/flags.rs"
12 /// LSP server for the Rust programming language.
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.
18 /// Verbosity level, can be repeated multiple times.
19 repeated -v, --verbose
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
28 /// [Unstable] Wait until a debugger is attached to (requires debug build).
31 default cmd lsp-server {
37 /// Dump a LSP config JSON schema.
38 optional --print-config-schema
43 /// Suppress printing.
47 /// Parse stdin and print the list of symbols.
50 /// Highlight stdin as html.
52 /// Enable rainbow highlighting of identifiers.
56 /// Batch typecheck project and print summary statistics
58 /// Directory with Cargo.toml.
59 required path: PathBuf
61 optional --output format: OutputFormat
63 /// Randomize order in which crates, modules, and items are processed.
65 /// Run type inference in parallel.
67 /// Collect memory usage statistics.
68 optional --memory-usage
69 /// Print the total length of all source and macro files (whitespace is not counted).
70 optional --source-stats
72 /// Only analyze items matching this path.
73 optional -o, --only path: String
74 /// Also analyze all dependencies.
76 /// Don't load sysroot crates (`std`, `core` & friends).
79 /// Don't run build scripts or load `OUT_DIR` values by running `cargo check` before analysis.
80 optional --disable-build-scripts
81 /// Don't use expand proc macros.
82 optional --disable-proc-macros
83 /// Only resolve names, don't run type inference.
84 optional --skip-inference
88 /// Directory with Cargo.toml.
89 required path: PathBuf
91 /// Don't run build scripts or load `OUT_DIR` values by running `cargo check` before analysis.
92 optional --disable-build-scripts
93 /// Don't use expand proc macros.
94 optional --disable-proc-macros
98 /// A structured search replace rule (`$a.foo($b) ==> bar($a, $b)`)
99 repeated rule: SsrRule
103 /// A structured search replace pattern (`$a.foo($b)`)
104 repeated pattern: SsrPattern
106 /// Prints debug information for any nodes with source exactly equal to snippet.
107 optional --debug snippet: String
113 required path: PathBuf
117 required path: PathBuf
123 // The following code is generated by `xflags` macro.
124 // Run `env UPDATE_XFLAGS=1 cargo build` to regenerate.
126 pub struct RustAnalyzer {
129 pub log_file: Option<PathBuf>,
130 pub no_log_buffering: bool,
132 pub subcommand: RustAnalyzerCmd,
136 pub enum RustAnalyzerCmd {
137 LspServer(LspServer),
140 Highlight(Highlight),
141 AnalysisStats(AnalysisStats),
142 Diagnostics(Diagnostics),
145 ProcMacro(ProcMacro),
151 pub struct LspServer {
154 pub print_config_schema: bool,
166 pub struct Highlight {
171 pub struct AnalysisStats {
174 pub output: Option<OutputFormat>,
177 pub memory_usage: bool,
178 pub source_stats: bool,
179 pub only: Option<String>,
181 pub no_sysroot: bool,
182 pub disable_build_scripts: bool,
183 pub disable_proc_macros: bool,
184 pub skip_inference: bool,
188 pub struct Diagnostics {
191 pub disable_build_scripts: bool,
192 pub disable_proc_macros: bool,
197 pub rule: Vec<SsrRule>,
202 pub pattern: Vec<SsrPattern>,
204 pub debug: Option<String>,
208 pub struct ProcMacro;
221 pub const HELP: &'static str = Self::HELP_;
224 pub fn from_env() -> xflags::Result<Self> {
229 pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
230 Self::from_vec_(args)
235 #[derive(Debug, PartialEq, Eq)]
236 pub enum OutputFormat {
241 pub fn verbosity(&self) -> Verbosity {
243 return Verbosity::Quiet;
246 0 => Verbosity::Normal,
247 1 => Verbosity::Verbose,
248 _ => Verbosity::Spammy,
253 impl FromStr for OutputFormat {
256 fn from_str(s: &str) -> Result<Self, Self::Err> {
258 "csv" => Ok(Self::Csv),
259 _ => Err(format!("unknown output format `{}`", s)),