Warning
This extension is no longer maintained.
This has been replaced by the rust-analyzer extension.
Adds language support for Rust to Visual Studio Code. Supports:
Rust support is powered by a separate language server - either by the official Rust Language Server (RLS) or rust-analyzer, depending on the user's preference. If you don't have it installed, the extension will install it for you (with permission).
This extension is built and maintained by the Rust IDEs and editors team. Our focus is on providing a stable, high quality extension that makes the best use of the respective language server. We aim to support as many features as possible, but our priority is supporting the essential features as well as possible.
For support, please file an issue on the repo or talk to us on Discord. For RLS, there is also some troubleshooting and debugging advice.
Contributing code, tests, documentation, and bug reports is appreciated! For more details see contributing.md.
ext install rust-lang.rust
at the command palette Ctrl+P).File > Add Folder to Workspace...
). Open the folder for the whole
project (i.e., the folder containing Cargo.toml
, not the src
folder).This extension provides options in VSCode's configuration settings. These
include rust.*
, which are passed directly to RLS, and the rust-client.*
, which mostly deal with how to spawn it or debug it.
You can find the settings under File > Preferences > Settings
; they all
have IntelliSense help.
Examples:
rust.show_warnings
- set to false to silence warnings in the editor.rust.all_targets
- build and index code for all targets (i.e., integration tests, examples, and benches)rust.cfg_test
- build and index test code (i.e., code with #[cfg(test)]
/#[test]
)rust-client.channel
- specifies from which toolchain the RLS should be spawnedTIP: To select the underlying language server, set
rust-client.engine
accordingly!
Snippets are code templates which expand into common boilerplate. IntelliSense includes snippet names as options when you type; select one by pressing enter. You can move to the next snippet 'hole' in the template by pressing tab. We provide the following snippets:
for
- a for loopmacro_rules
- declare a macroif let
- an if let
statement for executing code only when a pattern matchesspawn
- spawn a threadextern crate
- insert an extern crate
statementThis extension is deliberately conservative about snippets and doesn't include too many. If you want more, check out Trusty Rusty Snippets.
The plugin provides tasks for building, running, and testing using the relevant
cargo commands. You can build using ctrl+shift+b(Win/Linux), cmd+shift+b(macOS).
Access other tasks via Run Task
in the command palette.
The plugin writes these into tasks.json
. The plugin will not overwrite
existing tasks, so you can customise these tasks. To refresh back to the
defaults, delete tasks.json
and restart VSCode.
To enable formatting on save, you need to set the editor.formatOnSave
setting
to true
. Find it under File > Preferences > Settings
.
rls
, rust-src
, and rust-analysis
components (the extension will install
these for you, with permission). Only rust-src
is required when using
rust-analyzer.Both language servers can use Cargo to get more information about Rust projects
and both use rustfmt
extensively to
format the code.
RLS uses Cargo and also the Rust compiler
(rustc
) in a more direct fashion, where
it builds the project and reuses the data computed by the compiler itself. To
provide code completion it uses a separate tool called
racer
.
Rust Analyzer is a separate
compiler frontend for the Rust language that doesn't use the Rust compiler
(rustc
) directly but rather performs its
own analysis that's tailor-fitted to the editor/IDE use case.