vscode go 插件安装
问题
vscode 自动安装golang的插件由于网络原因无法安装。安装不成功的插件一共有两种来源,一种是来自github,一种是来自golang.org/x/下面的。可以按照以下方式,手工下载代码,逐个安装
第一步 找到缺失插件
将vscode 安装失败的输出拷贝出来,里面包含了所需的插件名称,及插件的url ,大致如下:
Tools environment: GOPATH=D:\code\golang
Installing 17 tools at D:\code\golang\bin in module mode.
gocode
gopkgs
go-outline
go-symbols
guru
gorename
gotests
gomodifytags
impl
fillstruct
goplay
godoctor
dlv
gocode-gomod
godef
goreturns
golint
Installing github.com/mdempsky/gocode FAILED
Installing github.com/uudashr/gopkgs/v2/cmd/gopkgs FAILED
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/cweill/gotests/... FAILED
Installing github.com/fatih/gomodifytags FAILED
Installing github.com/josharian/impl FAILED
Installing github.com/davidrjenni/reftools/cmd/fillstruct FAILED
Installing github.com/haya14busa/goplay/cmd/goplay FAILED
Installing github.com/godoctor/godoctor FAILED
Installing github.com/go-delve/delve/cmd/dlv FAILED
Installing github.com/stamblerre/gocode FAILED
Installing github.com/rogpeppe/godef FAILED
Installing github.com/sqs/goreturns FAILED
Installing golang.org/x/lint/golint FAILED
17 tools failed to install.
第二步 下载源码并安装
基本流程
- github 里查找到插件的源码仓库
- 在GOPATH 里创建相关目录
- git clone 下载源码到相应目录,若是有多个分支时,clone 里选择合适的branch
- 切换到GOPATH 里, 安装模块: go install XXX
- 安装过程中,若是缺少其他模块,重复1~4 的步骤
插件安装举例
1、golang.org/x/tools/
1) 在https://github.com/golang 里搜索tools
2) 创建目录 $GOPATH/src/golang.org/x/
3) git clone -b release-branch.go1.15 https://github.com/golang/tools.git
4) tools 里包含多个模块:
go install golang.org/x/tools/cmd/guru
go install golang.org/x/tools/cmd/gorename
2、github.com/cweill/gotests/
1) 在github 里找到仓库路径:
https://github.com/cweill/gotests.git
2)创建目录,并下载
D:\code\golang\src\github.com>mkdir cweill
D:\code\golang\src\github.com>cd cweill
D:\code\golang\src\github.com\cweill>git clone https://github.com/cweill/gotests.git
3)安装模块
D:\code\golang>go install github.com/cweill/gotests/