您的位置:首页 > 编程语言 > Go语言

在Visual Studio Code中配置GO开发环境

2016-05-04 15:32 821 查看

一、GO语言安装

详情查看:/article/10863311.html

二、GoLang插件介绍

对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github.com/microsoft/vscode-go

这款插件的特性包括:

Colorization 代码着彩色
Completion Lists 代码自动完成(使用gocode)
Snippets 代码片段
Quick Info 快速提示信息(使用godef)
Goto Definition 跳转到定义(使用godef)
Find References 搜索参考引用(使用go-find-references)
File outline 文件大纲(使用go-outline)
Workspace symbol search 工作区符号搜索(使用
go-symbols

Rename 重命名(使用gorename)
Build-on-save 保存构建(使用go build和go test)
Format 代码格式化(使用goreturns或goimports或gofmt)
Add Imports 添加引用(使用 gopkgs)
Debugging 调试代码(使用delve)

安装方式:

git clone https://github.com/Microsoft/vscode-go cd vscode-go
npm install


详细请看/article/7016859.html

三、插件安装

3.1 Visual Studio Code

找到微软的官方网站,下载Visual Studio Code,官网地址 https://code.visualstudio.com/





点击上图红框,可以下载其他平台的编辑器,如下图:





下载安装过程省略,当前版本是:

3.2 安装插件

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





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





查询插件:





显示插件列表:





在插件列表中,选择 Go,进行安装,安装之后,系统会提示重启Visual Studio Code。

3.3 设置环境变量GOPATH

在Windows系统中设置GOPATH环境变量,我的值为D:\GoWorks





缺少GOPATH环境变量通常会报“$GOPATH not set.”这样的错误。

3.4 开启Visual Studio Code自动保存功能

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







添加或更改settings.json的“files.autoSave”属性为“onFocusChange”,并保存。





3.5 安装Git

Windows安装Git的过程省略;安装之后git\bin配置到PATH环境变量中。





四、插件配置

4.1 Visual Studio Code Go插件配置选项

Visual Studio Code的配置选项支持Go插件的设置,可以通过用户偏好设置或workspace设置进行配置。在菜单File->Preferences处可以找到。





在settings.json中设置go配置环境,如下图:





4.2 执行命令

查看官方网站:https://marketplace.visualstudio.com/items?itemName=lukehoban.Go

集成安装命令,拷贝到cmd窗口就可完成安装:

go get -u -v github.com/nsf/gocode
go get -u -v github.com/rogpeppe/godef
go get -u -v github.com/golang/lint/golint
go get -u -v github.com/lukehoban/go-find-references
go get -u -v github.com/lukehoban/go-outline
go get -u -v sourcegraph.com/sqs/goreturns
go get -u -v golang.org/x/tools/cmd/gorename
go get -u -v github.com/tpng/gopkgs
go get -u -v github.com/newhook/go-symbols
[code]go get -v -u github.com/peterh/liner github.com/derekparker/delve/cmd/dlv

未安装成功, 直接到网站下载 如:

github.com/nsf/gocode的代码放在

D:\GoWorks\src\github.com\nsf\gocode

然后进入这个文件夹,运行指令:go install.

这里提供一个脚本,简化运行,另存为批处理文件即可。

cd "c:\go\src\github.com\nsf\gocode"

go install

下载 https://godoc.org/golang.org/x/tools/到 D:/GoWorks/src/golang.org/x/tools/

重启vs code,如提示右下下角有analysis tool missing

到相应路径 下面执行 go install

3、使用 Hello word

1)File-> Open Folder,现在工作目录:







2)新建go文件





看看,智能提示出来了。





参考:https://marketplace.visualstudio.com/items?itemName=lukehoban.Go
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: