Search code examples
goneovimgopls

gopls stops working if build tags are added


No packages found for open file /home/user/projects/ws-client/request/client_connection_test.go. This file may be excluded due to its build tags; try adding "-tags=" to your gopls "buildFlags" configuration See the documentation for more information on working with build tags: https://github.com/golang/tools/blob/master/gopls/doc/settings.md#buildflags-string.

I use neovim with gopls lsp. The solution for this problem provided by the error above only works for vscode.

I have tried adding tags to other projects of mine, it is not code related, the error persists.

// +build connection

I have this simple tag


Solution

  • Did not find a solution for local projects. But you can define all build flags in neovim config file:

    local lspconfig = require'lspconfig'
    lspconfig.gopls.setup{
      settings = {
        gopls =  {
            buildFlags =  {"-tags=integration some-other-tags..."}
        }
      }
    }
    

    Not the best solution but at least it works