Rust language support - code completion, Intellisense, refactoring, reformatting, errors, snippets. A client for the Rust Language Server, built by the RLS team.
npm install coc-rls
It's fork of rls-vscode.
Adds language support for Rust to coc.nvim. 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
Rust support is powered by the Rust Language Server
(RLS). If you don't have it installed, the extension will install it for you.
For support, please file an issue on the repo
or talk to us on Gitter or in #rust-dev-tools
on IRC (Mozilla servers). There is also some
troubleshooting and debugging advice.
Note: multiple projects is not supported, you have to use different vim
instances.
- Install rustup (Rust toolchain manager).
- Install this extension in your vim by:
``vim`
:CocInstall coc-rls
- (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. 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.
NixOS users should use nix-shell or direnv for development. Follow these instructions to set them up first.
Then create two files:
1. An .envrc file containing use_nix.
2. And shell.nix containing:
``
let
moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
nixpkgs = import
#rustNightlyChannel = (nixpkgs.rustChannelOf { date = "2019-01-26"; channel = "nightly"; }).rust;
rustStableChannel = nixpkgs.latest.rustChannels.stable.rust.override {
extensions = [
"rust-src"
"rls-preview"
"clippy-preview"
"rustfmt-preview"
];
};
in
with nixpkgs;
stdenv.mkDerivation {
name = "moz_overlay_shell";
buildInputs = [
rustStableChannel
rls
rustup
];
}
Enter the shell in current directory and enjoy developing rust apps + coc.nvim + coc-rls :)
Tip: If you want to use nightly channel uncomment that line and use it :)
This extension provides some options into coc-settings.json. Theserust.
options have names which start with . Install coc-json
for auto completion support.
- "rust-client.logToFile":
When set to true, RLS stderr is logged to a file at workspace root level. Requires reloading extension after change., default: false
- "rust-client.setLibPath"
When set to false, environment variable DYLD_LIBRARY_PATH & LD_LIBRARY_PATH are kept for rls, default: true
- "rust-client.rustupPath":
Path to rustup executable. Ignored if rustup is disabled., default: "rustup"
- "rust-client.rlsPath":
Override RLS path. Only required for RLS developers. If you set this and use rustup, you should also set rust-client.channel to ensure your RLS sees the right libraries. If you don't use rustup, make sure to set rust-client.disableRustup., default: null
- "rust-client.revealOutputChannelOn":
Specifies message severity on which the output channel will be revealed. Requires reloading extension after change., default: "never"
Valid options: ["info","warn","error","never"]
- "rust-client.updateOnStartup":
Update the RLS whenever the extension starts up., default: false
- "rust-client.disableRustup":
Disable usage of rustup and use rustc/rls from PATH., default: false
- "rust-client.channel":
Rust channel to invoke rustup with. Ignored if rustup is disabled. By default, uses the same channel as your currently open project., default: null
Valid options: ["stable","beta","nightly"]
- "rust-client.trace.server":
Traces the communication between VS Code and the Rust language server., default: "off"
Valid options: ["off","messages","verbose"]
- "rust.sysroot":
--sysroot, default: null
- "rust.target":
--target, default: null
- "rust.rustflags":
Flags added to RUSTFLAGS., default: null
- "rust.clear_env_rust_log":
Clear the RUST_LOG environment variable before running rustc or cargo., default: true
- "rust.build_lib":
Specify to run analysis as if running cargo check --lib. Use null to auto-detect. (unstable), default: null
- "rust.build_bin":
Specify to run analysis as if running cargo check --bin . Use null to auto-detect. (unstable), default: null
- "rust.cfg_test":
Build cfg(test) code. (unstable), default: false
- "rust.unstable_features":
Enable unstable features., default: false
- "rust.wait_to_build":
Time in milliseconds between receiving a change notification and starting build., default: 1500
- "rust.show_warnings":
Show warnings., default: true
- "rust.crate_blacklist":
Overrides the default list of packages for which analysis is skipped.
Available since RLS 1.38, default: ["cocoa","gleam","glium","idna","libc","openssl","rustc_serialize","serde","serde_json","typenum","unicode_normalization","unicode_segmentation","winapi"]
- "rust.build_on_save":
Only index the project when a file is saved and not on change., default: false
- "rust.features":
A list of Cargo features to enable., default: []
- "rust.all_features":
Enable all Cargo features., default: false
- "rust.no_default_features":
Do not enable default Cargo features., default: false
- "rust.racer_completion":
Enables code completion using racer., default: true
- "rust.clippy_preference":
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."opt-in"
You need to install clippy via rustup if you haven't already., default:
Valid options: ["on","opt-in","off"]
- "rust.jobs":
Number of Cargo jobs to be run in parallel., default: null
- "rust.all_targets":
Checks the project as if you were running cargo check --all-targets (I.e., check all targets and integration tests too)., default: true
- "rust.target_dir":
When specified, it places the generated analysis files at the specified target directory. By default it is placed target/rls directory., default: null
- "rust.rustfmt_path":
When specified, RLS will use the Rustfmt pointed at the path instead of the bundled one, default: null
- "rust.build_command":
EXPERIMENTAL (requires 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., default: null
- "rust.full_docs":
Instructs cargo to enable full documentation extraction during save-analysis while building the crate., default: null
- "rust.show_hover_context":
Show additional context in hover tooltips when available. This is often the type local variable declaration., default: true
Snippets are code templates which expand into common boilerplate. Intellisense
includes snippet names as options when you type; select one by confirm the
completion.
You can move to the next 'hole' in the template by pressing '
We provide the following snippets:
- for - a for loopunimplemented
- unreachable
- println
- assert
- and assert_eqmacro_rules
- - declare a macroif let Option
- - an if let statement for executing code only in the Somespawn
case.
- - spawn a threadextern 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.
To enable formatting on save, open coc-settings.json by :CocConfig, then add"rust" to coc.preferences.formatOnSaveFiletypes field.
- Unless you have "rust-client.disableRustup": true, installrls-preview
Rustup required.
- A Rust toolchain (the extension will configure this for you, with
permission),
- RLS (currently ), rust-src, and rust-analysis` components (the
extension will install these for you, with permission).
This extension almost exclusively uses the RLS for its feature support (snippets
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.
MIT
[clippy]: https://github.com/rust-lang/rust-clippy