doomemacs/modules/lang/rust
Henrik Lissner 1abcf913aa
revert: fix(docs): set mode in file-local vars
emacs-straight/org-mode@e22b4eb7aa introduced a breaking change that
made it impossible to rely on .dir-locals.el to change org-mode buffers
in $EMACSDIR to doom-docs-org-mode (without infinite recursion), so we
used file-local variables in 7e400ab.

emacs-straight/org-mode@215de6176b reverted that change, so we can use
.dir-locals.el again, and this is my preference, since it requires less
boilerplate across our hundreds of org files.

Ref: emacs-straight/org-mode@215de6176b
Ref: emacs-straight/org-mode@e22b4eb7aa
Revert: 7e400abdc0
2022-08-07 19:08:07 +02:00
..
autoload.el Bump :lang rust 2021-05-03 00:17:16 -04:00
config.el fix(rust): enable rainbow-delimiters-mode in rustic-mode 2022-08-02 20:39:18 +02:00
doctor.el docs(tree-sitter): add doctor checks for flag 2022-05-22 21:26:00 +01:00
packages.el bump: :lang 2022-03-31 21:09:38 +02:00
README.org revert: fix(docs): set mode in file-local vars 2022-08-07 19:08:07 +02:00

:lang rust

Description   unfold

This module adds support for the Rust language and integration for its tools, e.g. cargo.

  • Code completion (racer or an LSP server)
  • Syntax checking (flycheck)
  • LSP support (for rust-analyzer and rls) (rustic)
  • Snippets

Maintainers

Module flags

+lsp
Enable LSP support for rustic-mode. Requires :tools lsp and a langserver (supports rust-analyzer and rls).

Packages

Hacks

  • rustic has been modified not to automatically install lsp-mode or eglot if they're missing. Doom expects you to have enabled the :tools lsp module yourself.

TODO Changelog

This module does not have a changelog yet.

Installation

Enable this module in your doom! block.

This module requires rust, which can be acquired through rustup:

curl https://sh.rustup.rs -sSf | sh

Note that when the Rust language has updates, you are to run rustup such that it doesn't upgrade itself:

rustup update --no-self-update

Other Requirements

  • If :editor format is enabled, you'll need rustfmt: $ rustup component add rustfmt-preview.
  • Users without +lsp enabled will need racer: $ cargo +nightly install racer (with requires rust nightly edition).
  • Users with +lsp enabled will need:

    • rust-analyzer or rls
  • Using the following commands requires:

    • cargo-process-check: $ cargo install cargo-check
    • cargo-process-clippy: $ rustup component add clippy-preview

TODO Usage

🔨 This module's usage documentation is incomplete. Complete it?

LSP support (rls or rust-analyzer)

This module supports LSP integration. For it to work you'll need:

  1. Either rust-analyzer or the Rust Language Server installed (e.g. through your OS package manager).
  2. The :tools lsp module enabled.
  3. The +lsp flag on this module enabled.

Format on save

Enable :editor format +onsave to get formatting on save with rustfmt. No additional configuration is necessary.

Keybinds

Binding Description
<localleader> b a cargo audit
<localleader> b b cargo build
<localleader> b B cargo bench
<localleader> b c cargo check
<localleader> b C cargo clippy
<localleader> b d cargo doc
<localleader> b n cargo update
<localleader> b o cargo outdated
<localleader> b r cargo run
<localleader> t a cargo test
<localleader> t t run current test

TODO Configuration

🔨 This module's configuration documentation is incomplete. Complete it?

Enable RLS by default

If both rls and rust-analyzer are present on your system, rust-analyzer is used by default. Modify rustic-lsp-server to change the default:

;; in $DOOMDIR/config.el
(after! rustic
  (setq rustic-lsp-server 'rls))

Enabling eglot support for Rust

Doom's :tools lsp module has an +eglot flag. Enable it and this module will use eglot instead.

Troubleshooting

Report an issue?

error[E0670]: `async fn` is not permitted in the 2015 edition

You may be seeing this error, despite having edition = "2018" in your Cargo.toml. This error actually originates from rustfmt, which the LSP server tries to invoke on save (if you have rustic-format-trigger or :editor format enabled).

To fix this your project needs a rustfmt.toml with edition = "2018" in it.

Frequently asked questions

This module has no FAQs yet. Ask one?

TODO Appendix

🔨 This module has no appendix yet. Write one?