In which I describe a new editor tool for go programmers that implements the Language Server Protocol. I’m excited to have a tool that works with my editor of choice, Sublime Text 3, and is easy to install.
Recently I tried installing some go tooling for Sublime Text 3, so I could get some auto-completion happening and get information about available functions. I tried installing goSublime, but found that there was no documentation on how to install it. The only page I found was for a development version of gosublime called margo. I tried cloning that per its instructions, and got some basic autocomplete but only for words in the current file, nothing with any knowledge of packages I had imported.
Hence my keenness to watch a video I found from gophercon by Rebecca Stambler entitled Go, pls stop breaking my editor. Interesting fact from that talk is that the Go plugin for VS Code installs 24 different tools to handle different editor-related jobs:
The new tool is called gopls, pronounced “go please”. It’s still in alpha at this stage, however it is developed by the go team and is intended to be supported by each new version of go, which is something that hasn’t been true of past 3rd party tools, such as gocode which broke when go 1.10 came out. Because it is a server, it caches information about your project, making the latency of completion much lower.
Installing gopls with Sublime Text 3
Assuming you have go installed, install gopls with:
go get golang.org/x/tools/gopls
If you’re using go in “module mode”, you can use the following command:
go get golang.org/x/tools/gopls@latest
Then for Sublime Text 3, install the Language Server Protocol package: LSP package using Package Control
Then follow the instructions here.
For other editors, instructions are here.
I have only just installed gopls, and I haven’t used it much yet, but so far it seems very responsive in its autocompletion and method info. I did find that the some of the completions are incorrect, for example if I have a string named ’t', and I type “t.i”, it will suggest t.import and t.imag, neither of which are valid. Gopls itself will tell me that.