mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Speedup fmt
This commit is contained in:
parent
8f1a83b4cb
commit
fabb804f30
2 changed files with 23 additions and 15 deletions
|
@ -4,7 +4,7 @@ extern crate teraron;
|
|||
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
process::Command,
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
|
||||
use failure::bail;
|
||||
|
@ -92,14 +92,16 @@ pub fn run(cmdline: &str, dir: &str) -> Result<()> {
|
|||
}
|
||||
|
||||
pub fn run_rustfmt(mode: Mode) -> Result<()> {
|
||||
run(&format!("rustup install {}", TOOLCHAIN), ".")?;
|
||||
run(
|
||||
&format!(
|
||||
"rustup component add rustfmt-preview --toolchain {}",
|
||||
TOOLCHAIN
|
||||
),
|
||||
".",
|
||||
)?;
|
||||
match Command::new("rustup")
|
||||
.args(&["run", TOOLCHAIN, "--", "cargo", "fmt", "--version"])
|
||||
.stderr(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.status()
|
||||
{
|
||||
Ok(status) if status.success() => (),
|
||||
_ => install_rustfmt()?,
|
||||
};
|
||||
|
||||
if mode == Verify {
|
||||
run(
|
||||
&format!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN),
|
||||
|
@ -110,3 +112,14 @@ pub fn run_rustfmt(mode: Mode) -> Result<()> {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn install_rustfmt() -> Result<()> {
|
||||
run(&format!("rustup install {}", TOOLCHAIN), ".")?;
|
||||
run(
|
||||
&format!(
|
||||
"rustup component add rustfmt-preview --toolchain {}",
|
||||
TOOLCHAIN
|
||||
),
|
||||
".",
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue