mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 21:13:37 +00:00
Merge #933
933: Check installed extension r=matklad a=c410-f3r Fixes #918. Edit: Windows encoding for Unicode is UTF-16 so String::from_utf8 will probably fail unless `Vec<u8>` is already UTF-8 somehow, which I don't know for sure. Co-authored-by: Caio <c410.f3r@gmail.com>
This commit is contained in:
commit
b1a1d20e06
2 changed files with 45 additions and 12 deletions
|
@ -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<Output> {
|
||||
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<F>(cmdline: &str, dir: &str, mut f: F) -> Result<Output>
|
||||
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<String, Test>,
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue