VS Code中Golang环境配置

1.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 :).

2.自动化配置:例如 代码自动补全  ,自动引依赖包等

  File->Preferences -> Setting ,然后输入 go,然后选择 setting.json(如果是远程,需要点击Rmote[Host:XXX]标签),填入你想要修改的配置。或者通过右上角图标,进入设置 setting.json页面,添加如下字段信息。实现代码自动补全需要设置字段为go.useCodeSnippetsOnFunctionSuggest ,go.inferGopath。

"go.autocompleteUnimportedPackages": true,         //自动完成未导入的包
“go.useCodeSnippetsOnFunctionSuggest”: true,       //自动提示代码,代码自动补全
"go.docsTool": "gogetdoc",                         //支持跳转到文件名含.路径等功能
"go.inferGopath": true,                            //开启推断gopath的功能
"go.gocodePackageLookupMode": "go",                //代码包查询模式
"go.gotoSymbol.includeImports": true

  可参考setting.json文件格式。如下配置是在远程ssh登录Linux虚拟机时,配置需要注意goroot以及gopath路径

{
    "go.goroot": "/usr/lib/golang",
    "go.gopath": "/root/go",
    "go.inferGopath": true,
    "go.autocompleteUnimportedPackages": true,
    "go.gocodePackageLookupMode": "go",
    "go.gotoSymbol.includeImports": true,
    "go.useCodeSnippetsOnFunctionSuggest": true,
    "go.useCodeSnippetsOnFunctionSuggestWithoutType": true,
    "go.docsTool": "gogetdoc",
}

发表评论

邮箱地址不会被公开。 必填项已用*标注