rust-analyzer/crates
Ryan Cumming e052ca9d61 Swallow expected rustfmt errors
My workflow in Visual Studio Code + Rust Analyzer has become:

1. Make a change to Rust source code using all the analysis magic

2. Save the file to trigger `cargo watch`. I have format on save enabled
   for all file types so this also runs `rustfmt`

3. Fix any diagnostics that `cargo watch` finds

Unfortunately if the Rust source has any syntax errors the act of saving
will pop up a scary "command has failed" message and will switch to the
"Output" tab to show the `rustfmt` error and exit code.

I did a quick survey of what other Language Servers do in this case.
Both the JSON and TypeScript servers will swallow the error and return
success. This is consistent with how I remember my workflow in those
languages. The syntax error will show up as a diagnostic so it should
be clear why the file isn't formatting.

I checked the `rustfmt` source code and while it does distinguish "parse
errors" from "operational errors" internally they both result in exit
status of 1. However, more catastrophic errors (missing `rustfmt`,
SIGSEGV, etc) will return 127+ error codes which we can distinguish from
a normal failure.

This changes our handler to log an info message and feign success if
`rustfmt` exits with status 1.

Another option I considered was only swallowing the error if the
formatting request came from format-on-save. However, the Language
Server Protocol doesn't seem to distinguish those cases.
2019-06-27 08:08:26 +10:00
..
gen_lsp_server Bump cargo_metadata, ena, flexi_logger 2019-06-20 15:09:39 -04:00
ra_arena Add is_empty to Arena 2019-04-26 11:42:10 -04:00
ra_assists Review 1 2019-06-25 13:26:12 -07:00
ra_batch move ra_prof dep where it belongs 2019-06-26 13:07:26 +03:00
ra_cli move ra_prof dep where it belongs 2019-06-26 13:07:26 +03:00
ra_db Add SourceRoot::is_library, in preparation for salsa's durability 2019-06-24 12:35:07 +03:00
ra_fmt apply T! macro where it is possible 2019-05-15 15:35:47 +03:00
ra_hir make sure that CrateDefMap is independent from syntax 2019-06-26 21:50:42 +03:00
ra_ide_api make sure that CrateDefMap is independent from syntax 2019-06-26 21:50:42 +03:00
ra_lsp_server Swallow expected rustfmt errors 2019-06-27 08:08:26 +10:00
ra_mbe fix: clean up warnings 2019-06-06 10:06:46 +08:00
ra_parser Merge #1415 2019-06-24 10:10:05 +00:00
ra_prof add cpuprofile to ra_prof 2019-06-26 11:11:28 +03:00
ra_project_model Bump cargo_metadata, ena, flexi_logger 2019-06-20 15:09:39 -04:00
ra_syntax Merge #1415 2019-06-24 10:10:05 +00:00
ra_text_edit Fix clippy::match_ref_pats 2019-06-04 18:05:07 -04:00
ra_tools Update teraron version 2019-06-17 00:07:31 +06:00
ra_tt Fix clippy::needless_return 2019-06-04 18:05:07 -04:00
test_utils Fix clippy::expect_fun_call 2019-06-04 18:05:07 -04:00
thread_worker Fix clippy::single_match 2019-06-04 18:05:07 -04:00