From fabb804f3091e1cf0f8c289fcb15a8d39bc960a5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 31 Oct 2018 23:57:38 +0300 Subject: [PATCH] Speedup fmt --- crates/ra_analysis/src/syntax_ptr.rs | 7 +------ crates/tools/src/lib.rs | 31 ++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/crates/ra_analysis/src/syntax_ptr.rs b/crates/ra_analysis/src/syntax_ptr.rs index e23bda4d597..71e51e7020c 100644 --- a/crates/ra_analysis/src/syntax_ptr.rs +++ b/crates/ra_analysis/src/syntax_ptr.rs @@ -1,9 +1,4 @@ -use std::marker::PhantomData; - -use ra_syntax::{ - ast::{self, AstNode}, - File, SyntaxKind, SyntaxNode, SyntaxNodeRef, TextRange, -}; +use ra_syntax::{File, SyntaxKind, SyntaxNode, SyntaxNodeRef, TextRange}; use crate::db::SyntaxDatabase; use crate::FileId; diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 3387d0620e4..8b8e9974e87 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs @@ -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 + ), + ".", + ) +}