Sublime Forum

Can't set gopls buildFlags in project settings

#1

I have a Go project that uses build tags.

When I run gopls it gives this warning:

If this file contains build tags, try adding "-tags=<build tag>" to your gopls "buildFlags" configuration (see (https://github.com/golang/tools/blob/master/gopls/doc/settings.md#buildflags-string).

Which is fine, that page says that I can add “-tags=wireinject” to the build.buildFlags setting.

After some experimentation, adding to the LSP config as follows works:

"gopls": {
    "enabled": true,
    "command": ["gopls"],
    "selector": "source.go",
    "initializationOptions": {
        "experimentalWorkspaceModule": false,
        "buildFlags": ["-tags=wireinject"],
    },
},

Note the bare “buildFlags”, rather than what I expected which was “build.buildFlags”.

However I can’t get it to work in project settings applied to the .sublime-project file.
From the comments on Project-specific package settings? I thought this would work but it doesn’t:

"settings": {
    "LSP": {
        "gopls": {
            "initializationOptions": {
                "buildFlags": ["-tags=wireinject"],
            },
        }
    }
}

Any help appreciated, thanks.

0 Likes

#2

I believe the initializationOptions are overridden wholesale when defined in a project, but don’t quote me on this as I am not one hundred percent sure of this. Is the experimentalWorkspaceModule option important as well? Have you tried putting experimentalWorkspaceModule in the project override as well?

Note that you can look at what the actual, resolved, initializationOptions are when inspecting the RPC traffic in the (LSP) log panel.

0 Likes

#3

experimentalWorkspaceModule defaults to false, so I just removed it with no adverse effect.

It turns out I erred above, and the project settings actually do work. I think I missed reloading the
folder as a project.

Anyway thanks for your help.

0 Likes