2019-06-05 09:49:02 +03:00
#+TITLE : lang/rust
#+DATE : June 5, 2019
2019-11-23 16:12:06 -05:00
#+SINCE : v3.0.0
2019-06-05 09:49:02 +03:00
#+STARTUP : inlineimages
* Table of Contents :TOC_3:noexport:
- [[#description ][Description ]]
- [[#module-flags ][Module Flags ]]
- [[#plugins ][Plugins ]]
2019-06-05 09:59:44 +03:00
- [[#hacks ][Hacks ]]
2019-06-05 09:49:02 +03:00
- [[#prerequisites ][Prerequisites ]]
- [[#features ][Features ]]
2020-08-23 17:26:33 -04:00
- [[#lsp-support-rls-or-rust-analyzer ][LSP support (rls or rust-analyzer) ]]
- [[#format-on-save ][Format on save ]]
2019-11-23 16:12:06 -05:00
- [[#keybinds ][Keybinds ]]
2019-06-05 09:49:02 +03:00
- [[#configuration ][Configuration ]]
2020-08-23 17:26:33 -04:00
- [[#enable-rls-by-default ][Enable RLS by default ]]
2019-12-21 14:08:57 -05:00
- [[#enabling-elgot-support-for-rust ][Enabling elgot support for Rust ]]
2019-06-05 09:49:02 +03:00
- [[#troubleshooting ][Troubleshooting ]]
2020-10-04 15:27:29 -04:00
- [[#errore0670-async-fn-is-not-permitted-in-the-2015-edition][error[E0670]: `async fn` is not permitted in the 2015 edition]]
2019-06-05 09:49:02 +03:00
* Description
2019-11-23 16:12:06 -05:00
This module adds support for the Rust language and integration for its tools,
e.g. ~cargo~ .
2019-06-05 09:59:44 +03:00
2020-08-23 17:26:33 -04:00
+ Code completion (=racer= or an LSP server)
+ Syntax checking (=flycheck= )
+ LSP support (for rust-analyzer and rls) (=rustic= )
2019-06-05 09:59:44 +03:00
+ Snippets
2019-06-05 09:49:02 +03:00
** Module Flags
2020-08-23 17:26:33 -04:00
+ ~+lsp~ to add support Language server protocol. Will use the first of
=rust-analyzer= or =rls= (in that order).
2019-06-05 09:49:02 +03:00
** Plugins
2019-11-23 16:00:14 -05:00
+ [[https://github.com/brotzeit/rustic ][rustic ]]
+ [[https://github.com/racer-rust/emacs-racer ][racer ]]* (unless =+lsp= )
2019-06-05 09:59:44 +03:00
** Hacks
2019-11-23 16:12:06 -05:00
+ rustic has been modified /not/ to automatically install lsp-mode or elgot if
2020-08-23 17:26:33 -04:00
they're missing. Doom expects you to have enabled the =:tools lsp= module
yourself.
2017-11-02 20:00:43 +01:00
2019-06-05 09:49:02 +03:00
* Prerequisites
2020-08-23 17:26:33 -04:00
This module requires ~rust~ , which can be acquired through =rustup= :
2017-11-02 20:00:43 +01:00
~curl https://sh.rustup.rs -sSf | sh~
2020-08-23 17:26:33 -04:00
Additional requirements depend on the module's configuration:
2017-11-02 20:00:43 +01:00
2020-08-23 17:26:33 -04:00
+ 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=
+ To use The following commands require:
2019-09-26 13:41:05 -04:00
+ ~cargo-process-check~ : ~cargo install cargo-check~
2019-09-27 14:39:17 -04:00
+ ~cargo-process-clippy~ : ~rustup component add clippy-preview~
2019-07-04 21:13:21 +02:00
2019-06-05 09:49:02 +03:00
* Features
2020-08-23 17:26:33 -04:00
** LSP support (rls or rust-analyzer)
This module supports LSP integration. For it to work you'll need:
1. Either [[https://github.com/rust-analyzer/rust-analyzer ][rust-analyzer ]] or [[https://github.com/rust-lang/rls ][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 the [[file:../../../modules/editor/format/README.org ][:editor format ]] module's =+onsave= flag to get formatting on save with
rustfmt. No additional configuration is necessary.
2017-11-02 20:00:43 +01:00
2019-11-23 16:12:06 -05:00
** Keybinds
2019-07-04 21:33:13 +02:00
| Binding | Description |
|---------------------+-----------------------------|
2019-11-23 16:12:06 -05:00
| ~<localleader> b a~ | ~cargo audit~ |
2019-07-05 16:15:05 +02:00
| ~<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~ |
2019-11-23 16:12:06 -05:00
| ~<localleader> b n~ | ~cargo update~ |
| ~<localleader> b o~ | ~cargo outdated~ |
2019-07-05 16:15:05 +02:00
| ~<localleader> b r~ | ~cargo run~ |
2019-07-04 21:33:13 +02:00
| ~<localleader> t a~ | ~cargo test~ |
| ~<localleader> t t~ | ~run current test~ |
2017-11-02 20:00:43 +01:00
2019-06-05 09:49:02 +03:00
* TODO Configuration
2020-08-23 17:26:33 -04:00
** Enable RLS by default
If both =rls= and =rust-analyzer= are present on your system, =rust-analyzer= is
selected by default. Modify ~rustic-lsp-server~ to change the default:
2017-11-02 20:00:43 +01:00
2019-11-23 16:12:06 -05:00
#+BEGIN_SRC elisp
2019-12-21 14:08:57 -05:00
;; in $DOOMDIR/config.el
2020-08-23 17:26:33 -04:00
(after! rustic
(setq rustic-lsp-server 'rls))
2019-06-05 09:49:02 +03:00
#+END_SRC
2019-11-23 16:12:06 -05:00
2019-12-21 14:08:57 -05:00
** Enabling elgot support for Rust
2020-08-23 17:26:33 -04:00
Doom's =:tools lsp= module has an =+eglot= flag. Enable it and this module will
use eglot instead.
2019-12-21 14:08:57 -05:00
2020-10-04 15:27:29 -04:00
* Troubleshooting
** 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-on-save~ or =:editor
format= enabled).
To fix this your project needs a =rustfmt.toml= with ~edition = "2018"~ in it.