mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-14 08:57:34 +00:00
Merge #3080
3080: More convenient run_with_output r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
46a474866e
3 changed files with 16 additions and 19 deletions
|
@ -18,7 +18,7 @@ impl Cmd<'_> {
|
|||
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) {
|
||||
run_with_output(self.windows, self.work_dir)
|
||||
} else {
|
||||
|
@ -34,8 +34,10 @@ pub fn run(cmdline: &str, dir: &str) -> Result<()> {
|
|||
.map(|_| ())
|
||||
}
|
||||
|
||||
pub fn run_with_output(cmdline: &str, dir: &str) -> Result<Output> {
|
||||
do_run(cmdline, dir, &mut |_| {})
|
||||
pub fn run_with_output(cmdline: &str, dir: &str) -> Result<String> {
|
||||
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> {
|
||||
|
|
|
@ -127,15 +127,12 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
|
|||
}
|
||||
.run()?;
|
||||
|
||||
let installed_extensions = {
|
||||
let output = Cmd {
|
||||
unix: &format!(r"{} --list-extensions", code_binary),
|
||||
windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary),
|
||||
work_dir: ".",
|
||||
}
|
||||
.run_with_output()?;
|
||||
String::from_utf8(output.stdout)?
|
||||
};
|
||||
let installed_extensions = Cmd {
|
||||
unix: &format!(r"{} --list-extensions", code_binary),
|
||||
windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary),
|
||||
work_dir: ".",
|
||||
}
|
||||
.run_with_output()?;
|
||||
|
||||
if !installed_extensions.contains("rust-analyzer") {
|
||||
anyhow::bail!(
|
||||
|
@ -161,12 +158,10 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
|
|||
|
||||
fn install_server(opts: ServerOpt) -> Result<()> {
|
||||
let mut old_rust = false;
|
||||
if let Ok(output) = run_with_output("cargo --version", ".") {
|
||||
if let Ok(stdout) = String::from_utf8(output.stdout) {
|
||||
println!("{}", stdout);
|
||||
if !check_version(&stdout, REQUIRED_RUST_VERSION) {
|
||||
old_rust = true;
|
||||
}
|
||||
if let Ok(stdout) = run_with_output("cargo --version", ".") {
|
||||
println!("{}", stdout);
|
||||
if !check_version(&stdout, REQUIRED_RUST_VERSION) {
|
||||
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 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()), ".")?;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue