vscode編輯器golang調試

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

安裝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檔案,修改gorootgopath

{// 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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.