From cb60416cb59c87244a523bab464a265db7e58f04 Mon Sep 17 00:00:00 2001 From: Caio Date: Tue, 5 Mar 2019 18:19:36 -0300 Subject: Check installed extension --- crates/tools/src/lib.rs | 36 ++++++++++++++++++++++++++---------- crates/tools/src/main.rs | 21 +++++++++++++++++++-- 2 files changed, 45 insertions(+), 12 deletions(-) (limited to 'crates/tools') diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 3c23ed76e..1e29c63d4 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs @@ -2,7 +2,7 @@ use std::{ fs, collections::HashMap, path::{Path, PathBuf}, - process::{Command, Stdio}, + process::{Command, Output, Stdio}, io::{Error, ErrorKind} }; @@ -80,15 +80,14 @@ pub fn project_root() -> PathBuf { } pub fn run(cmdline: &str, dir: &str) -> Result<()> { - eprintln!("\nwill run: {}", cmdline); - let project_dir = project_root().join(dir); - let mut args = cmdline.split_whitespace(); - let exec = args.next().unwrap(); - let status = Command::new(exec).args(args).current_dir(project_dir).status()?; - if !status.success() { - bail!("`{}` exited with {}", cmdline, status); - } - Ok(()) + do_run(cmdline, dir, |c| { + c.stdout(Stdio::inherit()); + }) + .map(|_| ()) +} + +pub fn run_with_output(cmdline: &str, dir: &str) -> Result { + do_run(cmdline, dir, |_| {}) } pub fn run_rustfmt(mode: Mode) -> Result<()> { @@ -175,6 +174,23 @@ pub fn gen_tests(mode: Mode) -> Result<()> { install_tests(&tests.err, ERR_INLINE_TESTS_DIR, mode) } +fn do_run(cmdline: &str, dir: &str, mut f: F) -> Result +where + F: FnMut(&mut Command), +{ + eprintln!("\nwill run: {}", cmdline); + let proj_dir = project_root().join(dir); + let mut args = cmdline.split_whitespace(); + let exec = args.next().unwrap(); + let mut cmd = Command::new(exec); + f(cmd.args(args).current_dir(proj_dir).stderr(Stdio::inherit())); + let output = cmd.output()?; + if !output.status.success() { + bail!("`{}` exited with {}", cmdline, output.status); + } + Ok(output) +} + #[derive(Default, Debug)] struct Tests { pub ok: HashMap, diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs index 963ffbe98..4a1b2ff9a 100644 --- a/crates/tools/src/main.rs +++ b/crates/tools/src/main.rs @@ -1,7 +1,8 @@ use clap::{App, SubCommand}; - +use core::str; +use failure::bail; use tools::{ - generate, gen_tests, install_format_hook, run, run_rustfmt, + generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt, Overwrite, Result, run_fuzzer, }; @@ -44,5 +45,21 @@ fn install_code_extension() -> Result<()> { } else { run(r"code --install-extension ./ra-lsp-0.0.1.vsix --force", "./editors/code")?; } + verify_installed_extensions()?; + Ok(()) +} + +fn verify_installed_extensions() -> Result<()> { + let exts = if cfg!(windows) { + run_with_output(r"cmd.exe /c code.cmd --list-extensions", ".")? + } else { + run_with_output(r"code --list-extensions", ".")? + }; + if !str::from_utf8(&exts.stdout)?.contains("ra-lsp") { + bail!( + "Could not install the Visual Studio Code extension. Please make sure you \ + have at least NodeJS 10.x installed and try again." + ); + } Ok(()) } -- cgit v1.2.3