https://marketplace.visualstudio.com/items/lukehoban.Go
Go for Visual Studio CodeThis extension adds rich language support for the Go language to VS Code, including:
IDE FeaturesDebuggerUsingFirst, you will need to install Visual Studio Code In a terminal window with the GOPATH environment variable set to the GOPATH you want to work on, launch Note: It is strongly encouraged to turn OptionsThe following Visual Studio Code settings are available for the Go extension. These can be set in user preferences (
CommandsIn addition to integrated editing features, the extension also provides several commands in the Command Palette for working with Go files:
Optional: DebuggingTo use the debugger, you must currently manually install Once this is installed, go to the Code debug viewlet and select the configuration gear, placing the following in your launch.json:
The The
Building and Debugging the ExtensionYou can set up a development environment for debugging the extension during extension development. First make sure you do not have the extension installed in
You can now go to the Debug viewlet and select In the You can now hit breakpoints and step through the extension. If you make edits in the extension To debug the debugger, see the debugAdapter readme. ToolsThe extension uses the following tools, installed in the current GOPATH. If any tools are missing, you will see an "Analysis Tools Missing" warning in the bottom right corner of the editor. Clicking it will offer to install the missing tools for you.
To install them just paste and run:
And for debugging:
License |
在Visual Studio Code配置GoLang开发环境
作者:chszs
博客主页:http://blog.csdn.net/chszs
Visual Studio Code是我非常喜欢的开发工具。那么,如果能在Visual Studio Code上配置GoLang开发环境,以此开发GoLang程序,无疑很有趣。本文主要讲述这个过程。
一、GoLang的安装
GoLang在Windows的安装比较简单,过程省略。
验证一下:
D:\>go version
go version go1.5.1 windows/amd64
要注意,GoLang的安装要确保两个环境变量,一个是GOROOT环境变量;二是PATH环境变量要包含$GOROOT\bin值。
二、GoLang插件介绍
对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github.com/microsoft/vscode-go
这款插件的特性包括:
- 代码着彩色
- 代码自动完成(使用gocode)
- 代码片段
- 快速提示信息(使用godef)
- 跳转到定义(使用godef)
- 搜索参考引用(使用go-find-references)
- 文件大纲(使用go-outline)
- 重命名(使用gorename)
- 保存构建(使用go build和go test)
- 代码格式化(使用goreturns或goimports或gofmt)
- 调试代码(使用delve)
三、插件安装
1、安装Visual Studio Code 0.10.2版
去官方网站:https://code.visualstudio.com/
下载Visual Studio Code 0.10.2版,安装过程略。
2、安装插件
进入Visual Studio Code界面,使用快捷键Ctrrl+Shift+p,打开命令面板,选择“Extensions: Install Extension”,等待插件名列表的加载(这一步国内较慢)。
然后在输入框“ext install ”输入go,选择go 0.6.15,点击安装,安装完成后要求重启开发环境,点击重启按钮,自动刷新环境。
3、设置GOPATH环境变量
在Windows系统中设置GOPATH环境变量,我的值为D:\tools\VSCode\works
缺少GOPATH环境变量通常会报“$GOPATH not set.”这样的错误。
4、开启自动保存
强烈建议把自动保存功能开启。开启方法为:选择菜单File,点击Auto save。
5、安装Git
Windows安装Git的过程省略。记得把git\bin配置到PATH环境变量中。
四、配置插件
Visual Studio Code的配置选项支持GoLang插件的设置,可以通过用户偏好设置或workspace设置进行配置。在菜单File->Preferences处可以找到。
1、点击User Settings
找到
// Specifies the GOPATH to use when no environment variable is set.
"go.gopath": null,
如果没有设置GOPATH环境变量,那么这里就该设置。
2、执行命令
1)安装gocode
go get -u -v github.com/nsf/gocode
2)安装godef
go get -u -v github.com/rogpeppe/godef
3)安装golint
go get -u -v github.com/golang/lint/golint
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
3、使用
以上都完成后,开始GoLang开发就很方便了。如图所示:
有疑问加站长微信联系(非本文作者)