@@ -927,22 +927,22 @@ pub(crate) fn handle_formatting(
927
927
let captured_stderr = String :: from_utf8 ( output. stderr ) . unwrap_or_default ( ) ;
928
928
929
929
if !output. status . success ( ) {
930
- match output . status . code ( ) {
931
- Some ( 1 )
932
- if !captured_stderr . contains ( "not installed" )
933
- && !captured_stderr . contains ( "not available" ) =>
934
- {
930
+ let rustfmt_not_installed =
931
+ captured_stderr . contains ( "not installed" ) || captured_stderr . contains ( "not available" ) ;
932
+
933
+ return match output . status . code ( ) {
934
+ Some ( 1 ) if !rustfmt_not_installed => {
935
935
// While `rustfmt` doesn't have a specific exit code for parse errors this is the
936
936
// likely cause exiting with 1. Most Language Servers swallow parse errors on
937
937
// formatting because otherwise an error is surfaced to the user on top of the
938
938
// syntax error diagnostics they're already receiving. This is especially jarring
939
939
// if they have format on save enabled.
940
940
log:: info!( "rustfmt exited with status 1, assuming parse error and ignoring" ) ;
941
- return Ok ( None ) ;
941
+ Ok ( None )
942
942
}
943
943
_ => {
944
944
// Something else happened - e.g. `rustfmt` is missing or caught a signal
945
- return Err ( LspError :: new (
945
+ Err ( LspError :: new (
946
946
-32900 ,
947
947
format ! (
948
948
r#"rustfmt exited with:
@@ -952,9 +952,9 @@ pub(crate) fn handle_formatting(
952
952
output. status, captured_stdout, captured_stderr,
953
953
) ,
954
954
)
955
- . into ( ) ) ;
955
+ . into ( ) )
956
956
}
957
- }
957
+ } ;
958
958
}
959
959
960
960
let ( new_text, new_line_endings) = LineEndings :: normalize ( captured_stdout) ;
0 commit comments