mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-18 17:40:29 +00:00
⬆️ xshell
This commit is contained in:
parent
5e85158706
commit
56e43c34e7
14 changed files with 247 additions and 212 deletions
|
@ -11,7 +11,7 @@ use std::{
|
|||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use xshell::{cmd, pushenv};
|
||||
use xshell::{cmd, Shell};
|
||||
|
||||
pub fn list_rust_files(dir: &Path) -> Vec<PathBuf> {
|
||||
let mut res = list_files(dir);
|
||||
|
@ -133,8 +133,8 @@ impl fmt::Display for Location {
|
|||
}
|
||||
}
|
||||
|
||||
fn ensure_rustfmt() {
|
||||
let version = cmd!("rustfmt --version").read().unwrap_or_default();
|
||||
fn ensure_rustfmt(sh: &Shell) {
|
||||
let version = cmd!(sh, "rustfmt --version").read().unwrap_or_default();
|
||||
if !version.contains("stable") {
|
||||
panic!(
|
||||
"Failed to run rustfmt from toolchain 'stable'. \
|
||||
|
@ -144,10 +144,11 @@ fn ensure_rustfmt() {
|
|||
}
|
||||
|
||||
pub fn reformat(text: String) -> String {
|
||||
let _e = pushenv("RUSTUP_TOOLCHAIN", "stable");
|
||||
ensure_rustfmt();
|
||||
let sh = Shell::new().unwrap();
|
||||
sh.set_var("RUSTUP_TOOLCHAIN", "stable");
|
||||
ensure_rustfmt(&sh);
|
||||
let rustfmt_toml = project_root().join("rustfmt.toml");
|
||||
let mut stdout = cmd!("rustfmt --config-path {rustfmt_toml} --config fn_single_line=true")
|
||||
let mut stdout = cmd!(sh, "rustfmt --config-path {rustfmt_toml} --config fn_single_line=true")
|
||||
.stdin(text)
|
||||
.read()
|
||||
.unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue