rls-vscode

RLS-based plugin for VSCode

Github stars Tracking Chart

Rust support for Visual Studio Code


Build Status

Adds language support for Rust to Visual Studio Code. Supports:

  • code completion
  • jump to definition, peek definition, find all references, symbol search
  • types and documentation on hover
  • code formatting
  • refactoring (rename, deglob)
  • error squiggles and apply suggestions from errors
  • snippets
  • build tasks

Rust support is powered by the Rust Language Server
(RLS). If you don't have it installed, the extension will install it for you.

This extension is built and maintained by the RLS team, part of the Rust
IDEs and editors team.
It is the reference client implementation for the RLS. Our focus is on providing
a stable, high quality extension that makes best use of the RLS. 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. There is also some
troubleshooting and debugging
advice.

Contributing code, tests, documentation, and bug reports is appreciated! For
more details on building and debugging, etc., see contributing.md.

Quick start

  • Install rustup (Rust toolchain manager).
  • Install this extension from the VSCode Marketplace
    (or by entering ext install rust-lang.rust at the command palette Ctrl+P).
  • (Skip this step if you already have Rust projects that you'd like to work on.)
    Create a new Rust project by following these instructions.
  • Open a Rust project (File > Add Folder to Workspace...). Open the folder for the whole
    project (i.e., the folder containing 'Cargo.toml'), not the 'src' folder.
  • You'll be prompted to install the RLS. Once installed, the RLS should start
    building your project.

Configuration

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.

Some highlights:

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

Features

Snippets

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 'hole' in the template by pressing 'tab'. We provide
the following snippets:

  • for - a for loop
  • unimplemented
  • unreachable
  • print(ln)
  • assert(_eq)
  • macro_rules - declare a macro
  • if let Option - an if let statement for executing code only in the Some
    case.
  • spawn - spawn a thread
  • extern crate - insert an extern crate statement

This extension is deliberately conservative about snippets and doesn't include
too many. If you want more, check out
Trusty Rusty Snippets.

Tasks

The plugin provides tasks for building, running, and testing using the relevant
cargo commands. You can build using ctrl+shift+b. 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.

Format on save

To enable formatting on save, you need to set the editor.formatOnSave setting
to true. Find it under File > Preferences > Settings.

Requirements

  • Rustup,
  • A Rust toolchain (the extension will configure this for you, with
    permission),
  • rls, rust-src, and rust-analysis components (the
    extension will install these for you, with permission).

Implementation

This extension almost exclusively uses the RLS for its feature support (syntax
highlighting, snippets, and build tasks are provided client-side). The RLS uses
the Rust compiler (rustc) to get data about Rust programs. It uses Cargo to
manage building. Both Cargo and rustc are run in-process by the RLS. Formatting
and code completion are provided by rustfmt and Racer, again both of these are
run in-process by the RLS.

Main metrics

Overview
Name With Ownerrust-lang/vscode-rust
Primary LanguageTypeScript
Program languageTypeScript (Language Count: 3)
Platform
License:Other
所有者活动
Created At2016-09-02 22:57:33
Pushed At2022-11-15 17:22:45
Last Commit At2022-11-15 07:52:50
Release Count36
Last Release Namev0.7.8 (Posted on )
First Release Name0.2.0 (Posted on 2017-08-08 18:33:16)
用户参与
Stargazers Count1.4k
Watchers Count30
Fork Count161
Commits Count1.9k
Has Issues Enabled
Issues Count694
Issue Open Count294
Pull Requests Count199
Pull Requests Open Count8
Pull Requests Close Count67
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private