首頁  >  文章  >  開發工具  >  vscode編輯好go語言程式碼怎麼運行

vscode編輯好go語言程式碼怎麼運行

尚
原創
2020-04-01 16:58:3714811瀏覽

vscode編輯好go語言程式碼怎麼運行

vscode運行go語言程式碼需要安裝vscode-go外掛程式。然後使用F5(continue)、F10(step over)、F11(step into)等快速鍵執行go語言程式碼。

安裝vscode-go 外掛

進入vscode介面,開啟指令面板Ctrl Shift P,輸入install,

vscode編輯好go語言程式碼怎麼運行

外掛功能包括:

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外掛程式設定選項

啟動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

推薦學習:vscode教學

以上是vscode編輯好go語言程式碼怎麼運行的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn