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

huangapple go评论90阅读模式
英文:

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警告:

找不到打开文件/Users/kurtpeek/go/src/github.com/Shopify/sarama/functional_consumer_group_test.go的包:<nil>。
如果此文件包含构建标签,请尝试将“-tags=<build tag>”添加到您的gopls“buildFlags”配置中(请参阅(https://github.com/golang/tools/blob/master/gopls/doc/settings.md#buildflags-string)。
否则,请参阅故障排除指南以获取帮助(https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md)。go list

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

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

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

> gopls check functional_consumer_group_test.go 
gopls: 未返回任何包:packages.Load 错误

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

//go:build functional
// +build functional

然而,我不清楚如何修改我的VS Code settings.json以通过这些构建约束。有人知道如何使这个功能测试能够构建吗?

英文:

I've checked out the main branch of github.com/Shopify/sarama (at commit 947343309601b4eb3c2fa3e7d15d701b503dd491
) but I notice that in VS Code I can't "Go to definition" as usual. If I hover over the package name sarama in functional_consumer_group_test.go, I get the linter warning

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

(See screenshot below).

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

From the command line, if I try to gopls that file, I get a similar error:

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

I suspect this has something to do with the build constraints (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

It's not clear to me, however, how to modify my VS Code settings.json to pass these build constraints. Does anyone know how to get this functional test to build?

答案1

得分: 6

根据 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在该文件中可以正常工作。

英文:

Following https://www.ryanchapin.com/configuring-vscode-to-use-build-tags-in-golang-to-separate-integration-and-unit-test-code/, I had to create a .vscode/settings.json file in the repository's root directory and add the following contents:

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

Now VS Code works like normal in that file:

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

答案2

得分: 1

你尝试过go clean -cache吗?

这个链接可能会有帮助:
https://github.com/golang/go/issues/42353

英文:

Have you tried go clean -cache?

And this link may help:
https://github.com/golang/go/issues/42353

答案3

得分: 0

这对我有用!通过将其添加到.vscode/settings.json中:

{
    "gopls.env": {
        "GOFLAGS": "-tags=test"
    }
}
英文:

This worked for me!
by adding it in .vscode/settings.json

{
    "gopls.env": {
        "GOFLAGS": "-tags=test"
    }
}

huangapple
  • 本文由 发表于 2022年4月8日 08:23:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/71790348.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定