VS Code Golang 踩坑
摘要:
第一步: 安裝最新版的Golang
Go 語言中文網
第二步: 安裝VS Code 的 Go 語言外掛
Go 語言支援 for VS Code
第三步: 接受VS Code 的推薦安裝
...
第一步: 安裝最新版的Golang
第二步: 安裝VS Code 的 Go 語言外掛
第三步: 接受VS Code 的推薦安裝
- 這裡應該會一個都安裝不上, 因為Golang 官網是被牆的
- 使用 git bash 設定 代理.
export http_proxy=http://127.0.0.1:1080 export https_proxy=https://127.0.0.1:1080
- 手動安裝需要的golib
go get -v -u github.com/mdempsky/gocodegocode go get -v -u github.com/uudashr/gopkgs/cmd/gopkgsgopkgs go get -v -u github.com/ramya-rao-a/go-outlinego-outline go get -v -u github.com/acroca/go-symbolsgo-symbols go get -v -u golang.org/x/tools/cmd/guruguru go get -v -u golang.org/x/tools/cmd/gorenamegorename go get -v -u github.com/derekparker/delve/cmd/dlvdlv go get -v -u github.com/stamblerre/gocodgocode-gomod go get -v -u github.com/rogpeppe/godefgodef go get -v -u github.com/ianthehat/godefgodef-gomod go get -v -u github.com/sqs/goreturnsgoreturns go get -v -u golang.org/x/lint/golintgolint
- 手動 build
go build -o %GOPATH%\\bin\\gocode.exe github.com/mdempsky/gocode go build -o %GOPATH%\\bin\\gopkgs.exe github.com/uudashr/gopkgs/cmd/gopkgs% go build -o %GOPATH%\\bin\\go-outline.exe github.com/ramya-rao-a/go-outline% go build -o %GOPATH%\\bin\\go-symbols.exe github.com/acroca/go-symbols% go build -o %GOPATH%\\bin\\guru.exe golang.org/x/tools/cmd/guru% go build -o %GOPATH%\\bin\\gorename.exe golang.org/x/tools/cmd/gorename% go build -o %GOPATH%\\bin\\dlv.exe github.com/derekparker/delve/cmd/dlv% go build -o %GOPATH%\\bin\\gocode-gomod.exe github.com/stamblerre/gocode go build -o %GOPATH%\\bin\\godef.exe github.com/rogpeppe/godef go build -o %GOPATH%\\bin\\godef-gomod.exe github.com/ianthehat/godef go build -o %GOPATH%\\bin\\goreturns.exe github.com/sqs/goreturns% go build -o %GOPATH%\\bin\\golint.exe golang.org/x/lint/golint
- 手動將所有的.exe檔案放入%Goroot%\bin 資料夾下, 至少包含以下幾種
dlv gocode gocode-gomod godef godef-gomod golint go-outline gopkgs gorename goreturns go-symbols guru
配置 VS Code
- 使用資料夾配置, 在.vscode資料夾下新建settings.json
{ "go.buildOnSave": "package", "go.lintOnSave": "package", "go.vetOnSave": "package", "go.coverOnSave": false, "go.formatTool": "goreturns", "go.goroot": "C://Go", "go.gopath": "C://go", "go.gocodeAutoBuild": true }