赞
踩
工欲善其事,必先利其器
坑啊!我可以google,但就是无法使用vscode在安装时去下载"golang.org/x/tools"下的东西,全部都是这个报错,导致很多go插件提供的骚功能无法使用,也对不起vs这位宇宙第一ide的兄弟vscode,没办法只能开启手动下载安装模式。下面是vs自动安装的输出,有的成功有的失败,失败的原因都一样,成功的可以庆祝一下。
Installing 14 tools at F:\Softs\GoLang\repository gocode gopkgs go-outline go-symbols guru gorename gomodifytags goplay impl godef goreturns golint gotests dlv Installing github.com/nsf/gocode FAILED Installing github.com/uudashr/gopkgs/cmd/gopkgs SUCCEEDED Installing github.com/ramya-rao-a/go-outline FAILED Installing github.com/acroca/go-symbols FAILED Installing golang.org/x/tools/cmd/guru FAILED Installing golang.org/x/tools/cmd/gorename FAILED Installing github.com/fatih/gomodifytags FAILED Installing github.com/haya14busa/goplay/cmd/goplay SUCCEEDED Installing github.com/josharian/impl FAILED Installing github.com/rogpeppe/godef SUCCEEDED Installing sourcegraph.com/sqs/goreturns FAILED Installing github.com/golang/lint/golint FAILED Installing github.com/cweill/gotests/... FAILED Installing github.com/derekparker/delve/cmd/dlv SUCCEEDED
解决:
1、切换到 %GOPATH%/src/github.com目录下,我的%GOPATH%是 F:\Softs\GoLang\repository,如果 github.com目录下面没有golang请自行创建
2、完成目录切换后,开始下载插件包: git clone https://github.com/golang/tools.git tools
3、将下载的tools目录文件夹拷贝到%GOPATH%\src\golang.org\x\下,如果没有相关路径自行创建
4、我们将上面无法安装成功的包,手动安装,由于每个人可能安装成功的不一样,可以全部执行,将目录切换到%GOPATH%下执行下面代码
go install github.com/nsf/gocode
go install github.com/uudashr/gopkgs/cmd/gopkgs
go install github.com/ramya-rao-a/go-outline
go install github.com/acroca/go-symbols
go install golang.org/x/tools/cmd/guru
go install golang.org/x/tools/cmd/gorename
go install github.com/fatih/gomodifytags
go install github.com/haya14busa/goplay/cmd/goplay
go install github.com/josharian/impl
go install github.com/rogpeppe/godef
go install sourcegraph.com/sqs/goreturns
go install github.com/golang/lint/golint
go install github.com/cweill/gotests/...
go install github.com/derekparker/delve/cmd/dlv
在这里基本已经可以结束了,但是由于有些包在vscode自动安装的时候并没有下载成功,会出现
can’t load package: package github.com/josharian/impl: cannot find package “github.com/josharian/impl” in any of:
等类似错误,我们只需要在%GOPATH%/src/github.com目录下执行git clone https://github.com/josharian/impl
,就是提示哪个无法找到就执行就可以了,然后再切换到%GOPATH%目录下继续执行即可。
我目前使用的是go1.11版本,vscode版本是1.31.1,亲测没问题,有问题欢迎留言。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。