Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to run the edited go code in vscode

Shulou Source: shulou.com Published: 2022-06-02 15:18:20 09月19日 Update

This article will explain in detail how to run the edited go language code in vscode. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

The vscode-go plug-in is required for vscode to run go language code. Then use keyboard shortcuts such as F5 (continue), F10 (step over), F11 (step into) to run the go language code.

Install the vscode-go plug-in

Enter the vscode interface, open the command panel Ctrl + Shift + P, and enter install

Plug-in features include:

Completion Lists (using gocode) Signature Help (using godoc) SnippetsQuick 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 gotest) 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

Visual Studio Code Go plug-in configuration options

After starting vscode, select 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 place with error or warning, F8.

Jump to the place defined by function F12

Zoom the entire screen Cmd + / Ctrl +

This is the end of the article on "how to run the edited go code in vscode". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Code language run plug-ins e.g. files articles commands places shortcuts more panels good practical content workspaces articles features pictures interfaces Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MySQL Shulou Tech Info Microsoft Redmi