doomemacs/modules/lang/rust
2020-08-23 17:27:32 -04:00
..
autoload.el lang/rust: replace cargo.el w/ rustic-cargo #2108 2019-11-23 16:00:30 -05:00
config.el Move :ui pretty-code to :ui ligatures 2020-08-20 02:14:32 -04:00
doctor.el Refactor lang/rust lsp check 2020-02-29 19:09:50 -05:00
packages.el Bump * 2020-08-19 16:18:11 -04:00
README.org lang/rust: update readme 2020-08-23 17:27:32 -04:00

lang/rust

Description

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

Module Flags

  • +lsp to add support Language server protocol. Will use the first of rust-analyzer or rls (in that order).

Plugins

Hacks

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

Prerequisites

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

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

Additional requirements depend on the module's configuration:

  • 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:

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

Features

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 the :editor format module's +onsave flag 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

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:

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

Enabling elgot support for Rust

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

TODO Troubleshooting