Skip to content

Commit 638755a

Browse files
committed
Log rustfmt parsing errors as warnings
We unconditionally pass an edition parameter to rustfmt, for some crates this might fail rustfmt so instead of swallowing the error, at least Log it on a level that is logged by default so users won't be completely confused about it. See for context rust-lang/rust-analyzer#10209 Closes rust-lang/rust-analyzer#10209
1 parent 49700e4 commit 638755a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

crates/rust-analyzer/src/handlers.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ fn run_rustfmt(
17661766

17671767
let line_index = snap.file_line_index(file_id)?;
17681768

1769-
let mut rustfmt = match snap.config.rustfmt() {
1769+
let mut command = match snap.config.rustfmt() {
17701770
RustfmtConfig::Rustfmt { extra_args, enable_range_formatting } => {
17711771
let mut cmd = process::Command::new(toolchain::rustfmt());
17721772
cmd.args(extra_args);
@@ -1831,12 +1831,12 @@ fn run_rustfmt(
18311831
}
18321832
};
18331833

1834-
let mut rustfmt = rustfmt
1834+
let mut rustfmt = command
18351835
.stdin(Stdio::piped())
18361836
.stdout(Stdio::piped())
18371837
.stderr(Stdio::piped())
18381838
.spawn()
1839-
.context(format!("Failed to spawn {:?}", rustfmt))?;
1839+
.context(format!("Failed to spawn {:?}", command))?;
18401840

18411841
rustfmt.stdin.as_mut().unwrap().write_all(file.as_bytes())?;
18421842

@@ -1855,7 +1855,11 @@ fn run_rustfmt(
18551855
// formatting because otherwise an error is surfaced to the user on top of the
18561856
// syntax error diagnostics they're already receiving. This is especially jarring
18571857
// if they have format on save enabled.
1858-
tracing::info!("rustfmt exited with status 1, assuming parse error and ignoring");
1858+
tracing::warn!(
1859+
?command,
1860+
%captured_stderr,
1861+
"rustfmt exited with status 1"
1862+
);
18591863
Ok(None)
18601864
}
18611865
_ => {

0 commit comments

Comments
 (0)