Add a simple SSR subcommand to the rust-analyzer command line binary

This commit is contained in:
David Lattimore
2020-06-27 17:31:50 +10:00
parent ca31b1d63a
commit 93a91ae9de
6 changed files with 73 additions and 0 deletions

View File

@@ -5,6 +5,7 @@
use anyhow::{bail, Result};
use pico_args::Arguments;
use ra_ssr::SsrRule;
use rust_analyzer::cli::{BenchWhat, Position, Verbosity};
use std::{fmt::Write, path::PathBuf};
@@ -45,6 +46,9 @@ pub(crate) enum Command {
/// this would include the parser test files.
all: bool,
},
Ssr {
rules: Vec<SsrRule>,
},
ProcMacro,
RunServer,
Version,
@@ -270,6 +274,32 @@ ARGS:
Command::Diagnostics { path, load_output_dirs, with_proc_macro, all }
}
"proc-macro" => Command::ProcMacro,
"ssr" => {
if matches.contains(["-h", "--help"]) {
eprintln!(
"\
rust-analyzer ssr
USAGE:
rust-analyzer ssr [FLAGS] [RULE...]
EXAMPLE:
rust-analyzer ssr '$a.foo($b) ==> bar($a, $b)'
FLAGS:
-h, --help Prints help information
ARGS:
<RULE> A structured search replace rule"
);
return Ok(Err(HelpPrinted));
}
let mut rules = Vec::new();
while let Some(rule) = matches.free_from_str()? {
rules.push(rule);
}
Command::Ssr { rules }
}
_ => {
print_subcommands();
return Ok(Err(HelpPrinted));
@@ -297,6 +327,7 @@ SUBCOMMANDS:
diagnostics
proc-macro
parse
ssr
symbols"
)
}

View File

@@ -60,6 +60,9 @@ fn main() -> Result<()> {
args::Command::Diagnostics { path, load_output_dirs, with_proc_macro, all } => {
cli::diagnostics(path.as_ref(), load_output_dirs, with_proc_macro, all)?
}
args::Command::Ssr { rules } => {
cli::apply_ssr_rules(rules)?;
}
args::Command::Version => println!("rust-analyzer {}", env!("REV")),
}
Ok(())