aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/handlers.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 23f323f55..78411f6c0 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -861,16 +861,18 @@ pub(crate) fn handle_formatting(
861 } 861 }
862 }; 862 };
863 863
864 let mut rustfmt = rustfmt.stdin(Stdio::piped()).stdout(Stdio::piped()).spawn()?; 864 let mut rustfmt =
865 rustfmt.stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped()).spawn()?;
865 866
866 rustfmt.stdin.as_mut().unwrap().write_all(file.as_bytes())?; 867 rustfmt.stdin.as_mut().unwrap().write_all(file.as_bytes())?;
867 868
868 let output = rustfmt.wait_with_output()?; 869 let output = rustfmt.wait_with_output()?;
869 let captured_stdout = String::from_utf8(output.stdout)?; 870 let captured_stdout = String::from_utf8(output.stdout)?;
871 let captured_stderr = String::from_utf8(output.stderr).unwrap_or_default();
870 872
871 if !output.status.success() { 873 if !output.status.success() {
872 match output.status.code() { 874 match output.status.code() {
873 Some(1) => { 875 Some(1) if !captured_stderr.contains("not installed") => {
874 // While `rustfmt` doesn't have a specific exit code for parse errors this is the 876 // While `rustfmt` doesn't have a specific exit code for parse errors this is the
875 // likely cause exiting with 1. Most Language Servers swallow parse errors on 877 // likely cause exiting with 1. Most Language Servers swallow parse errors on
876 // formatting because otherwise an error is surfaced to the user on top of the 878 // formatting because otherwise an error is surfaced to the user on top of the
@@ -886,8 +888,9 @@ pub(crate) fn handle_formatting(
886 format!( 888 format!(
887 r#"rustfmt exited with: 889 r#"rustfmt exited with:
888 Status: {} 890 Status: {}
889 stdout: {}"#, 891 stdout: {}
890 output.status, captured_stdout, 892 stderr: {}"#,
893 output.status, captured_stdout, captured_stderr,
891 ), 894 ),
892 ) 895 )
893 .into()); 896 .into());