This is a creation in Article, where the information may have evolved or changed.
Installing Vscode
Installing the Vscode-go Plugin
Enter the Vscode interface, open the command panel Ctrl + Shift + P
, enter install
,
Plug-in features include:
Completion Lists (usingGocode) Signature Help (usingGodoc) Snippetsquick Info (usingGODEF)GotoDefinition (usingGODEF) Find References (usingGuru) File Outline (usingGo-outline) Workspace Symbol search (usingGo-symbols) Rename (usingGorename) build- on-save (usingGo Build andGo test) lint- on-save (usingGolintorGometalinter) Format (usingGoreturnsorGoimportsorGOFMT) Generate Unit tests Squeleton (usinggotests) AddImports(usingGOPKGS) [Partially implemented] debugging (usingDelve
Manual Installation
Go get- u - vGitHub.Com/nsf/gocodego get- u - vGitHub.Com/rogpeppe/godefgo get- u - vGitHub.Com/golang/lint/golintgo get- u - vGitHub.Com/lukehoban/go-outlineGo get- u - vSourcegraph.Com/sqs/goreturnsgo get- u - vGolang.Org/x/tools/cmd/gorenamego get- u - vGitHub.Com/tpng/gopkgsgo get- u - vGitHub.Com/newhook/go-symbolsGo get- u - vGolang.Org/x/tools/cmd/gurugo get- u - vGitHub.Com/cweill/gotests/...
Visual Studio Code Go
Plug-in configuration options
vscode
Workspace Settings After startup, choose Preferences, File menu
In the open .vscode/settings.json
file, modify goroot
andgopath
{// GoConfiguration//Run ' Go build '/' Go test-c 'On save."Go.buildonsave": true,// FlagsTo ' go build '/' Go test ' used during Build-on-saveorRunning tests. (e.g. ['-ldflags= '-S "'])"Go.buildflags":[],// Run LintTool on save."Go.lintonsave": true,// Specifies LintTool name."Go.linttool": "Golint",// FlagsTo pass toLinttool (e.g. ['-min_confidenc=.8 '])"Go.lintflags":[],// Run ' Go tool vet 'On save."Go.vetonsave": true,// FlagsTo pass to ' Go tool vet ' (e.g. ['-all ','-shadow '])"Go.vetflags":[],// Pick ' gofmt ',' Goimports ' or ' Goreturns 'To run on format."Go.formattool": "Goreturns",// FlagsTo pass to format tool (e.g. ['-S '])"Go.formatflags":[],// RunThe formatting tools with THE-D flag"Go.usediffforformatting": true,// CompleteFunctions with their parameter signature"Go.usecodesnippetsonfunctionsuggest": false,// SpecifiesTheGopathTo use whenNo environment variable is set."Go.gopath": "//home/chenjianhua/gocode",// SpecifiesTheGorootTo use whenNo environment variable is set."Go.goroot": "/usr/local/go",// RunFormatting tool on save."Go.formatonsave": true,// Run ' Go test-coverprofile 'On save"Go.coveronsave": false,// SpecifiesThe timeout forGo testinch parsedurationFormat."Go.testtimeout": "30s",// EnableGocode' s autobuild feature "Go.gocodeautobuild": true,//The Go build tags to use for all commands that support a '-t AGS '..." argument" go.buildtags ":" ",///environment variables that would passed to the process that runs the Go tests "Go.testenvvars": {},//Autocomplete members from unimported packages. "Go.autocompleteunimportedpackages": true}
Vscode Editor Shortcut keys
命令面板 Ctrl + Shift + P 或者 F1转到文件 Ctrl + P切换终端 Ctrl + `重命名 F2调试 F5(continue)F10(step over)F11(stepinto)跳到下一个有error或者warning的地方 F8 跳到function定义的地方 F12缩放整个画面 Cmd +/Ctrl +
Open golang
Project
文件 -> 打开golang项目所在文件夹
There's a hint when you write the code.
Useful plugins
Vscode-icons