diff --git a/Cargo.lock b/Cargo.lock index 93b7f746e0..e45cde6838 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2082,18 +2082,18 @@ checksum = "06069a848f95fceae3e5e03c0ddc8cb78452b56654ee0c8e68f938cf790fb9e3" [[package]] name = "xflags" -version = "0.2.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f14fe1ed41a5a2b5ef3f565586c4a8a559ee55d3953faab360a771135bdee00" +checksum = "cbf19f5031a1a812e96fede16f8161218883079946cea87619d3613db1efd268" dependencies = [ "xflags-macros", ] [[package]] name = "xflags-macros" -version = "0.2.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45d11d5fc2a97287eded8b170ca80533b3c42646dd7fa386a5eb045817921022" +checksum = "2afbd7f2039bb6cad2dd45f0c5dff49c0d4e26118398768b7a605524d4251809" [[package]] name = "xshell" diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index 71566d5de6..a4e6550984 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -25,7 +25,7 @@ itertools = "0.10.3" scip = "0.1.1" lsp-types = { version = "0.93.1", features = ["proposed"] } parking_lot = "0.12.1" -xflags = "0.2.4" +xflags = "0.3.0" oorandom = "11.1.3" rustc-hash = "1.1.0" serde = { version = "1.0.137", features = ["derive"] } diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index f6a6802972..eabfcf1944 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs @@ -37,16 +37,15 @@ fn main() { process::exit(code); } - if let Err(err) = try_main() { + let flags = flags::RustAnalyzer::from_env_or_exit(); + if let Err(err) = try_main(flags) { tracing::error!("Unexpected error: {}", err); eprintln!("{}", err); process::exit(101); } } -fn try_main() -> Result<()> { - let flags = flags::RustAnalyzer::from_env()?; - +fn try_main(flags: flags::RustAnalyzer) -> Result<()> { #[cfg(debug_assertions)] if flags.wait_dbg || env::var("RA_WAIT_DBG").is_ok() { #[allow(unused_mut)] @@ -76,10 +75,6 @@ fn try_main() -> Result<()> { println!("rust-analyzer {}", rust_analyzer::version()); return Ok(()); } - if cmd.help { - println!("{}", flags::RustAnalyzer::HELP); - return Ok(()); - } with_extra_thread("LspServer", run_server)?; } flags::RustAnalyzerCmd::ProcMacro(flags::ProcMacro) => { diff --git a/crates/rust-analyzer/src/cli/flags.rs b/crates/rust-analyzer/src/cli/flags.rs index aa32654fbd..5bcc97e226 100644 --- a/crates/rust-analyzer/src/cli/flags.rs +++ b/crates/rust-analyzer/src/cli/flags.rs @@ -31,8 +31,6 @@ xflags::xflags! { default cmd lsp-server { /// Print version. optional --version - /// Print help. - optional -h, --help /// Dump a LSP config JSON schema. optional --print-config-schema @@ -54,10 +52,10 @@ xflags::xflags! { } /// Batch typecheck project and print summary statistics - cmd analysis-stats + cmd analysis-stats { /// Directory with Cargo.toml. required path: PathBuf - { + optional --output format: OutputFormat /// Randomize order in which crates, modules, and items are processed. @@ -84,38 +82,37 @@ xflags::xflags! { optional --skip-inference } - cmd diagnostics + cmd diagnostics { /// Directory with Cargo.toml. required path: PathBuf - { + /// Don't run build scripts or load `OUT_DIR` values by running `cargo check` before analysis. optional --disable-build-scripts /// Don't use expand proc macros. optional --disable-proc-macros } - cmd ssr + cmd ssr { /// A structured search replace rule (`$a.foo($b) ==> bar($a, $b)`) repeated rule: SsrRule - {} + } - cmd search + cmd search { /// A structured search replace pattern (`$a.foo($b)`) repeated pattern: SsrPattern - { /// Prints debug information for any nodes with source exactly equal to snippet. optional --debug snippet: String } cmd proc-macro {} - cmd lsif + cmd lsif { required path: PathBuf - {} + } - cmd scip + cmd scip { required path: PathBuf - {} + } } } @@ -150,7 +147,6 @@ pub enum RustAnalyzerCmd { #[derive(Debug)] pub struct LspServer { pub version: bool, - pub help: bool, pub print_config_schema: bool, } @@ -218,7 +214,10 @@ pub struct Scip { } impl RustAnalyzer { - pub const HELP: &'static str = Self::HELP_; + #[allow(dead_code)] + pub fn from_env_or_exit() -> Self { + Self::from_env_or_exit_() + } #[allow(dead_code)] pub fn from_env() -> xflags::Result { diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 95d44e9b9d..14816912b7 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -11,5 +11,5 @@ anyhow = "1.0.57" flate2 = "1.0.24" write-json = "0.1.2" xshell = "0.2.2" -xflags = "0.2.4" +xflags = "0.3.0" # Avoid adding more dependencies to this crate diff --git a/xtask/src/flags.rs b/xtask/src/flags.rs index 993c64ccea..0fce488983 100644 --- a/xtask/src/flags.rs +++ b/xtask/src/flags.rs @@ -7,10 +7,6 @@ xflags::xflags! { /// Run custom build command. cmd xtask { - default cmd help { - /// Print help information. - optional -h, --help - } /// Install rust-analyzer server or editor plugin. cmd install { @@ -42,9 +38,9 @@ xflags::xflags! { optional --dry-run } /// Builds a benchmark version of rust-analyzer and puts it into `./target`. - cmd bb + cmd bb { required suffix: String - {} + } } } @@ -58,7 +54,6 @@ pub struct Xtask { #[derive(Debug)] pub enum XtaskCmd { - Help(Help), Install(Install), FuzzTests(FuzzTests), Release(Release), @@ -68,11 +63,6 @@ pub enum XtaskCmd { Bb(Bb), } -#[derive(Debug)] -pub struct Help { - pub help: bool, -} - #[derive(Debug)] pub struct Install { pub client: bool, @@ -111,7 +101,10 @@ pub struct Bb { } impl Xtask { - pub const HELP: &'static str = Self::HELP_; + #[allow(dead_code)] + pub fn from_env_or_exit() -> Self { + Self::from_env_or_exit_() + } #[allow(dead_code)] pub fn from_env() -> xflags::Result { diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 335ac324a5..a37f469adc 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -25,15 +25,12 @@ use std::{ use xshell::{cmd, Shell}; fn main() -> anyhow::Result<()> { + let flags = flags::Xtask::from_env_or_exit(); + let sh = &Shell::new()?; sh.change_dir(project_root()); - let flags = flags::Xtask::from_env()?; match flags.subcommand { - flags::XtaskCmd::Help(_) => { - println!("{}", flags::Xtask::HELP); - Ok(()) - } flags::XtaskCmd::Install(cmd) => cmd.run(sh), flags::XtaskCmd::FuzzTests(_) => run_fuzzer(sh), flags::XtaskCmd::Release(cmd) => cmd.run(sh),