-->
2 min read

fixing gopls build tags in zed for mage

Table of Contents

problem

On my journey of learning Go I’ve started to use Mage for handy things like running end-to-end tests (don’t yell at me… I know), and automating the build process (including code formatting, just to make sure). I ran into the problem that gopls just stops working if there’s no correlating build tag, which is recommended to use with gopls.

Example Magefile:

//go:build mage

package main

import (
    "github.com/magefile/mage/sh"
)

// Runs go mod download and then installs the binary.
func Build() error {
    if err := sh.Run("go", "mod", "download"); err != nil {
        return err
    }
    return sh.Run("go", "install", "./...")
}

Kicking off the troubleshooting journey, I first made sure I was up-to-date:

brew update &&
brew upgrade

solution

The update didn’t fix it, but man I had some ooooolllllddd packages. It turns out this is a pretty common issue (build tags not playing nice with gopls by default) and requires some manual intervention. Most of the solutions I ran into when initially Googling around where centered around VSCode, but luckily I stumbled on one for Zed.

Opening my settings.json located in ~/.config/zed I added the following entry:

"lsp": {
  "gopls": {
    "initialization_options": {
      "buildFlags": ["-tags=mage"]
    }
  }
}

That fixed it!


alp1n3
Hi, I'm alp1n3

This is a collection of my cybersecurity notes & projects.

I graduated from Dakota State University with a MS in Cyber Defense & BS in Cyber Operations. Since then I've worked as a Malware Analyst with the U.S. Army Cyber Command, and am now a Web Application Security Consultant.

I'm a big fan of open security standards for applications and workflow automation when it comes to security testing. The easier it is to identify and replicate, the more secure everyone's apps can be! My other writings and projects are scattered across the web, but can be found in the links page.

Contact me:

Signal: alp1n3.01 | Email Me | GitHub


Content licenced under CC BY-NC-ND 4.0