Skip to content

Latest commit

 

History

History
139 lines (111 loc) · 4.69 KB

README.org

File metadata and controls

139 lines (111 loc) · 4.69 KB

lang/rust

Table of Contents

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 eglot if they’re missing. Doom expects you to have enabled the :tools lsp module yourself.

Prerequisites

Install

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

Arch Linux

sudo pacman -S rustup

See also the Rust article on the Arch Wiki.

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

General

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

Other Requirements

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
  • Using the following commands requires:
    • 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

BindingDescription
<localleader> b acargo audit
<localleader> b bcargo build
<localleader> b Bcargo bench
<localleader> b ccargo check
<localleader> b Ccargo clippy
<localleader> b dcargo doc
<localleader> b ncargo update
<localleader> b ocargo outdated
<localleader> b rcargo run
<localleader> t acargo test
<localleader> t trun current test

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 eglot support for Rust

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

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.