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
{
35 /// Dump a LSP config JSON schema.
36 optional
--print
-config
-schema
41 /// Suppress printing.
45 /// Parse stdin and print the list of symbols.
48 /// Highlight stdin as html.
50 /// Enable rainbow highlighting of identifiers.
54 /// Batch typecheck project and print summary statistics
56 /// Directory with Cargo.toml.
57 required path
: PathBuf
59 optional
--output format
: OutputFormat
61 /// Randomize order in which crates, modules, and items are processed.
63 /// Run type inference in 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
70 /// Only analyze items matching this path.
71 optional
-o
, --only path
: String
72 /// Also analyze all dependencies.
74 /// Don't load sysroot crates (`std`, `core` & friends).
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
86 /// Directory with Cargo.toml.
87 required path
: PathBuf
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
96 /// A structured search replace rule (`$a.foo($b) ==> bar($a, $b)`)
97 repeated rule
: SsrRule
101 /// A structured search replace pattern (`$a.foo($b)`)
102 repeated pattern
: SsrPattern
103 /// Prints debug information for any nodes with source exactly equal to snippet.
104 optional
--debug snippet
: String
110 required path
: PathBuf
114 required path
: PathBuf
120 // The following code is generated by `xflags` macro.
121 // Run `env UPDATE_XFLAGS=1 cargo build` to regenerate.
123 pub struct RustAnalyzer
{
126 pub log_file
: Option
<PathBuf
>,
127 pub no_log_buffering
: bool
,
129 pub subcommand
: RustAnalyzerCmd
,
133 pub enum RustAnalyzerCmd
{
134 LspServer(LspServer
),
137 Highlight(Highlight
),
138 AnalysisStats(AnalysisStats
),
139 Diagnostics(Diagnostics
),
142 ProcMacro(ProcMacro
),
148 pub struct LspServer
{
150 pub print_config_schema
: bool
,
162 pub struct Highlight
{
167 pub struct AnalysisStats
{
170 pub output
: Option
<OutputFormat
>,
173 pub memory_usage
: bool
,
174 pub source_stats
: bool
,
175 pub only
: Option
<String
>,
177 pub no_sysroot
: bool
,
178 pub disable_build_scripts
: bool
,
179 pub disable_proc_macros
: bool
,
180 pub skip_inference
: bool
,
184 pub struct Diagnostics
{
187 pub disable_build_scripts
: bool
,
188 pub disable_proc_macros
: bool
,
193 pub rule
: Vec
<SsrRule
>,
198 pub pattern
: Vec
<SsrPattern
>,
200 pub debug
: Option
<String
>,
204 pub struct ProcMacro
;
218 pub fn from_env_or_exit() -> Self {
219 Self::from_env_or_exit_()
223 pub fn from_env() -> xflags
::Result
<Self> {
228 pub fn from_vec(args
: Vec
<std
::ffi
::OsString
>) -> xflags
::Result
<Self> {
229 Self::from_vec_(args
)
234 #[derive(Debug, PartialEq, Eq)]
235 pub enum OutputFormat
{
240 pub fn verbosity(&self) -> Verbosity
{
242 return Verbosity
::Quiet
;
245 0 => Verbosity
::Normal
,
246 1 => Verbosity
::Verbose
,
247 _
=> Verbosity
::Spammy
,
252 impl FromStr
for OutputFormat
{
255 fn from_str(s
: &str) -> Result
<Self, Self::Err
> {
257 "csv" => Ok(Self::Csv
),
258 _
=> Err(format
!("unknown output format `{s}`")),