Coc.nvimを触ってみようアドベントカレンダー 15日目 – coc-rls

とっても楽しいcoc.nvimを触ってみようというアドベントカレンダーです。15日目はcoc-rls。vimでRustを触りたい場合にはこの拡張を入れておけばとりあえず問題なしです。
2021.12.15

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

Coc.nvimを触ってみよう Advent Calendar 2021 15日目です。

今回は coc-rls です。

coc-rls について

Rustのコード補完、lintを行うcoc拡張です。vscode-rustのforkとなります。

coc-rls をインストールする

まずはrustupにて各種コンポーネントをインストールします。

% curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  /path/to/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory located at:

  /path/to/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo\'s bin directory, located at:

  /path/to/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /path/to/.profile
  /path/to/.zshenv

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: aarch64-apple-darwin
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>

info: profile set to 'default'
info: default host triple is aarch64-apple-darwin
warning: Updating existing toolchain, profile choice will be ignored
info: syncing channel updates for 'stable-aarch64-apple-darwin'
info: default toolchain set to 'stable-aarch64-apple-darwin'

  stable-aarch64-apple-darwin unchanged - rustc 1.57.0 (f1edd0429 2021-11-29)


Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo\'s bin directory ($HOME/.cargo/bin).

To configure your current shell, run:
source $HOME/.cargo/env
% exec $SHELL -l
% rustup component add rls rust-analysis rust-src
info: downloading component 'rls'
info: installing component 'rls'
info: downloading component 'rust-analysis'
info: installing component 'rust-analysis'
info: downloading component 'rust-src'
info: installing component 'rust-src'

vimを起動した状態で以下のコマンドを実行します。

:CocInstall coc-rls

使ってみる

適当なrsファイルを編集してみると動作していることが分かります。

幾つかsnippetsも入っていますが、より多くのパターンがほしい場合はTrusty Rusty Snippetsも使ってみましょう。

あとがき

Rustに入門する時には併せて入れておきたい拡張です。coc-settings.jsonに記述できるオプションは数多いため、必要に応じて設定してみましょう。