When working on *.go
files with build tags defined, I get undeclared name
errors. It appears as thought I can specify gopls settings using the below structure, but the problem remains which makes me believe they aren’t being applied properly.
nvim_lsp.gopls.setup{
on_attach = on_attach,
capabilities = capabilities,
filetypes = { "go", "gomod" },
root_dir = util.root_pattern("go.mod", ".git"),
settings = {
gopls = {
buildFlags = {"-tags=integration"},
}
},
}
I have the following directory, where I’ve been able to reproduce the problem:
.
├── go.mod
└── internal
└── stringhelpers
├── strings_main_test.go
└── strings_test.go
// strings_main_test.go
// +build integration
package stringhelpers_test
import "testing"
func TestMain(m *testing.M) {
m.Run()
}
func getString() string {
return "test-"
}
// strings_test.go
// +build integration
package stringhelpers_test
import (
"strings"
"testing"
)
func TestHasPrefix(t *testing.T) {
if strings.HasPrefix("test-123", getString()) != true {
t.Fail()
}
}
When editing internal/stringhelpers/strings_test.go
, I see the following error:
When I remove the build tags, the problem goes away.
Is there a way to capture whether the buildFlag is being set properly?