背景

vscode也许是现在最流行的代码编辑器了吧,主要是还能映射其他代码编辑器的快捷键,比如vim、sublime text等。可是由于网络原因吧【被墙】,我在安装go插件的总会遇到失败。

环境

Ubuntu

设置中文菜单栏

当我们到vscode官网下载ded包,安装好后vscode是英文菜单,如果想设置为中文,我们可以先下载中文拓展插件,然后修改配置文件

1、安装中文拓展插件

Linux vscode基本配置以及golang插件安装

2、修改配置文件

Ctrl + Shift + Pconfigure
locale.json

安装vscode golang第三方包/插件

Ctrl + Shift + Pgo: install
Installing github.com/mdempsky/gocode FAILED
Installing github.com/uudashr/gopkgs/cmd/gopkgs FAILED
Installing github.com/ramya-rao-a/go-outline FAILED
Installing github.com/acroca/go-symbols FAILED
Installing golang.org/x/tools/cmd/guru FAILED
Installing golang.org/x/tools/cmd/gorename FAILED
Installing github.com/derekparker/delve/cmd/dlv FAILED
Installing github.com/rogpeppe/godef FAILED
Installing golang.org/x/tools/cmd/godoc FAILED
Installing github.com/sqs/goreturns FAILED
Installing github.com/golang/lint/golint FAILED
Installing github.com/cweill/gotests/... FAILED
Installing github.com/fatih/gomodifytags FAILED
Installing github.com/josharian/impl FAILED
Installing github.com/davidrjenni/reftools/cmd/fillstruct FAILED
Installing github.com/haya14busa/goplay/cmd/goplay FAILED

就是各种google,发现好像都没有很好很全的解决这个问题,都是东凑西凑才得以解决,所以记录下解决方法

GOPATH
$ mkdir -p github.com/golang 
$ mkdir -p golang.org/x

2、克隆golang官方的tools包到上一步创建的两个目录

$ git clone https://github.com/golang/tools.git github.com/golang/tools
$ git clone https://github.com/golang/tools.git golang.org/x/tools

注:如果你发现克隆代码非常慢,而你电脑又可以翻墙,那快把终端也设置socks5代理吧

3、安装第三方包

$ go install github.com/mdempsky/gocode
$ go install github.com/uudashr/gopkgs/cmd/gopkgs
$ go install github.com/ramya-rao-a/go-outline
$ go install github.com/acroca/go-symbols
$ go install golang.org/x/tools/cmd/guru
$ go install golang.org/x/tools/cmd/gorename
$ go install github.com/derekparker/delve/cmd/dlv
$ go install github.com/rogpeppe/godef
$ go install golang.org/x/tools/cmd/godoc
$ go install github.com/sqs/goreturns
$ go install github.com/golang/lint/golint
$ go install github.com/cweill/gotests/gotests
$ go install github.com/fatih/gomodifytags
$ go install github.com/josharian/impl
$ go install github.com/davidrjenni/reftools/cmd/fillstruct
$ go install github.com/haya14busa/goplay/cmd/goplay

4、更改下用户的配置文件

文件首选项设置go

添加以下设置
Linux vscode基本配置以及golang插件安装

    # vscode好像还不支持socks5代理
    # https://code.visualstudio.com/docs/setup/network
    "http.proxy": "http://127.0.0.1:1080",
    "http.proxyStrictSSL": false,

    "go.goroot": "/usr/local/go",
    "go.gopath": "/home/tab/go",
    "go.autocompleteUnimportedPackages": true,
    "go.gocodePackageLookupMode": "go",
    "go.gotoSymbol.includeImports": true,
    "go.useCodeSnippetsOnFunctionSuggest": true,
    "go.useCodeSnippetsOnFunctionSuggestWithoutType": true,
    "go.docsTool": "gogetdoc",
    "go.inferGopath": true

到此,vscode golang的开发环境配置基本完成了。