下载:https://code.visualstudio.com/Download

安装:
配置语言:crtl+shift+P --------》》 输入“configure language”,然后回车 --------》》安装语言 --------》》安装汉语简体
安装go插件:

安装代码自动补全插件:

安装跳转翻页的标签插件:

版本管理插件:gitlens

todo插件:

code runner插件:

VSCode 必须安装以下插件:
首先你必须安装 Golang 插件,然后再给 Go 安装工具包。
在 VS Code 中,使用快捷键:command+shift+P
,然后键入:go:install/update tools
,将所有 16 个插件都勾选上,然后点击 OK 即开始安装。
Installing 16 tools at /Users/maiyang/develop/goworkspace//bin gocode gopkgs go-outline go-symbols guru gorename dlv godef godoc goreturns golint gotests gomodifytags impl fillstruct goplay
Installing github.com/mdempsky/gocode SUCCEEDED Installing github.com/uudashr/gopkgs/cmd/gopkgs SUCCEEDED Installing github.com/ramya-rao-a/go-outline SUCCEEDED Installing github.com/acroca/go-symbols SUCCEEDED Installing golang.org/x/tools/cmd/guru SUCCEEDED Installing golang.org/x/tools/cmd/gorename SUCCEEDED Installing github.com/derekparker/delve/cmd/dlv SUCCEEDED Installing github.com/rogpeppe/godef SUCCEEDED Installing golang.org/x/tools/cmd/godoc SUCCEEDED Installing github.com/sqs/goreturns SUCCEEDED Installing github.com/golang/lint/golint SUCCEEDED Installing github.com/cweill/gotests/... SUCCEEDED Installing github.com/fatih/gomodifytags SUCCEEDED Installing github.com/josharian/impl SUCCEEDED Installing github.com/davidrjenni/reftools/cmd/fillstruct SUCCEEDED Installing github.com/haya14busa/goplay/cmd/goplay SUCCEEDED
All tools successfully installed. You're ready to Go :). |
go get -v github.com/nsf/gocode
go get -v github.com/rogpeppe/godef
go get -v github.com/golang/lint/golint
go get -v github.com/lukehoban/go-find-references
go get -v github.com/lukehoban/go-outline
go get -v sourcegraph.com/sqs/goreturns
go get -v golang.org/x/tools/cmd/gorename
go get -v github.com/tpng/gopkgs
go get -v github.com/newhook/go-symbols
go
get
github.com/uudashr/gopkgs/v2/cmd/gopkgs
go
get
github.com/cweill/gotests/gotests
go
get
github.com/fatih/gomodifytags
go
get
github.com/josharian/impl
go
get
github.com/go-delve/delve/cmd/dlv
go
get
honnef.co/go/tools/cmd/staticcheck
go
get
golang.org/x/tools/gopls
go
get
github.com/haya14busa/goplay/cmd/goplay
修改默认配置的方法:
在 Preferences -> Setting 然后输入 go,然后选择 setting.json
,填入你想要修改的配置
"go.autocompleteUnimportedPackages": true, |
- VSCode 的一些插件需要配置代理,才能够正常安装。
"http.proxy": "192.168.0.100:1087", |
- 如果你遇到使用标准包可以出现代码提示,但是使用自己的包或者第三方库无法出现代码提示,你可以查看一下你的配置项。
- 如果引用的包使用了 ( . “aa.com/text”) 那这个text包下的函数也无法跳转进去,这是为什么?
修改 "go.docsTool"
为 gogetdoc
,默认是 godoc
。
"go.docsTool": "gogetdoc", |
其他
- 当我们在使用 import 功能的时候,如果无法通过 lint 检查,则不会执行自动 import。
- 如果你需要自动 import 的前提是你必须把要导入的包的函数写完整。
附带我的 settings.json
{ "go.goroot": "", "go.gopath": "", "go.inferGopath": true, "go.autocompleteUnimportedPackages": true, "go.gocodePackageLookupMode": "go", "go.gotoSymbol.includeImports": true, "go.useCodeSnippetsOnFunctionSuggest": true, "go.useCodeSnippetsOnFunctionSuggestWithoutType": true, "go.docsTool": "gogetdoc", } |
字体配置:默认配置即可:
Consolas, 'Courier New', monospace

只显示一个文件:
问题:VSCode的标签栏一直只能显示一个文件tab, 点一次被替换,让人丈二和尚摸不着头脑:javascript:void(0)
解决:点击Code>首选项>设置,在搜索框输入 “workbench.editor.enablePreview” ,去掉选择框,一切回归正常。

安装中文:
Mac 用户按住快捷键 Cmd+Shift+P
(Windows 用户按住快捷键Ctrl+Shift+P
),打开命令面板。
在命令面板中,输入Configure Display Language
,选择Install additional languages
,然后安装插件Chinese (Simplified) Language Pack for Visual Studio Code
即可。
或者,我们可以直接安装插件Chinese (Simplified) Language Pack for Visual Studio Code
,是一样的。
安装完成后,重启 VS Code。
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch test package",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${fileDirname}"
},
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
// "program": "${fileDirname}",
"program": "${workspaceFolder}/src/apps/mishop_api",
"env": {},
"args": [],
"dlvLoadConfig": {
"followPointers": true,
"maxVariableRecurse": 1,
"maxStringLen": 10240,
"maxArrayValues": 64,
"maxStructFields": -1
}
}
]
}
#####################