aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs35
1 files changed, 25 insertions, 10 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 6373240d5..47222cd0a 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -621,17 +621,32 @@ pub fn handle_formatting(
621 621
622 let output = rustfmt.wait_with_output()?; 622 let output = rustfmt.wait_with_output()?;
623 let captured_stdout = String::from_utf8(output.stdout)?; 623 let captured_stdout = String::from_utf8(output.stdout)?;
624
624 if !output.status.success() { 625 if !output.status.success() {
625 return Err(LspError::new( 626 match output.status.code() {
626 -32900, 627 Some(1) => {
627 format!( 628 // While `rustfmt` doesn't have a specific exit code for parse errors this is the
628 r#"rustfmt exited with: 629 // likely cause exiting with 1. Most Language Servers swallow parse errors on
629 Status: {} 630 // formatting because otherwise an error is surfaced to the user on top of the
630 stdout: {}"#, 631 // syntax error diagnostics they're already receiving. This is especially jarring
631 output.status, captured_stdout, 632 // if they have format on save enabled.
632 ), 633 log::info!("rustfmt exited with status 1, assuming parse error and ignoring");
633 ) 634 return Ok(None);
634 .into()); 635 }
636 _ => {
637 // Something else happened - e.g. `rustfmt` is missing or caught a signal
638 return Err(LspError::new(
639 -32900,
640 format!(
641 r#"rustfmt exited with:
642 Status: {}
643 stdout: {}"#,
644 output.status, captured_stdout,
645 ),
646 )
647 .into());
648 }
649 }
635 } 650 }
636 651
637 Ok(Some(vec![TextEdit { 652 Ok(Some(vec![TextEdit {