使用 Visual Studio Code 开发 Go 程序

使用 Visual Studio Code 开发 Go 程序 并且安装相关插件

  • 检查 GOPATH/bin 是否存在于 PATH
  • 然后安装下列依赖

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    go get -u -v github.com/mdempsky/gocode
    go get -u -v github.com/uudashr/gopkgs/cmd/gopkgs
    go get -u -v github.com/ramya-rao-a/go-outline
    go get -u -v github.com/acroca/go-symbols
    go get -u -v golang.org/x/tools/cmd/guru
    go get -u -v golang.org/x/tools/cmd/gorename
    go get -u -v github.com/derekparker/delve/cmd/dlv
    go get -u -v github.com/stamblerre/gocode
    go get -u -v github.com/rogpeppe/godef
    go get -u -v github.com/ianthehat/godef
    go get -u -v github.com/sqs/goreturns
    go get -u -v golang.org/x/lint/golint
    go get -u -v github.com/cweill/gotests/...
    go get -u -v github.com/fatih/gomodifytags
    go get -u -v github.com/josharian/impl
    go get -u -v github.com/davidrjenni/reftools/cmd/fillstruct
    go get -u -v github.com/haya14busa/goplay/cmd/goplay
  • 打开 Visual Studio Code 安装插件

    • 按下 Ctrl + P 输入 ext install ext 回车
    • 输入 Go 查找 安装第一个
  • 打开 Visual Studio Code 的配置

    • 添加下列配置
      1
      2
      3
      4
      5
      6
      7
      8
      "go.buildOnSave": "package",
      "go.lintOnSave": "package",
      "go.vetOnSave": "package",
      "go.buildFlags": [],
      "go.lintFlags": [],
      "go.vetFlags": [],
      "go.formatOnSave": true,
      "go.gocodeAutoBuild": true
  • 相关问题解决

    • 代码补全无效 只能提示 PANIC
      • 问题: go 的代码补全 gocode 是C/S模式的 所以 应该是 gocode daemon 挂了
      • 解决: 执行 gocode close && gocode -s & 重启服务