• Stars
    star
    378
  • Rank 110,237 (Top 3 %)
  • Language
    TypeScript
  • Created over 5 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rust language server support for coc.nvim

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 rust toolchain components.

    rustup component add rls rust-analysis rust-src
  • 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. Add "rust-client.disableRustup": true to coc-settings.json
  3. 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.enable":

    When set to true, enables this extension. Requires reloading extension after change., default: true

  • "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 <name>. 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. You need to install clippy via rustup if you haven't already., default: "opt-in"

    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

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

More Repositories

1

coc.nvim

Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
TypeScript
22,790
star
2

coc-tsserver

Tsserver extension for coc.nvim that provide rich features like VSCode for javascript & typescript
TypeScript
1,000
star
3

coc-snippets

Snippets solution for coc.nvim
TypeScript
924
star
4

coc-python

Python extension for coc.nvim, fork of vscode-python
TypeScript
576
star
5

coc-prettier

Prettier extension for coc.nvim.
TypeScript
512
star
6

coc-tabnine

Tabnine integration of coc.nvim
TypeScript
470
star
7

coc-java

Java extension for coc.nvim
TypeScript
407
star
8

coc-git

Git integration of coc.nvim
TypeScript
401
star
9

coc-eslint

Eslint extension for coc.nvim
TypeScript
378
star
10

vim-jsx-improve

Syntax and indent plugin for React jsx.
Vim Script
285
star
11

coc-pairs

Basic auto pairs extension of coc.nvim
TypeScript
283
star
12

coc-lists

Common lists for coc.nvim
TypeScript
259
star
13

coc-json

Json language extension for coc.nvim
TypeScript
229
star
14

coc-yaml

Yaml language server extension for coc.nvim
TypeScript
226
star
15

coc-vetur

Vue language server extension for coc.nvim
TypeScript
217
star
16

coc-highlight

Document highlight and document colors LSP support for coc.nvim
TypeScript
210
star
17

coc-sources

Additional common sources of coc.nvim
JavaScript
200
star
18

coc-html

Html language server extension for coc.nvim.
TypeScript
196
star
19

coc-css

Css language server extension for coc.nvim
TypeScript
189
star
20

coc-solargraph

Solargraph extension for coc.nvim
TypeScript
188
star
21

coc-yank

Yank highlight and persist yank history support for vim
TypeScript
188
star
22

coc-emmet

Emmet extension for coc.nvim
TypeScript
169
star
23

coc-vimtex

vimtex integration for coc.nvim
JavaScript
121
star
24

denite-git

Manger list of git objects with interface of denite.nvim
Python
73
star
25

coc-smartf

Make jump to character easier.
TypeScript
73
star
26

vim-node-rpc

Make vim behavior like neovim rpc server by use node server in the middle.
TypeScript
61
star
27

jsonc.vim

jsonc syntax support for vim
Vim Script
60
star
28

denite-extra

extra useful sources for denite.nvim
Python
55
star
29

coc-jest

Jest extension for coc.nvim
TypeScript
51
star
30

coc-tslint-plugin

coc.nvim extension that provides TSLint support using the typescript-tslint-plugin
TypeScript
49
star
31

coc-r-lsp

R LSP Client for coc.nvim
TypeScript
48
star
32

coc-stylelint

Stylelint language server extension for coc.nvim
JavaScript
42
star
33

vim-easygit

A git wrapper focus on simplity and usability
Vim Script
38
star
34

coc-imselect

Input method enhance for iTerm2 on mac.
TypeScript
37
star
35

coc-typos

Typos integration with coc.nvim
TypeScript
32
star
36

neovim

Node client API for both vim8 and neovim.
TypeScript
28
star
37

npm.nvim

Npm plugin to make vim user works with npm easier
Python
26
star
38

redismru.vim

MRU plugin build for speed with async IO operation
Vim Script
25
star
39

coc-neco

viml completion source for coc.nvim
Vim Script
23
star
40

coc-denite

Denite support of coc.nvim
Python
22
star
41

todoapp.vim

Todo management in vim using unite and sqlite
Vim Script
20
star
42

neoclide

Web enhanced IDE forked from Nyaovim
JavaScript
18
star
43

coc-tslint

Tslint language server extension of coc.nvim
TypeScript
17
star
44

rename.nvim

Rename plugin for neovim
TypeScript
16
star
45

plug.nvim

None block plugin manager for neovim
TypeScript
14
star
46

coc-repl

Read-Eval-Print-Loop (REPL) for coc.nvim
JavaScript
12
star
47

macnote.vim

Light weight note manager on mac using vim
Vim Script
11
star
48

macdown.vim

Live preview markdown in Chrome using applescript
JavaScript
11
star
49

wasm-fuzzy

Fuzzy match at native speed
C
10
star
50

mycomment.vim

one mapping for comment: <leader>c
Vim Script
10
star
51

coc-extension-codemod

Fix the code of coc.nvim extension.
JavaScript
10
star
52

coc-jedi

Deprecated, use https://github.com/neoclide/coc-python instead.
Python
10
star
53

coc-pyls

Deprecated, use https://github.com/neoclide/coc-python instead.
TypeScript
7
star
54

keep.nvim

Recover removed files made ease for neovim
JavaScript
5
star
55

neoclide-client

Embedding neovim as UI component with unified data flow
JavaScript
3
star
56

tern-neovim

Neovim tern plugin use remote plugin feature
Python
3
star
57

coc-wxml

wxml extension for coc.nvim
TypeScript
3
star
58

neovim-component

Editor component used for neoclide
JavaScript
2
star
59

electron-discuss

Discuss issues with electron
1
star