From 5ce420ac8487d991ead53f51ae2d45ef33d4f94e Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Thu, 31 Dec 2020 09:03:34 +0000 Subject: handle_formatting: Notice if rustfmt is missing and report In an attempt to fix #6052 and #4249 this attempts to detect if rustfmt is a rustup proxy which isn't installed, and reports the error message to the user for them to fix. In theory this ought to be memoised but for now it'll do as-is. Future work might be to ask the user if they would like us to trigger the installation (if possible). Signed-off-by: Daniel Silverstone --- crates/rust-analyzer/src/handlers.rs | 11 +++++++---- 1 file 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( } }; - let mut rustfmt = rustfmt.stdin(Stdio::piped()).stdout(Stdio::piped()).spawn()?; + let mut rustfmt = + rustfmt.stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped()).spawn()?; rustfmt.stdin.as_mut().unwrap().write_all(file.as_bytes())?; let output = rustfmt.wait_with_output()?; let captured_stdout = String::from_utf8(output.stdout)?; + let captured_stderr = String::from_utf8(output.stderr).unwrap_or_default(); if !output.status.success() { match output.status.code() { - Some(1) => { + Some(1) if !captured_stderr.contains("not installed") => { // While `rustfmt` doesn't have a specific exit code for parse errors this is the // likely cause exiting with 1. Most Language Servers swallow parse errors on // formatting because otherwise an error is surfaced to the user on top of the @@ -886,8 +888,9 @@ pub(crate) fn handle_formatting( format!( r#"rustfmt exited with: Status: {} - stdout: {}"#, - output.status, captured_stdout, + stdout: {} + stderr: {}"#, + output.status, captured_stdout, captured_stderr, ), ) .into()); -- cgit v1.2.3