golang 插件gopls, dlv 升级

2024-01-15  本文已影响0人  東玖零

背景:有一个工程要求golang的版本号为1.7以上才可以运行,于是我就从1.6升级到1.7。

使用berw相关命令安装了1.7.13的环境,修改一下环境变量指定到1.7.3的目录下。

本地代码调试是成功的,但vscode会给出以下提示:

Tools (gopls, dlv) need recompiling to work with go version go1.17.13 darwin/amd64

当我们点击提示上的升级按钮就报错了,报错如下:

Tools environment: GOPATH=/Users/adong/go, GOBIN=/Users/adong/go/bin
Installing 1 tool at the configured GOBIN: /Users/adong/go/bin
  gopls

Installing golang.org/x/tools/gopls@latest FAILED
{
 "code": 1,
 "killed": false,
 "signal": null,
 "cmd": "/usr/local/Cellar/go@1.17/1.17.13/libexec/bin/go install -v golang.org/x/tools/gopls@latest",
 "stdout": "",
 "stderr": "package golang.org/x/tools/gopls\n\timports golang.org/x/tools/gopls/internal/lsp/cmd\n\timports golang.org/x/tools/gopls/internal/vulncheck/scan: build constraints exclude all Go files in /Users/adong/go/pkg/mod/golang.org/x/tools/gopls@v0.14.2/internal/vulncheck/scan\n"
}

1 tools failed to install.

gopls: failed to install gopls(golang.org/x/tools/gopls@latest): Error: Command failed: /usr/local/Cellar/go@1.17/1.17.13/libexec/bin/go install -v golang.org/x/tools/gopls@latest
package golang.org/x/tools/gopls
    imports golang.org/x/tools/gopls/internal/lsp/cmd
    imports golang.org/x/tools/gopls/internal/vulncheck/scan: build constraints exclude all Go files in /Users/adong/go/pkg/mod/golang.org/x/tools/gopls@v0.14.2/internal/vulncheck/scan

每次打开都提示升级,每次点升级又报错,网上找到了解决方法。

$ git clone https://github.com/go-delve/delve
$ cd delve
$ git tag // 找到自己对应的版本,我是1.7.3
$ git checkout v1.7.3
$ go install github.com/go-delve/delve/cmd/dlv

上述命令一行一行执行,执行完成dlv就升级完成了。

我想gopls升级也是类似方法,搬个砖记录一下。

后记:发现了更简单的方法,google一下gopls https://github.com/golang/tools/tree/master/gopls,直接找到github上的golang/tools项目,gopls页面说明:

Go Version Final gopls version with support (without warnings)
Go 1.12 gopls@v0.7.5
Go 1.15 gopls@v0.9.5
Go 1.17 gopls@v0.11.0
Go 1.18 gopls@v0.14.2

我当前使用的go版本是1.17,那么gopls的版本是v0.11.0,直接使用

go install -v golang.org/x/tools/gopls@v0.11.0  

我想dlv也可以用相似原理吧。

上一篇下一篇

猜你喜欢

热点阅读