windows vscode安裝go插件

vscode中有很多go的相關插件,非常好用如下:
gocode
gopkgs
go-outline
go-symbols
guru
gorename
gomodifytags
goplay
impl
godef
goreturns
golint
gotests
dlv

但是使用vscode 檢查插件安裝,會出現安裝失敗的情況。

下面介紹如何安裝失敗的插件

進行如下命令進行目錄切換:
cd %GOPATH%\src\github.com\golang
我這裏的GOPATH是在E:\gopath
如果src目錄下面沒有github.com\golang請自行創建

完成目錄切換後,開始下載插件包:
git clone https://github.com/golang/tools.git tools

當下載完成後,你會發現%GOPATH%\src\github.com\golang多了一個tools目錄
需要把tools目錄下的所有文件拷貝到%GOPATH%\src\golang.org\x\tools下,如果沒有自行創建
當然如果你是windows環境,如果你當前是在%GOPATH%\src\golang.org\x\tools
目錄下,你可以直接使用如下命令進行拷貝:
xcopy /s /e %GOPATH%\src\github.com\golang\tools
關於這個命令的使用可以具體百度查看,如果對該命令不熟悉就手動拷貝,直接將你下載的tools目錄下的所有文件拷貝到%GOPATH%\src\golang.org\x\tools目錄下

下面安裝無法安裝的插件
開始安裝:
切換到GOPATH目錄下,執行相關的go install 命令

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/josharian/impl

go install github.com/rogpeppe/godef

go install github.com/sqs/goreturns

go install github.com/golang/lint/golint

go install github.com/cweill/gotests/gotests

如果中間出現安裝golint失敗

E:\gopath>go install github.com/golang/lint/golint
src\github.com\golang\lint\golint\golint.go:19:2: cannot find package "golang.org/x/lint" in any of:
        E:\Go\src\golang.org\x\lint (from $GOROOT)
        E:\gopath\src\golang.org\x\lint (from $GOPATH)

需要把%GOPATH%\src\github.com\golang目錄下的lint目錄拷貝到%GOPATH%\src\golang.org\x\,然後重新執行安裝命令。

如果還有其他插件安裝失敗,比如gotests,這需要在github.com插件目錄下創建對應的文件夾和下載插件。

E:\gopath>go install github.com/cweill/gotests/gotests
can't load package: package github.com/cweill/gotests/gotests: cannot find package "github.com/cweill/gotests/gotests" in any of:
        E:\Go\src\github.com\cweill\gotests\gotests (from $GOROOT)
        E:\gopath\src\github.com\cweill\gotests\gotests (from $GOPATH)

在github.com目錄下創建cweill文件夾,然後git clone https://github.com/cweill/gotests.git,然後切換到%GOPATH%目錄下,go install github.com/cweill/gotests/gotests

其他安裝不成功的插件,也可以通過這種方式安裝。最後全部安裝成功

參考:https://blog.csdn.net/dmt742055597/article/details/85865186

           https://www.cnblogs.com/Leo_wl/p/8242628.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章