這是一個建立於
的文章,其中的資訊可能已經有所發展或是發生改變。
背景
在上一篇在Deepin Linux上用Sublime Text3配置GoLang開發環境 文章中介紹了用Sublime Text 3進行Golang開發,本篇中再介紹最新的Golang開發神器Visual Studio Code。
Visual Studio Code重新定義和最佳化了代碼編輯,以便產生和調試新式 Web 應用程式和雲應用程式。 您可以在常用平台(Linux、OS X 和 Windows)上免費使用 Visual Studio Code。
Go語言安裝
詳情查看:安裝Golang
VSCode安裝
從 Visual Studio Code官網下載最新版本1.4.0並安裝。
外掛程式安裝
在左側導航條有5個按鈕,依次是資源管理員,搜尋,GIT,調試,擴充,點擊擴充按鈕,然後在市集中搜尋擴充Go進行外掛程式安裝。
vs-go
外掛程式安裝後重啟Visual Studio Code,再次點擊已安裝的外掛程式可以看到外掛程式的介紹。
Go for Visual Studio Code
Visual Studio Code Go外掛程式配置選項
從菜單中選擇"檔案" -> “喜好設定" -> "使用者佈建",進行如下設定
settings
// 將設定放入此檔案中以覆蓋預設設定{ "files.autoSave": "onFocusChange", "go.buildOnSave": true, "go.lintOnSave": true, "go.vetOnSave": true, "go.buildFlags": [], "go.lintFlags": [], "go.vetFlags": [], "go.useCodeSnippetsOnFunctionSuggest": false, "go.formatOnSave": false, "go.formatTool": "goreturns", "go.gopath":"/home/tonny/golang", "go.goroot": "/usr/local/go"}
Go工具安裝
由於國內對golang.org訪問不通暢,採用變通的方法來安裝Go工具。
➜ tonny@tonny-pc ~ mkdir -p $GOPATH/src/golang.org/x ➜ tonny@tonny-pc ~ cd $GOPATH/src/golang.org/x➜ tonny@tonny-pc ~ git clone https://github.com/golang/tools.git➜ tonny@tonny-pc ~ go get golang.org/x/tools/cmd/godoc➜ tonny@tonny-pc ~ ll $GOROOT/bin
其他相關工具安裝,參考如下:
➜ tonny@tonny-pc ~ vi gotools.sh#!/bin/bash # Get all go tools for vscodego 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-find-referencesgo 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-symbols➜ tonny@tonny-pc ~ chmod +x gotools.sh ➜ tonny@tonny-pc ~ ./gotools.sh
調試工具dlv
go get github.com/derekparker/delve/cmd/dlv$ make install
Note: If you are using Go 1.5 you must set GO15VENDOREXPERIMENT=1 before continuing. The GO15VENDOREXPERIMENT env var simply opts into the Go 1.5 Vendor Experiment.