This is a creation in Article, where the information may have evolved or changed.
First, Introduction
For the Visual Studio Code development tool, there is a good Golang plug-in, its homepage is: https://github.com/microsoft/vscode-go
Features of this plugin include:
- Colorization Code with color
- Completion Lists Code Auto-complete (using Gocode)
- Snippets Code Snippets
- Quick Info Prompt information (using GODEF)
- Goto definition jumps to definitions (using Godef)
- Find References Search reference (using go-find-references)
- File Outline Document Outline (using Go-outline)
- Workspace symbol Search Workspace sign searching (using
go-symbols
)
- Rename renaming (using Gorename)
- Build-on-save Save build (using Go build and go test)
- Format code formatting (using Goreturns or Goimports or gofmt)
- Add Imports Reference (using gopkgs)
- Debugging debug code (using delve)
IDE Features:
Debugging Features:
Second, installation tools
First, you need to install visual Studio Code version 0.10. Select extension in the command panel (ctrl-shift-p or F1 key) and go.
Note: Visual Studio code installation, see 3.1 Visual Studio Code.
To set the working environment system variable Gopath, see "Setting environment variable Gopath 3.3". The Gopath of this machine is D:\GoWorks. Open the Gopath folder or subfolder you want to work with to start editing the go file.
Other plug-in installation is described in the "four, plug-in configuration." After installation, the interface is as follows:
Press F5, prompt cannot debug, install Debugging tool.
Debug tool installation, run at command line:
go get -v -u github.com/peterh/liner github.com/derekparker/delve/cmd/dlv
At the press of F5, debug:
Third, the Configuration tool
3.1 Settings.json
The following Visual Studio code settings are available for Go extensions. These can be set in user preferences or workspace settings (. vscode/settings.json).
Open the workspace Settings.json:
{ "Files.autosave": "Onfocuschange" go.buildonsave: true , " Go.lintonsave ": true , " Go.vetonsave ": Span style= "COLOR: #0000ff" >true "Go.buildflags" : [], "go.lintflags" : [], "Go.vetflags" Span style= "COLOR: #000000" >: [], "go.usecodesnippetsonfunctionsuggest": false "Go.formatonsave": false "Go.formattool": "Goreturns" "go.goroot": "\ c \ \go " "Go.gopath": "D:\\goworks" }
3.2 Launch.json
Debug tool Configuration Launch.json:
{ "version":"0.2.0", "configurations": [ { "name":"Launch", "type":"Go", "Request":"Launch", "Mode":"Debug", " Program":"${workspaceroot}", "Env": {}, "args": [] } ] }
The program parameter can refer to a package folder for debugging, or a file in that folder.
mode
Parameters can be set to:
- Debug compiles the program folder under the debugger and launches the contents. Default
- Test debug tests in the Programs folder.
- exec to run the pre-built binaries of the program folder that builds the current code instead.
3.3 Building and debugging extensions
You can set up debugging for your development environment with extended extensions.
First make sure that the. vscode/extensions is not installed. Then clone the other local repository on your machine, run NPM to install and open code for the development instance.
In the cmd command, open the D:\GoWorks directory:
Run the following command in the cmd window:
git clone https://github.com/Microsoft/vscode-go
Go to vscode-go Directory
Run NPM Install
Enter code. Pop-up Vscode-go window
Now you can debug Viewlet and check launch extension when pressing the F5 key.
In the [Extension development Host] instance, open the Gopath folder.
You can now kill the breakpoint and step through the extension.
If the extension is on. TS file for editing, simply reload the [Extension development Host]code instance in the newly extended code load, the debug instance is automatically connected.
Detailed new can be consulted: https://github.com/Microsoft/vscode-go/blob/master/src/debugAdapter/Readme.md