aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorDaniel Silverstone <[email protected]>2020-12-31 09:03:34 +0000
committerDaniel Silverstone <[email protected]>2020-12-31 10:25:51 +0000
commit5ce420ac8487d991ead53f51ae2d45ef33d4f94e (patch)
tree8414439a6141133dd2eb68ffd94f0ede306870f3 /crates
parent558206f70e418730967fd690f5f219993de071bc (diff)
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 <[email protected]>
Diffstat (limited to 'crates')
-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());