mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +00:00
More convenient run_with_output
This commit is contained in:
parent
33df947d62
commit
1b6acc391a
3 changed files with 16 additions and 19 deletions
|
@ -18,7 +18,7 @@ impl Cmd<'_> {
|
||||||
run(self.unix, self.work_dir)
|
run(self.unix, self.work_dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn run_with_output(self) -> Result<Output> {
|
pub fn run_with_output(self) -> Result<String> {
|
||||||
if cfg!(windows) {
|
if cfg!(windows) {
|
||||||
run_with_output(self.windows, self.work_dir)
|
run_with_output(self.windows, self.work_dir)
|
||||||
} else {
|
} else {
|
||||||
|
@ -34,8 +34,10 @@ pub fn run(cmdline: &str, dir: &str) -> Result<()> {
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_with_output(cmdline: &str, dir: &str) -> Result<Output> {
|
pub fn run_with_output(cmdline: &str, dir: &str) -> Result<String> {
|
||||||
do_run(cmdline, dir, &mut |_| {})
|
let output = do_run(cmdline, dir, &mut |_| {})?;
|
||||||
|
let stdout = String::from_utf8(output.stdout)?;
|
||||||
|
Ok(stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_run(cmdline: &str, dir: &str, f: &mut dyn FnMut(&mut Command)) -> Result<Output> {
|
fn do_run(cmdline: &str, dir: &str, f: &mut dyn FnMut(&mut Command)) -> Result<Output> {
|
||||||
|
|
|
@ -127,15 +127,12 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
|
||||||
}
|
}
|
||||||
.run()?;
|
.run()?;
|
||||||
|
|
||||||
let installed_extensions = {
|
let installed_extensions = Cmd {
|
||||||
let output = Cmd {
|
unix: &format!(r"{} --list-extensions", code_binary),
|
||||||
unix: &format!(r"{} --list-extensions", code_binary),
|
windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary),
|
||||||
windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary),
|
work_dir: ".",
|
||||||
work_dir: ".",
|
}
|
||||||
}
|
.run_with_output()?;
|
||||||
.run_with_output()?;
|
|
||||||
String::from_utf8(output.stdout)?
|
|
||||||
};
|
|
||||||
|
|
||||||
if !installed_extensions.contains("rust-analyzer") {
|
if !installed_extensions.contains("rust-analyzer") {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
|
@ -161,12 +158,10 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
|
||||||
|
|
||||||
fn install_server(opts: ServerOpt) -> Result<()> {
|
fn install_server(opts: ServerOpt) -> Result<()> {
|
||||||
let mut old_rust = false;
|
let mut old_rust = false;
|
||||||
if let Ok(output) = run_with_output("cargo --version", ".") {
|
if let Ok(stdout) = run_with_output("cargo --version", ".") {
|
||||||
if let Ok(stdout) = String::from_utf8(output.stdout) {
|
println!("{}", stdout);
|
||||||
println!("{}", stdout);
|
if !check_version(&stdout, REQUIRED_RUST_VERSION) {
|
||||||
if !check_version(&stdout, REQUIRED_RUST_VERSION) {
|
old_rust = true;
|
||||||
old_rust = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub fn run_hook() -> Result<()> {
|
||||||
let diff = run_with_output("git diff --diff-filter=MAR --name-only --cached", ".")?;
|
let diff = run_with_output("git diff --diff-filter=MAR --name-only --cached", ".")?;
|
||||||
|
|
||||||
let root = project_root();
|
let root = project_root();
|
||||||
for line in String::from_utf8(diff.stdout)?.lines() {
|
for line in diff.lines() {
|
||||||
run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?;
|
run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue