Skip to content
Rust language server support for coc.nvim
TypeScript JavaScript
Branch: master
Clone or download
Latest commit 0c005a8 Jul 13, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
snippets add print to snippets May 7, 2019
src fix lint issue Jul 13, 2019
.gitignore init Oct 26, 2018
.npmignore use webpack Jun 19, 2019
Readme.md doc May 31, 2019
package.json Release 1.1.2 Jun 19, 2019
tsconfig.json use webpack Jun 19, 2019
tslint.json fix lint issue Jul 13, 2019
webpack.config.js use webpack Jun 19, 2019
yarn.lock use webpack Jun 19, 2019

Readme.md

Rust support for coc.nvim

NPM version

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.

Quick start

  • Install rustup (Rust toolchain manager).

  • Install this extension in your vim by:

    :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

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 <nixpkgs> { overlays = [ moz_overlay ]; };
  #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 :)

Configuration

This extension provides some options into coc-settings.json. These options have names which start with rust.. 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.
  • rust-client.rustupPath - Path to rustup executable, default rustup.
  • rust-client.rlsPath - Path to rls executable (only required for rls developers), default: null.
  • rust-client.revealOutputChannelOn - Specifies message severity on which the output channel will be revealed.
  • 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.
  • rust-client.channel - Rust channel to install RLS from. By default it will use the same channel as your currently open project rls-preview
  • 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.build_lib - if you have both a binary and library in your crate, set to true to build only the library.
  • rust.build_bin - if you have multiple binaries, you can specify which to build using this option.
  • rust.cfg_test - build and index test code (i.e., code with #[cfg(test)]/#[test])

Features

Snippets

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 '' (by default). We provide the following snippets:

  • for - a for loop
  • unimplemented
  • unreachable
  • println
  • assert and 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.

Format on save

To enable formatting on save, open coc-settings.json by :CocConfig, then add "rust" to coc.preferences.formatOnSaveFiletypes field.

Requirements

  • Unless you have "rust-client.disableRustup": true, install Rustup required.
  • A Rust toolchain (the extension will configure this for you, with permission),
  • RLS (currently rls-preview), 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 (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.

LICENSE

MIT

You can’t perform that action at this time.