VS Code installs Go plug-in, custom extension configuration, breakpoint debugging

1. Install the plugin

Use shortcut keys Ctrl+Shift+Xto open the plug-in installation page to install Goplug-ins.

2. Customize the extended configuration

Use shortcut keys Ctrl+,to open the Custom Configuration page, edit settings.json, expand the definition of Go related configuration items.

{
    
    
    "editor.formatOnSave": true,
    "files.autoSave": "onFocusChange",
    "go.buildOnSave": "workspace",
    "go.lintOnSave": "package",
    "go.vetOnSave": "package",
    "go.buildFlags": [],
    "go.lintFlags": [],
    "go.vetFlags": [],
    "go.coverOnSave": false,
    "go.autocompleteUnimportedPackages": true,
    "go.useLanguageServer": true,
    "go.inferGopath": true,
    "go.docsTool": "godoc",
    "go.gocodePackageLookupMode": "go",
    "go.gotoSymbol.includeImports": true,
    "go.useCodeSnippetsOnFunctionSuggest": true,
    "go.useCodeSnippetsOnFunctionSuggestWithoutType": true,
    "go.formatTool": "goreturns",
    "go.gocodeAutoBuild": false,
    "go.liveErrors": {
    
    
        "enabled": true,
        "delay": 0
    },
    "go.gopath": "/data/go",
    "go.goroot": "/usr/local/go/1.12.7/libexec"
}

3. Installation dependencies

VSCode installation

The first time you have finished editing Gothe code to save time, VS Codeyou will be prompted to install dependent, click Install Allto install. If you encounter wall problems, you need to manually install the dependencies, and you need to download the source code of the dependencies first, and then install them.

go get -u -v github.com/ramya-rao-a/go-outline
go get -u -v github.com/acroca/go-symbols
go get -u -v github.com/mdempsky/gocode
go get -u -v github.com/rogpeppe/godef
go get -u -v golang.org/x/tools/cmd/godoc
go get -u -v github.com/zmb3/gogetdoc
go get -u -v golang.org/x/lint/golint
go get -u -v github.com/fatih/gomodifytags
go get -u -v golang.org/x/tools/cmd/gorename
go get -u -v sourcegraph.com/sqs/goreturns
go get -u -v golang.org/x/tools/cmd/goimports
go get -u -v github.com/cweill/gotests/...
go get -u -v golang.org/x/tools/cmd/guru
go get -u -v github.com/josharian/impl
go get -u -v github.com/haya14busa/goplay/cmd/goplay
go get -u -v github.com/uudashr/gopkgs/cmd/gopkgs
go get -u -v github.com/davidrjenni/reftools/cmd/fillstruct
go get -u -v github.com/alecthomas/gometalinter
gometalinter --install

Partly dependent on the source code address:

4. Breakpoint debugging

Created in the project root directory .vscode/lauch.jsonand configure the debug parameters:

{
    
    
    "version": "0.2.0",
    "configurations": [
        {
    
    
            "name": "gotest",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "remotePath": "",
            "port": 10550,
            "host": "127.0.0.1",
            "program": "/data/go/src/test/main.go",
            "env": {
    
    
                "GOPATH": "/data/go"
            },
            "args": [],
            "showLog": true
        }
    ]
}

Break point in the project file, press F5 to start breakpoint debugging.
If you encounter an error:

could not launch process: executables built by Go 1.11 or later need Delve built by Go 1.11 or later

Upgrade and install delve

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

Guess you like

Origin blog.csdn.net/wohu1104/article/details/111464402