Skip to content

Rust#

Server#

For more information about the LSP server, check rls.

Installation#

For more instructions on how to install manually, check here.

Debugger: Yes#


root_file: docs/manual-language-docs/lsp-rust-rls.md#

RLS#

Customization#

This is an incomplete list of the available options

  • lsp-rust-rls-server-command change command to start RLS

  • lsp-rust-show-hover-context turn off hover tooltips

rustfmt#

Code formatting with rustfmt can be configured with:

lsp-rust-rustfmt-path change default path for rustfmt executable

To enable automatic code format on save, add this to your init.el (rust-mode is assumed to be installed):

(add-hook 'before-save-hook (lambda () (when (eq 'rust-mode major-mode)
                                           (lsp-format-buffer))))

Available configurations#

lsp-rust-server#

Type: (choice (const :tag rls rls) (const :tag rust-analyzer rust-analyzer))

Default: rust-analyzer

Choose LSP server.


lsp-rust-all-features#

Type: boolean

Default: nil

Enable all Cargo features.


lsp-rust-all-targets#

Type: boolean

Default: t

Checks the project as if you were running cargo check --all-targets. I.e., check all targets and integration tests too.


lsp-rust-build-bin#

Type: (choice (const :tag None nil) (string :tag Binary))

Default: nil

If non-nil, checks the project as if you passed -- bin <build_bin> argument to cargo.

Mutually exclusive with lsp-rust-build-lib. (Unstable)


lsp-rust-build-command#

Type: (choice (const :tag None nil) (string :tag Command))

Default: nil

EXPERIMENTAL (requires rust.unstable_features) If set, executes a given program responsible for rebuilding save-analysis to be loaded by the RLS. The program given should output a list of resulting .json files on stdout.

Implies rust.build_on_save: true.


lsp-rust-build-lib#

Type: boolean

Default: nil

If non-nil, checks the project as if you passed the --lib argument to cargo.

Mutually exclusive with, and preferred over, lsp-rust-build-bin. (Unstable)


lsp-rust-build-on-save#

Type: boolean

Default: nil

Only index the project when a file is saved and not on change.


lsp-rust-cfg-test#

Type: boolean

Default: nil

If non-nil, checks the project as if you were running cargo test rather than cargo build.

I.e., compiles (but does not run) test code.


lsp-rust-clear-env-rust-log#

Type: boolean

Default: t

Clear the RUST_LOG environment variable before running rustc or cargo.


lsp-rust-clippy-preference#

Type: (choice (const on) (const opt-in) (const off))

Default: opt-in

Controls eagerness of clippy diagnostics when available. Valid values are (case-insensitive): - "off": Disable clippy lints. - "opt-in": Clippy lints are shown when crates specify #![warn(clippy)]. - "on": Clippy lints enabled for all crates in workspace.

You need to install clippy via rustup if you haven`t already.


lsp-rust-crate-blocklist#

Type: lsp-string-vector

Default: [cocoa gleam glium idna libc openssl rustc_serialize serde serde_json typenum unicode_normalization unicode_segmentation winapi]

A list of Cargo crates to blocklist.


lsp-rust-features#

Type: lsp-string-vector

Default: []

List of features to activate. Corresponds to the rust-analyzer setting rust-analyzer.cargo.features. Set this to "all" to pass --all-features to cargo.


lsp-rust-full-docs#

Type: boolean

Default: nil

Instructs cargo to enable full documentation extraction during save-analysis while building the crate.


lsp-rust-jobs#

Type: (choice (const :tag Auto nil) (number :tag Jobs))

Default: nil

Number of Cargo jobs to be run in parallel.


lsp-rust-library-directories#

Type: (repeat string)

Default: (~/.cargo/registry/src ~/.rustup/toolchains)

List of directories which will be considered to be libraries.


lsp-rust-no-default-features#

Type: boolean

Default: nil

Do not enable default Cargo features.


lsp-rust-racer-completion#

Type: boolean

Default: t

Enables code completion using racer.


lsp-rust-rls-server-command#

Type: (repeat string)

Default: (rls)

Command to start RLS.


lsp-rust-rustflags#

Type: (choice (const :tag None nil) (string :tag Flags))

Default: nil

Flags added to RUSTFLAGS.


lsp-rust-rustfmt-path#

Type: (choice (const :tag Bundled nil) (string :tag Path))

Default: nil

When specified, RLS will use the Rustfmt pointed at the path instead of the bundled one


lsp-rust-show-hover-context#

Type: boolean

Default: t

Show additional context in hover tooltips when available. This is often the type local variable declaration.


lsp-rust-show-warnings#

Type: boolean

Default: t

Show warnings.


lsp-rust-sysroot#

Type: (choice (const :tag None nil) (string :tag Sysroot))

Default: nil

If non-nil, use the given path as the sysroot for all rustc invocations instead of trying to detect the sysroot automatically.


lsp-rust-target#

Type: (choice (const :tag None nil) (string :tag Target))

Default: nil

If non-nil, use the given target triple for all rustc invocations.


lsp-rust-target-dir#

Type: (choice (const :tag Default nil) (string :tag Directory))

Default: nil

When specified, it places the generated analysis files at the specified target directory. By default it is placed target/rls directory.


lsp-rust-unstable-features#

Type: boolean

Default: nil

Enable unstable features.


lsp-rust-wait-to-build#

Type: (choice (const :tag Auto nil) (number :tag Time))

Default: nil

Time in milliseconds between receiving a change notification and starting build. If not specified, automatically inferred by the latest build duration.



Last update: November 19, 2024