diff options
author | Michael Benfield <mbenfield@google.com> | 2022-07-26 23:08:24 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-07-26 23:57:37 +0000 |
commit | 47f4df525e7956780ca2cda5945f4785f0c76550 (patch) | |
tree | cd855244d9eab6445b00fd6257a966171b751a05 | |
parent | 5f84460959d28b1bf80e429eede18aaa6ef20ccf (diff) | |
download | toolchain-utils-47f4df525e7956780ca2cda5945f4785f0c76550.tar.gz |
rust-analyzer-chromiumos-wrapper: Support some command line arguments.
VS Code (and possibly other editors) like to pass `--version` and
possibly other arguments, so forward them to `rust-analyzer`.
BUG=b:240341002
TEST=Build, test on VS Code
Change-Id: Icadf05088c4220f058fcdce68489d266368ab1e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3785120
Commit-Queue: George Burgess <gbiv@chromium.org>
Auto-Submit: Michael Benfield <mbenfield@google.com>
Reviewed-by: George Burgess <gbiv@chromium.org>
Tested-by: Michael Benfield <mbenfield@google.com>
-rw-r--r-- | rust-analyzer-chromiumos-wrapper/src/main.rs | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/rust-analyzer-chromiumos-wrapper/src/main.rs b/rust-analyzer-chromiumos-wrapper/src/main.rs index 7bc52d26..626108ad 100644 --- a/rust-analyzer-chromiumos-wrapper/src/main.rs +++ b/rust-analyzer-chromiumos-wrapper/src/main.rs @@ -20,11 +20,7 @@ use simplelog::{Config, LevelFilter, WriteLogger}; use serde_json::{from_slice, to_writer, Value}; fn main() -> Result<()> { - if env::args().len() > 1 { - bail!("rust-analyzer-chromiumos-wrapper doesn't support command line arguments"); - } - - init_log()?; + let args = env::args().skip(1); let d = env::current_dir()?; let chromiumos_root = match find_chromiumos_root(&d) { @@ -32,10 +28,46 @@ fn main() -> Result<()> { None => { // It doesn't appear that we're in a chroot. Run the // regular rust-analyzer. - return Err(process::Command::new("rust-analyzer").exec())?; + return Err(process::Command::new("rust-analyzer").args(args).exec())?; } }; + let args: Vec<String> = args.collect(); + if !args.is_empty() { + // We've received command line arguments, and there are 3 possibilities: + // * We just forward the arguments to rust-analyzer and exit. + // * We don't support the arguments, so we bail. + // * We still need to do our path translation in the LSP protocol. + fn run(args: &[String]) -> Result<()> { + return Err(process::Command::new("cros_sdk") + .args(["--", "rust-analyzer"]) + .args(args) + .exec())?; + } + + if args.iter().any(|x| match x.as_str() { + "--version" | "--help" | "-h" | "--print-config-schema" => true, + _ => false, + }) { + // With any of these options rust-analyzer will just print something and exit. + return run(&args); + } + + if !args[0].starts_with("-") { + // It's a subcommand, and seemingly none of these need the path translation + // rust-analyzer-chromiumos-wrapper provides. + return run(&args); + } + + if args.iter().any(|x| x == "--log-file") { + bail!("rust-analyzer-chromiums_wrapper doesn't support --log-file"); + } + + // Otherwise it seems we're probably OK to proceed. + } + + init_log()?; + let outside_prefix: &'static str = { let path = chromiumos_root .to_str() @@ -55,8 +87,10 @@ fn main() -> Result<()> { let inside_prefix: &'static str = "file:///mnt/host/source/"; let cmd = "cros_sdk"; - let args: [&str; 2] = ["--", "rust-analyzer"]; - let mut child = KillOnDrop(run_command(cmd, args)?); + let all_args = ["--", "rust-analyzer"] + .into_iter() + .chain(args.iter().map(|x| x.as_str())); + let mut child = KillOnDrop(run_command(cmd, all_args)?); let mut child_stdin = BufWriter::new(child.0.stdin.take().unwrap()); let mut child_stdout = BufReader::new(child.0.stdout.take().unwrap()); |