怎么配置使用Go语言IDE中的VSCode

发布时间:2020-07-28 09:59:28 作者:小猪
来源:亿速云 阅读:127

这篇文章主要讲解了怎么配置使用Go语言IDE中的VSCode,内容清晰明了,对此有兴趣的小伙伴可以学习一下,相信大家阅读完之后会有帮助。

一、Golang 环境配置

关于 Goland 的系统环境配置,这里就不在过多讲解,可以直接参考该链接的前半部分即可。

二、安装配置 VSCode

下载链接:https://code.visualstudio.com/

选择自己系统对应的版本就可以,这个做 IT 的都不知道那就转行吧。

2.1 安装 golang 插件

进入Visual Studio Code,使用快捷键F1,打开命令面板

怎么配置使用Go语言IDE中的VSCode

在上图光标处·输入 exten ,然后选择“Extensions:Install Extension”,如下图

怎么配置使用Go语言IDE中的VSCode

查询并安装 Go 插件

怎么配置使用Go语言IDE中的VSCode

提示:在插件列表中,选择 Go,进行安装,安装之后,系统会提示重启Visual Studio Code。由于我这里已经安装过了,所以不会出现 "Install" 选项。

2.2 开启自动保存功能

打开Visual Studio Code,找到菜单File -> Preferences -> Settings,如下图:

怎么配置使用Go语言IDE中的VSCode

选中 "User Settings" 配置如下内容

怎么配置使用Go语言IDE中的VSCode

{
 "files.autoSave": "onFocusChange",
 "editor.fontSize": 18,
 "go.goroot": "D:\\Go",
 "go.gopath": "D:\\Golang\\MyGO"
}

其他保持默认配置即可;

2.3 执行相关命令(自行安装好git)

更多详细信息参考:https://marketplace.visualstudio.com/items?itemName=ms-vscode.Go

1)安装gocode

打开命令提示符(以管理员身份打开),输入:

go get -u -v github.com/nsf/gocode

2)安装godef

go get -u -v github.com/rogpeppe/godef

3)安装golint

# 创建 $GOPATH/src/golang.org/x
cd $GOPATH/src/golang.org/x
git clone https://github.com/golang/tools.git
git clone https://github.com/golang/lint.git

# 完成以上步骤后,执行
go get golang.org/x/lint/golint

如果你遇到了类似如下错误,就可以通过 git clone 的方式把包下载到本地,再进行安装即可解决问题;

Fetching https://golang.org/x/tools/go/buildutil?go-get=1
https fetch failed: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
package golang.org/x/tools/go/buildutil: unrecognized import path "golang.org/x/tools/go/buildutil" (https fetch: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)

4)安装go-find-references

go get -u -v github.com/lukehoban/go-find-references

5)安装go-outline

go get -u -v github.com/lukehoban/go-outline

6)安装goreturns

go get -u -v sourcegraph.com/sqs/goreturns

7)安装gorename

go get -u -v golang.org/x/tools/cmd/gorename

提示:如果还提示报错,因为前面已经git clone 下来了,可以执行执行"go installgolang.org/x/tools/cmd/gorename";

8)安装gopkgs

go get -u -v github.com/tpng/gopkgs

9)安装go-symbols

go get -u -v github.com/newhook/go-symbols

2.4 写一个程序进行测试

怎么配置使用Go语言IDE中的VSCode

可以看到能够进行相关提示。这里我们执行完整程序测试一下,程序是否正常。

怎么配置使用Go语言IDE中的VSCode

看完上述内容,是不是对怎么配置使用Go语言IDE中的VSCode有进一步的了解,如果还想学习更多内容,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. Go语言常用的IDE有哪些
  2. go语言的ide有哪些

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

go ide vscode

上一篇:centos中vim退出的方法

下一篇:解决anaconda安装好打不开的问题

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》