2022-03-28 15:03:21 +02:00
#+title : :lang rust
#+subtitle : Fe2O3.unwrap().unwrap().unwrap().unwrap()
#+created : September 30, 2015
#+since : 0.7
2021-10-16 01:28:32 +02:00
* Description :unfold:
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
2022-09-26 02:19:42 +08:00
- Code completion ([[doom-package:racer ]] or an LSP server)
- Syntax checking ([[doom-package:flycheck ]])
- LSP support (for rust-analyzer and rls) ([[doom-package:rustic ]])
2021-10-16 01:28:32 +02:00
- Snippets
2019-06-05 09:49:02 +03:00
2021-10-16 01:28:32 +02:00
** Maintainers
- @hlissner
2019-06-05 09:49:02 +03:00
2021-10-16 01:28:32 +02:00
[[doom-contrib-maintainer: ][Become a maintainer? ]]
2019-06-05 09:59:44 +03:00
2021-10-16 01:28:32 +02:00
** Module flags
- +lsp ::
2022-09-26 02:19:42 +08:00
Enable LSP support for ~rustic-mode~ . Requires [[doom-module::tools lsp ]] and a langserver
2022-09-07 01:21:44 +02:00
(supports [[https://rust-analyzer.github.io/ ][rust-analyzer ]] and rls).
2023-01-03 20:53:18 +01:00
- +tree-sitter ::
Leverages tree-sitter for better syntax highlighting and structural text
editing. Requires [[doom-module::tools tree-sitter ]].
2017-11-02 20:00:43 +01:00
2021-10-16 01:28:32 +02:00
** Packages
2022-09-26 02:19:42 +08:00
- [[doom-package:rustic ]]
2017-11-02 20:00:43 +01:00
2021-10-16 01:28:32 +02:00
** Hacks
- rustic has been modified /not/ to automatically install lsp-mode or eglot if
2022-09-26 02:19:42 +08:00
they're missing. Doom expects you to have enabled the [[doom-module::tools lsp ]] module
2021-10-16 01:28:32 +02:00
yourself.
2021-05-17 07:24:55 -07:00
2021-10-16 01:28:32 +02:00
** TODO Changelog
# This section will be machine generated. Don't edit it by hand.
/This module does not have a changelog yet./
2021-05-17 07:24:55 -07:00
2021-10-16 01:28:32 +02:00
* Installation
[[id:01cffea4-3329-45e2-a892-95a384ab2338 ][Enable this module in your ~doom!~ block. ]]
2021-05-17 07:24:55 -07:00
2021-10-16 01:28:32 +02:00
This module requires ~rust~ , which can be acquired through =rustup= :
2021-05-17 07:24:55 -07:00
#+begin_src sh
2021-10-16 01:28:32 +02:00
curl https://sh.rustup.rs -sSf | sh
2021-05-17 07:24:55 -07:00
#+end_src
2021-10-16 01:28:32 +02:00
Note that when the Rust /language/ has updates, you are to run =rustup= such
that it doesn't upgrade itself:
2021-05-17 07:24:55 -07:00
#+begin_src sh
rustup update --no-self-update
#+end_src
** Other Requirements
2022-09-26 02:19:42 +08:00
- If [[doom-module::editor format ]] is enabled, you'll need =rustfmt= : ~$ rustup component add
2020-08-23 17:26:33 -04:00
rustfmt-preview~.
2022-09-26 02:19:42 +08:00
- Users with [[doom-module:+lsp ]] enabled will need [[https://rust-analyzer.github.io/ ][rust-analyzer ]] (rls is supported, but
2022-09-07 01:17:29 +02:00
[[https://blog.rust-lang.org/2022/07/01/RLS-deprecation.html ][deprecated ]]).
2021-10-16 01:28:32 +02:00
- Using the following commands requires:
- ~cargo-process-check~ : ~$ cargo install cargo-check~
- ~cargo-process-clippy~ : ~$ rustup component add clippy-preview~
* TODO Usage
#+begin_quote
🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module: ][Complete it? ]]
#+end_quote
2019-07-04 21:13:21 +02:00
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:
2022-09-07 01:21:44 +02:00
1. To install [[https://github.com/rust-analyzer/rust-analyzer ][rust-analyzer ]] through your OS package manager ([[https://github.com/rust-lang/rls ][RLS ]] is supported
too, but it is [[https://blog.rust-lang.org/2022/07/01/RLS-deprecation.html ][deprecated ]]).
2022-09-26 02:19:42 +08:00
2. To enable the [[doom-module::tools lsp ]] module.
3. To enable the [[doom-module:+lsp ]] flag on this module.
2020-08-23 17:26:33 -04:00
** Format on save
2022-09-26 02:19:42 +08:00
Enable [[doom-module::editor format +onsave ]] to get formatting on save with =rustfmt= . No
2021-10-16 01:28:32 +02:00
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 |
|---------------------+-----------------------------|
2021-10-16 01:28:32 +02:00
| =<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~ |
2017-11-02 20:00:43 +01:00
2019-06-05 09:49:02 +03:00
* TODO Configuration
2021-10-16 01:28:32 +02:00
#+begin_quote
🔨 /This module's configuration documentation is incomplete./ [[doom-contrib-module: ][Complete it? ]]
#+end_quote
2021-02-04 05:02:55 +01:00
** Enabling eglot support for Rust
2022-09-26 02:19:42 +08:00
Doom's [[doom-module::tools lsp ]] module has an [[doom-module:+eglot ]] flag. Enable it and this module will use
2021-10-16 01:28:32 +02:00
eglot instead.
2019-12-21 14:08:57 -05:00
2020-10-04 15:27:29 -04:00
* Troubleshooting
2021-10-16 01:28:32 +02:00
[[doom-report: ][Report an issue? ]]
2020-10-04 15:27:29 -04:00
** 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
2022-09-26 02:19:42 +08:00
server tries to invoke on save (if you have ~rustic-format-trigger~ or [[doom-module::editor
2021-11-20 18:35:19 +01:00
format]] enabled).
2020-10-04 15:27:29 -04:00
To fix this your project needs a =rustfmt.toml= with ~edition = "2018"~ in it.
2021-10-16 01:28:32 +02:00
* Frequently asked questions
/This module has no FAQs yet./ [[doom-suggest-faq: ][Ask one? ]]
* TODO Appendix
#+begin_quote
🔨 This module has no appendix yet. [[doom-contrib-module: ][Write one? ]]
#+end_quote