mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
run stable fmt through rustup
This commit is contained in:
parent
51705698bd
commit
e8a9bc09a3
2 changed files with 11 additions and 10 deletions
|
@ -13,9 +13,8 @@ use xshell::cmd;
|
||||||
fn check_code_formatting() {
|
fn check_code_formatting() {
|
||||||
let sh = &Shell::new().unwrap();
|
let sh = &Shell::new().unwrap();
|
||||||
sh.change_dir(sourcegen::project_root());
|
sh.change_dir(sourcegen::project_root());
|
||||||
sh.set_var("RUSTUP_TOOLCHAIN", "stable");
|
|
||||||
|
|
||||||
let out = cmd!(sh, "rustfmt --version").read().unwrap();
|
let out = cmd!(sh, "rustup run stable rustfmt --version").read().unwrap();
|
||||||
if !out.contains("stable") {
|
if !out.contains("stable") {
|
||||||
panic!(
|
panic!(
|
||||||
"Failed to run rustfmt from toolchain 'stable'. \
|
"Failed to run rustfmt from toolchain 'stable'. \
|
||||||
|
@ -23,9 +22,9 @@ fn check_code_formatting() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = cmd!(sh, "cargo fmt -- --check").run();
|
let res = cmd!(sh, "rustup run stable cargo fmt -- --check").run();
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
let _ = cmd!(sh, "cargo fmt").run();
|
let _ = cmd!(sh, "rustup run stable cargo fmt").run();
|
||||||
}
|
}
|
||||||
res.unwrap()
|
res.unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,7 @@ impl fmt::Display for Location {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ensure_rustfmt(sh: &Shell) {
|
fn ensure_rustfmt(sh: &Shell) {
|
||||||
let version = cmd!(sh, "rustfmt --version").read().unwrap_or_default();
|
let version = cmd!(sh, "rustup run stable rustfmt --version").read().unwrap_or_default();
|
||||||
if !version.contains("stable") {
|
if !version.contains("stable") {
|
||||||
panic!(
|
panic!(
|
||||||
"Failed to run rustfmt from toolchain 'stable'. \
|
"Failed to run rustfmt from toolchain 'stable'. \
|
||||||
|
@ -147,13 +147,15 @@ fn ensure_rustfmt(sh: &Shell) {
|
||||||
|
|
||||||
pub fn reformat(text: String) -> String {
|
pub fn reformat(text: String) -> String {
|
||||||
let sh = Shell::new().unwrap();
|
let sh = Shell::new().unwrap();
|
||||||
sh.set_var("RUSTUP_TOOLCHAIN", "stable");
|
|
||||||
ensure_rustfmt(&sh);
|
ensure_rustfmt(&sh);
|
||||||
let rustfmt_toml = project_root().join("rustfmt.toml");
|
let rustfmt_toml = project_root().join("rustfmt.toml");
|
||||||
let mut stdout = cmd!(sh, "rustfmt --config-path {rustfmt_toml} --config fn_single_line=true")
|
let mut stdout = cmd!(
|
||||||
.stdin(text)
|
sh,
|
||||||
.read()
|
"rustup run stable rustfmt --config-path {rustfmt_toml} --config fn_single_line=true"
|
||||||
.unwrap();
|
)
|
||||||
|
.stdin(text)
|
||||||
|
.read()
|
||||||
|
.unwrap();
|
||||||
if !stdout.ends_with('\n') {
|
if !stdout.ends_with('\n') {
|
||||||
stdout.push('\n');
|
stdout.push('\n');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue