LoginSignup
14
9

More than 3 years have passed since last update.

VSCodeでgo toolsのコマンドがみつからない。

Last updated at Posted at 2019-09-23

事象

VSCodeでgo toolsのコマンドを実行すると、コマンドがみつからないと怒られる。

command 'go.test.cancel' not found

尚、ターミナルからは go envGOPATHGOROOTの設定が確認できていて、そこに必要なtoolsは存在している。

原因と解決

どうやら、VSCodeがGOPATHを正しく認識できていないようだった。
ターミナルからVSCodeを起動すると、GOPATHやGOROOTの環境情報を取得できるようなので、それで起動してみよう。

code .

ターミナルから起動すると下記のメッセージが出力されたのでインストール。
toolsの再コンパイルが必要だったようだ。

goroot (/Users/****/.goenv/versions/1.12.0) is different than before (/users/****/.goenv/versions/1.12.0), a few Go tools may need recompiling

必要なtoolsがGOPATH配下にインストール/更新され、再コンパイルされた。

Installing 17 tools at /Users/****/go/1.12.0/bin
  gocode
  gopkgs
  go-outline
  go-symbols
  guru
  gorename
  dlv
  gocode-gomod
  godef
  goreturns
  golint
  gopls
  gotests
  gomodifytags
  impl
  fillstruct
  goplay

Installing github.com/mdempsky/gocode SUCCEEDED
Installing github.com/uudashr/gopkgs/cmd/gopkgs SUCCEEDED
Installing github.com/ramya-rao-a/go-outline SUCCEEDED
Installing github.com/acroca/go-symbols SUCCEEDED
Installing golang.org/x/tools/cmd/guru SUCCEEDED
Installing golang.org/x/tools/cmd/gorename SUCCEEDED
Installing github.com/go-delve/delve/cmd/dlv SUCCEEDED
Installing github.com/stamblerre/gocode SUCCEEDED
Installing github.com/rogpeppe/godef SUCCEEDED
Installing github.com/sqs/goreturns SUCCEEDED
Installing golang.org/x/lint/golint SUCCEEDED
Installing golang.org/x/tools/cmd/gopls SUCCEEDED
Installing github.com/cweill/gotests/... SUCCEEDED
Installing github.com/fatih/gomodifytags SUCCEEDED
Installing github.com/josharian/impl SUCCEEDED
Installing github.com/davidrjenni/reftools/cmd/fillstruct SUCCEEDED
Installing github.com/haya14busa/goplay/cmd/goplay SUCCEEDED

Reload VS Code window to use the Go language server
All tools successfully installed. You're ready to Go :)

これで問題は解決した。

その後

goenvでgoのバージョンを切り替えてVSCodeを起動した際、必要な時は「toolsをインストール/更新してください」とメッセージが出てきた。
code . で起動しなくてもGOPATHやGOROOTの変更を読み込んでいるように見える…

VSCode側からtoolsのインストール/更新のお知らせがなかったが必要そうな場合、ターミナルからVSCodeを起動してみよう。

14
9
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
14
9