Use Clippy for Checking with Rust-analyzer, in Emacs with Eglot

2024-02-24
Forward links: id:Eglot related:Emacs under:Blog Backward links:

So according to Avery Larsen: Enable Clippy With rust-analyzer(Larsen 2023), setting "rust-analyzer.check.command": "clippy" in settings.json does the trick. I think this solution is related to VSCode's setting.

In our Emacs world, there is no such a file. However we have .dir-locals.el and Eglot neatly provides a project-specific configuration eglot-workspace-configuration, as showed in João Távora: Eglot Manual 5.1 Project-specific configuration(Távora 2022), for tweaking this settings.json-ish behavior.

Simply put the following in .dir-locals.el:

((nil
  . ((eglot-workspace-configuration
      . (:rust-analyzer (:check (:command "clippy")))))))

Side notes:

Reference

GNU. 2018. “33.31 Parsing and Generating Json Values.” 2018. https://www.gnu.org/software/emacs/manual/html_node/elisp/Parsing-JSON.html.
Larsen, Avery. 2023. “Enable Clippy with Rust-Analyzer.” January 3, 2023. https://averylarsen.com/posts/enable-clippy-with-rust-analyzer/.
Távora, João. 2022. “Eglot Manual.” 2022. https://joaotavora.github.io/eglot/.