這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。
安裝vscode
安裝vscode-go 外掛程式
進入vscode介面,開啟命令選擇區Ctrl + Shift + P
,輸入install
,
外掛程式特性包括:
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 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)
手動安裝
go get -u -v github.com/nsf/gocodego get -u -v github.com/rogpeppe/godefgo get -u -v github.com/golang/lint/golintgo get -u -v github.com/lukehoban/go-outlinego get -u -v sourcegraph.com/sqs/goreturnsgo get -u -v golang.org/x/tools/cmd/gorenamego get -u -v github.com/tpng/gopkgsgo get -u -v github.com/newhook/go-symbolsgo get -u -v golang.org/x/tools/cmd/gurugo get -u -v github.com/cweill/gotests/...
Visual Studio Code Go
外掛程式配置選項
啟動vscode
後選擇 檔案菜單 -> 喜好設定 -> 工作區設定
在開啟的.vscode/settings.json
檔案,修改goroot
和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編輯器快速鍵
命令選擇區 Ctrl + Shift + P 或者 F1轉到檔案 Ctrl + P切換終端 Ctrl + `重新命名 F2調試 F5(continue)F10(step over)F11(step into)跳到下一個有error或者warning的地方 F8 跳到function定義的地方 F12縮放整個畫面 Cmd +/Ctrl +
開啟golang
項目
檔案 -> 開啟golang項目所在檔案夾
編寫代碼的時候就有提示了
好用的外掛程式
vscode-icons