How to configure GO development environment in VSCode - ShrekHome/greatsoft.github.io GitHub Wiki

  1. Download and install the newest stable GOLang installer go1.14.6.windows-amd64.msi from https://studygolang.com/dl, because the official golang.org is unreachable in China.

  2. Set Windows Environment Variable:

  • GOPATH: %USERPROFILE%\go (set by user, where store user go code and their dependent libraries)
  • GOROOT: C:\go\ (set by installer, where golang is installed)
  • Append user Path: %USERPROFILE%\go\bin (set by installer, where go compiler toolset locate)
  1. Create recursively and cd into directory: %GOPATH%\src\golang.org\x

  2. Clone the following repositories from Github:

  1. cd back to %GOPATH%, create a new .bat file named install_plugins.bat, add the following lines:

echo Installing 17 tools for VSCODE

go get github.com/mdempsky/gocode

go get github.com/uudashr/gopkgs/v2/cmd/gopkgs

go get github.com/ramya-rao-a/go-outline

go get github.com/acroca/go-symbols

go get github.com/cweill/gotests/gotests

go get github.com/fatih/gomodifytags

go get github.com/josharian/impl

go get github.com/davidrjenni/reftools/cmd/fillstruct

go get github.com/haya14busa/goplay/cmd/goplay

go get github.com/godoctor/godoctor

go get github.com/go-delve/delve/cmd/dlv

go get github.com/rogpeppe/godef

go get github.com/sqs/goreturns

go install github.com/mdempsky/gocode

go install github.com/uudashr/gopkgs/v2/cmd/gopkgs

go install github.com/ramya-rao-a/go-outline

go install github.com/acroca/go-symbols

go install golang.org/x/tools/cmd/guru

go install golang.org/x/tools/cmd/gorename

go install github.com/cweill/gotests/gotests

go install github.com/fatih/gomodifytags

go install github.com/josharian/impl

go install github.com/davidrjenni/reftools/cmd/fillstruct

go install github.com/haya14busa/goplay/cmd/goplay

go install github.com/godoctor/godoctor

go install github.com/go-delve/delve/cmd/dlv

go install github.com/rogpeppe/godef

go install github.com/sqs/goreturns

go install golang.org/x/lint/golint

go install golang.org/x/tools/gopls

and run it. After that, all plugins would be installed at %GOPATH%\bin.

  1. Install Extension Go in VSCode,

  2. Editing user's settings.json, add the following lines:

{

"go.buildOnSave": "off",

"go.useCodeSnippetsOnFunctionSuggestWithoutType": true,

"go.useCodeSnippetsOnFunctionSuggest": true,

"go.gotoSymbol.includeImports": true,

"go.inferGopath": true,

"go.autocompleteUnimportedPackages": true,

"go.goroot": "$GOROOT",

"go.gopath": "C:\\Users\\zw\\go",

"go.useLanguageServer": true,

"[go]": {

    "editor.formatOnSave": true,

    "editor.codeActionsOnSave": {

        "source.organizeImports": true,

    },

    // Optional: Disable snippets, as they conflict with completion ranking.

    "editor.snippetSuggestions": "none",

},

"[go.mod]": {

    "editor.formatOnSave": true,

    "editor.codeActionsOnSave": {

        "source.organizeImports": true,

    },

},

"go.languageServerFlags": [

    "-rpc.trace", // for more detailed debug logging

    "serve",

    "--debug=localhost:6060", // to investigate memory usage, see profiles

],

"go.toolsEnvVars": {

    "GOFLAGS": "-tags=<yourtag>"

}

"gopls": {

     // Add parameter placeholders when completing a function.

    "usePlaceholders": true,

    // If true, enable additional analyses with staticcheck.
    // Warning: This will significantly increase memory usage.
    "staticcheck": false,
}

}

  1. When all above steps are correct, you can start your first hello.go in %GOPATH%\src.
⚠️ **GitHub.com Fallback** ⚠️