Go build tags + Emacs + gopls

With eglot being integratd in Emacs and gopls being the language server of choice I’ve been following this blog to configure my emacs for go, combined with readme instructions of gopls and eglot itself. Since at work we are using a monorepo setup for all go related code, we are also using build tags to customize the build, to make this work with gopls additional information needs to be passed to the language-server depending on the workspace. This is done differently depending on the editor interacting with gopls, based on the neovim example this can be replicated in emacs, and conviniently using .dir-locals.el to automatically configure the project correctly when opened.

((nil
  . ((eglot-workspace-configuration
      . (:gopls (:buildFlags  ["-tags=SOMETAG ANOTHERTAG"])))))))

It is important to use [ ... ] here which represents a vector in elisp, to make sure it gets serialized correctly by json-serialize into a JSON Array of string.

Using the above snippet, when visiting a *.go file in the project, gopls will automatically build using the provided build tags.

Installing golang-1.7 on ubuntu 16.10

Ubuntu, and in fact any debian as far as I’m aware has the the

$ update-alternatives

command to manage different versions of installed software. Currently when installing golang ubuntu will default to 1.6, but the repository contains 1.7 as well as package golang-1.7. To allow switching between the versions with the builtin system it can be setup via

$ update-alternatives --install /usr/bin/go go /usr/lib/go-1.7/bin/go 1

Where 1 is the priority, when using auto setup.

$ update-alternatives --config go

Now allows switching between the favorite go version.