Go 语言 IDE 之 VSCode 配置使用

Gogland 是 JetBrains 公司推出的 Go 语言集成开发环境。Gogland 同样基于 IntelliJ 平台开发,支持 JetBrains 的插件体系。官方:https://www.jetbrains.com/go/。关于 Goland 相关配置参考该链接即可。Goland 用的好好的,为

VSCode 是目前比较流行的 IDE 工具,在功能方面也相对齐全,使用方面也比较友好。

一、Golang 环境配置

关于 Goland 的系统环境配置,这里不做讲解。

二、安装配置 VSCode

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

2.1 安装 golang 插件

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

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

查询并安装 Go 插件

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

2.2 开启自动保存功能

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

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

 

{
    "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 install golang.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 写一个程序进行测试

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

OK,完全没有问题了。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值