LoginSignup
3
4

More than 3 years have passed since last update.

WSLとVS Code+Rust+RLSの設定

Last updated at Posted at 2019-05-27

実践Rustを読んでいてもWindows10(RustをインストールしているのはWSL Ubuntuのみ)の場合にうまくRLSがインストールできなかったので,調べたら次のようにやったらとりあえず動きました.

  • WSLの方でコンポーネントをインストール
$ rustup component add rls rust-analysis rust-src
  • VS Codeのsetting.jsonに次を加筆
{
    "rust-client.useWSL": true,
    "rust-client.revealOutputChannelOn": "info",
    "rust-client.rustupPath": "~/.cargo/bin/rustup"
}

image.png

この状態でRLSが可動すれば変数の型やドキュメントが読めますが,VS CodeのCtrl+Shift+bからcargo buildcargo checkを動かすとwslがうまくコマンドを実行できずcommand not foundが返ってきたので,タスクを次のように修正しました.これはcargo buildのケースです.タスクを修正するには,コマンドパレットからcargo buildを出したときの右側にある歯車を選択すると編集できました(他の方法があるかも).

JSONに書いてあるとおり,wsl.exeを通じてcargoのコマンドを実行するようにしました.

{
    "tasks": [
        {
            "type": "shell",
            "label": "cargo build",
            "command": "wsl.exe",
            "args": [
                "~/.cargo/bin/cargo",
                "build"
            ],
            "problemMatcher": [
                "$rustc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

追記(2019/6/2)

  • VS Codeで編集していると出力のところにエラーがしばらく出ていた
  • とりあえずrustup component add rustfmtを実行したらエラーが出なくなった気がしたけど,関係はなかった
  • 調査中…
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4