Home >Development Tools >VSCode >How to run the go language code edited by vscode
vscode needs to install the vscode-go plug-in to run go language code. Then use F5 (continue), F10 (step over), F11 (step into) and other shortcut keys to run the go language code.
Install the vscode-go plug-in
Enter the vscode interface, open the command panel Ctrl Shift P, enter install,
Plug-in features include:
Completion Lists (using gocode) Signature Help (using godoc) Snippets Quick Info (using godef) Goto Definition (using godef) Find References (using guru) File outline (using go-outline) Workspace symbol search (using go-symbols) Rename (using gorename) Build-on-save (using go build and go test) Lint-on-save (using golint or gometalinter) Format (using goreturns or goimports or gofmt) Generate unit tests squeleton (using gotests) Add Imports (using gopkgs) [partially implemented] Debugging (using delve)
Visual Studio Code Go plug-in configuration options
After starting vscode, select the File menu-> Preferences-> Workspace Settings
In the open. vscode/settings.json file, modify goroot and gopath
{ // Go configuration // Run 'go build'/'go test -c' on save. "go.buildOnSave": true, // Flags to `go build`/`go test` used during build-on-save or running tests. (e.g. ['-ldflags="-s"']) "go.buildFlags": [], // Run Lint tool on save. "go.lintOnSave": true, // Specifies Lint tool name. "go.lintTool": "golint", // Flags to pass to Lint tool (e.g. ['-min_confidenc=.8']) "go.lintFlags": [], // Run 'go tool vet' on save. "go.vetOnSave": true, // Flags to pass to `go tool vet` (e.g. ['-all', '-shadow']) "go.vetFlags": [], // Pick 'gofmt', 'goimports' or 'goreturns' to run on format. "go.formatTool": "goreturns", // Flags to pass to format tool (e.g. ['-s']) "go.formatFlags": [], // Run the formatting tools with the -d flag "go.useDiffForFormatting": true, // Complete functions with their parameter signature "go.useCodeSnippetsOnFunctionSuggest": false, // Specifies the GOPATH to use when no environment variable is set. "go.gopath": "//home/chenjianhua/gocode", // Specifies the GOROOT to use when no environment variable is set. "go.goroot": "/usr/local/go", // Run formatting tool on save. "go.formatOnSave": true, // Run 'go test -coverprofile' on save "go.coverOnSave": false, // Specifies the timeout for go test in ParseDuration format. "go.testTimeout": "30s", // Enable gocode's autobuild feature "go.gocodeAutoBuild": true, // The Go build tags to use for all commands that support a `-tags '...'` argument "go.buildTags": "", // Environment variables that will passed to the process that runs the Go tests "go.testEnvVars": {}, // Autocomplete members from unimported packages. "go.autocompleteUnimportedPackages": true }
vscode editor shortcut key
Command panel Ctrl Shift P or F1
Go to file Ctrl P
Switch terminal Ctrl `
Rename F2
Debug F5(continue)F10(step over)F11(step into)
Jump to the next one with error or F8 where warning is
Jump to where function is defined F12
Zoom the entire screen Cmd /Ctrl
Recommended learning: vscode tutorial
The above is the detailed content of How to run the go language code edited by vscode. For more information, please follow other related articles on the PHP Chinese website!