gopls returns github 的错误 "gopls: no packages returned: packages.Load error"。com/Shopify/sarama

gopls returns the error "gopls: no packages returned: packages.Load error" for github.com/Shopify/sarama

我已经检查了 github.com/Shopify/saramamain 分支(提交 947343309601b4eb3c2fa3e7d15d701b503dd491 ),但我注意到在 VS Code 中我不能像往常一样“转到定义” .如果我将鼠标悬停在 functional_consumer_group_test.go 中的包名称 sarama 上,我会收到 linter 警告

No packages found for open file /Users/kurtpeek/go/src/github.com/Shopify/sarama/functional_consumer_group_test.go: <nil>.
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).
Otherwise, see the troubleshooting guidelines for help investigating (https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md).go list

(见下方截图)。

从命令行,如果我尝试 gopls 那个文件,我会得到一个类似的错误:

> gopls check functional_consumer_group_test.go 
gopls: no packages returned: packages.Load error

我怀疑这与构建约束有关 (https://pkg.go.dev/cmd/go#hdr-Build_constraints) in that file, from https://github.com/Shopify/sarama/blob/947343309601b4eb3c2fa3e7d15d701b503dd491/functional_consumer_group_test.go#L1-L2,

//go:build functional
// +build functional

但是,我不清楚如何修改我的 VS 代码 settings.json 以通过这些构建约束。有谁知道如何构建此功能测试?

https://www.ryanchapin.com/configuring-vscode-to-use-build-tags-in-golang-to-separate-integration-and-unit-test-code/ 之后,我必须在存储库的根目录中创建一个 .vscode/settings.json 文件并添加以下内容:

{
    "go.buildFlags": [
        "-tags=functional"
    ],
    "go.testTags": "functional",
}

现在 VS Code 在该文件中正常工作:

你试过了吗go clean -cache

而这个 link 可能会有所帮助: https://github.com/golang/go/issues/42353