gopls 对 github.com/Shopify/sarama 返回错误“gopls:没有返回包:packages.Load 错误”

Kur*_*eek 9 go sarama

我已经检查了(at commit )main的分支,但我注意到在 VS Code 中我无法像往常一样“转到定义”。如果我将鼠标悬停在 中的包名称上,我会收到 linter 警告github.com/Shopify/sarama947343309601b4eb3c2fa3e7d15d701b503dd491 saramafunctional_consumer_group_test.go

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
Run Code Online (Sandbox Code Playgroud)

(参见下面的屏幕截图)。

在此输入图像描述

从命令行,如果我尝试gopls该文件,我会收到类似的错误:

> gopls check functional_consumer_group_test.go 
gopls: no packages returned: packages.Load error
Run Code Online (Sandbox Code Playgroud)

我怀疑这与该文件中的构建约束( https://pkg.go.dev/cmd/go#hdr-Build_constraints )有关,来自https://github.com/Shopify/sarama/blob/947343309601b4eb3c2fa3e7d15d701b503dd491 /function_consumer_group_test.go#L1-L2

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
Run Code Online (Sandbox Code Playgroud)

然而,我不清楚如何修改 VS Codesettings.json以通过这些构建约束。有谁知道如何构建这个功能测试?

Kur*_*eek 7

在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",
}
Run Code Online (Sandbox Code Playgroud)

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

在此输入图像描述