Go modules vs VSCode
概要
Go1.13からデフォルトになるGoの依存パッケージに対するバージョン管理機構Go modules
について、導入しようと思ったらVSCode周りが辛かったので備忘録としてまとめる。
間違ってたらごめんなさい。
TL;DR
- この記事読んでおけばだいたいわかる
- VSCodeでもGo modules対応はできる
Language Server
のgoplsを使う- 依存モジュールはGo modulesから取ってくるようになる
- 補完も効く
- Language Serverなんもわからんけどすごい
- やっぱりJetBrainsはすごい
Go modules
端的に表現すると、ついにGoに組み込まれた標準バージョン管理機構、depからの移行先。 この辺読むといいと思いますです。
- Go & Versioning
- github.com/golang/go/wiki/Modules
- Go Modulesの概要とGo1.12に含まれるModulesに関する変更 #golangjp #go112party
導入しようとしたきっかけ
- 今から走るプロジェクトにdep入れるのどうなん?:thinking_face:
- ライブラリでもgo modules対応見かけるようになってきたしそろそろいいのでは?
- CI jobで
dep
やvendor
の管理をもうしたくない
- RenovateがGo対応してるやん!って思ったらGo modulesだけだった
- Automated Dependency Updates for Go Modules
- Renovate supports upgrading dependencies in go.mod files and their accompanying go.sum checksums.
- RenovateがGoに必要かどうかは別議論
- Automated Dependency Updates for Go Modules
立ちはだかる壁VSCodeと理想のGoLand
- Go modules support in Visual Studio Code
- As you already know, the Go extension depends on various Go tools from the community to provide language support. Some of these tools support Go modules already, and others don't. Therefore, you will see that some features of the Go extension will work and others won't when using Go modules.
- まあそれはそう
- Go modules (vgo) - GoLand 2019.1 Help
- さすがのJetBrains
- 個人はともかく会社で全員分買うか?と言う問題
- 費用というより宗教的な話
希望のLanguage Server Protocol
- Language Server Protocolについては以下
Official page for Language Server Protocol
Adding features like auto complete, go to definition, or documentation on hover for a programming language takes significant effort. Traditionally this work had to be repeated for each development tool, as each tool provides different APIs for implementing the same feature.
A Language Server is meant to provide the language-specific smarts and communicate with development tools over a protocol that enables inter-process communication.
The idea behind the Language Server Protocol (LSP) is to standardize the protocol for how such servers and development tools communicate. This way, a single Language Server can be re-used in multiple development tools, which in turn can support multiple languages with minimal effort.
LSP is a win for both language providers and tooling vendors!
- 日本語記事だとこれとか
Goの補完ライブラリの歴史的経緯とGoのLanguage Server
gocode やめます(そして Language Server へ)
- Goの補完ライブラリのほとんどは内部に
gocode
を抱えている - しかし、
gocode
はthis project is not maintained anymore, look for alternatives or forks if you need Go autocompletion tool
となってしまった- nsf/gocode
- 詳細は上記記事
- Goの
Language Server
実装であるsourcegraph/go-langserver
も内部ではgocode
を使っていた
Google製Go Language Server gopls
- golang.org/x/tools/cmd/gopls
- Goコミュニティとしてこれに統一することが決まっている、Google製 Go Language Server。
- 元々
golsp
だった。 - 他のLanguage Serverは、以下のようにメンテナンスをやめている文が出ている。
- sourcegraph/go-langserver
Note: We have deprioritized work on this language server for use in editors in favor of Google's upcoming Go language server. It is in the best interests of the community to only have a single language server. If you want to use a Go language server with your editor in the meantime, try https://github.com/saibing/bingo, which is a partial fork of this repository with fixes for Go modules and other editor bugs.
- saibing/bingo
I am very sorry that I have planned not continue to maintain this project. According to the issue #13 collaborating on golsp, I hope that we will eventually have a unified language server: gopls. It is Google's upcoming Go language server. It is in the best interests of the community to only have a single language server.
goplsのVSCodeへの適用手順
- Go modules support in Visual Studio Code
-
Can I use the language server when using Go modules?
を参照
-
- github.com/golang/go/wiki/goplsには、もう少し詳細な設定が載っている。
- github.com/Microsoft/vscode-goのREADMEにもあるように、まだExperimentalな機能
- gopls自体もまだまだ実装途中。