Auto merge of #13366 - matklad:xflags, r=lnicola
internal: ⬆️ xflags
The main change here should be that flags are not inhereted, so
$ rust-analyzer analysis-stats . -v -v
would do what it should do
We also no longer Don\'t
This commit is contained in:
commit
61504c8d95
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -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"
|
||||
|
@ -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"] }
|
||||
|
@ -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) => {
|
||||
|
@ -31,8 +31,6 @@
|
||||
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 @@
|
||||
}
|
||||
|
||||
/// 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 @@
|
||||
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<Self> {
|
||||
|
@ -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
|
||||
|
@ -7,10 +7,6 @@
|
||||
|
||||
/// 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 @@
|
||||
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<Self> {
|
||||
|
@ -25,15 +25,12 @@
|
||||
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),
|
||||
|
Loading…
Reference in New Issue
Block a user