The RLS provides a server that runs in the background, providing IDEs, editors, and other tools with information about Rust programs. It supports functionality such as 'goto definition', symbol search, reformatting, and code completion, and enables renaming and refactorings.
The RLS gets its source data from the compiler and from Racer. Where possible it uses data from the compiler which is precise and complete. Where its not possible, (for example for code completion and where building is too slow), it uses Racer.
Since the Rust compiler does not yet support end-to-end incremental compilation, we can't offer a perfect experience. However, by optimising our use of the compiler and falling back to Racer, we can offer a pretty good experience for small to medium sized crates. As the RLS and compiler evolve, we'll offer a better experience for larger and larger crates.
The RLS is designed to be frontend-independent. We hope it will be widely adopted by different editors and IDEs. To seed development, we provide a reference implementation of an RLS frontend for Visual Studio Code.
You can install rustup on many platforms. This will help us quickly install the rls and its dependencies.
If you already have rustup installed, update to ensure you have the latest rustup and compiler:
rustup update
If you're going to use the VSCode extension, you can skip step 2.
Once you have rustup installed, run the following commands:
rustup component add rls-preview rust-analysis rust-src
Sometimes the rls-preview
component is not included in a nightly build due to
certain issues. To see if the component is included in a particular build and
what to do if it's not, check #641.
The RLS is built to work with many IDEs and editors, we mostly use VSCode to test the RLS. The easiest way is to use the published extension.
You'll know it's working when you see this in the status bar at the bottom, with a spinning indicator:
RLS: working ◐
Once you see:
RLS
Then you have the full set of capabilities available to you. You can goto def, find all refs, rename, goto type, etc. Completions are also available using the heuristics that Racer provides. As you type, your code will be checked and error squiggles will be reported when errors occur. You can hover these squiggles to see the text of the error.
The RLS can be configured on a per-project basis, using the Visual
Studio Code extension this will be done via the workspace settings file
settings.json
.
Other editors will have their own way of sending the workspace/DidChangeConfiguration method.
Entries in this file will affect how the RLS operates and how it builds your project.
Currently we accept the following options:
build_lib
(bool
, defaults tofalse
) checks the project as if you passed the--lib
argument to cargo. Mutually exclusive with, and preferred overbuild_bin
.build_bin
(String
, defaults to""
) checks the project as if you passed-- bin <build_bin>
argument to cargo. Mutually exclusive withbuild_lib
.cfg_test
(bool
, defaults tofalse
) checks the project as if you were runningcargo test
rather thancargo build
. I.e., compiles (but does not run) test code.unstable_features
(bool
, defaults tofalse
) enables unstable features. Currently no option requires this flag.sysroot
(String
, defaults to""
) if the given string is not empty, use the given path as the sysroot for all rustc invocations instead of trying to detect the sysroot automaticallytarget
(String
, defaults to""
) if the given string is not empty, use the given target triple for all rustc invocationswait_to_build
(u64
, defaults to500
) time in milliseconds between receiving a change notification and starting buildworkspace_mode
(bool
, defaults totrue
) When turned on, RLS will try to scan current workspace and analyze every package in it.analyze_package
(String
, defaults to""
) Whenworkspace_mode
is enabled, analysis will be only provided for the specified package (runs as if-p <analyze_package>
was passed).all_targets
(bool
, defaults tofalse
) checks the project as if you were runningcargo check --all-targets
. I.e., check all targets and integration tests too.racer_completion
(bool
, defaults totrue
) enables/disables code completion using racer.
For tips on debugging and troubleshooting, see debugging.md.
You can look in the contributing.md in this repo to learn more about contributing to this project.
If you want to implement RLS support in an editor, see clients.md.