-
-
Notifications
You must be signed in to change notification settings - Fork 673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editor support broken for gazelle
generated go_test
for packages containing both internal and external tests
#3015
Comments
Does |
Yes. |
@rohitagarwal003 I tried your setup with a barebones VSCode config and it seems to be working fine. Do you have anything custom on your settings.json? (Both workspace and global) |
I added my workspace's Here's my global settings.json:
Can you make sure you still don't see the error after you Reload Window or restart the editor with this BUILD file etc.? |
After adding the |
Just in case it adds more context, I also ran into this and in my case this is the output of
And the JSON payload that comes with it: {"NotHandled":false,"Sizes":{"WordSize":8,"MaxAlign":8},"Packages":[]} |
I've done a little more digging and found something else: This query checks for load("@io_bazel_rules_go//go:def.bzl", real_go_test = "go_test")
def go_test(name, race = "on", **kwargs):
"""The same as upstream go_test but the race detector is on by default."""
real_go_test(name, race = race, **kwargs) By adding {
"NotHandled": false,
"Sizes": {
"WordSize": 8,
"MaxAlign": 8
},
"Packages": []
} |
Follow-up to my above comment: I found the other place where diff --git a/go/tools/gopackagesdriver/aspect.bzl b/go/tools/gopackagesdriver/aspect.bzl
index de9eacd2..7e1ac2dc 100644
--- a/go/tools/gopackagesdriver/aspect.bzl
+++ b/go/tools/gopackagesdriver/aspect.bzl
@@ -98,7 +98,7 @@ def _go_pkg_info_aspect_impl(target, ctx):
# the test source files are there. Then, create the pkg json file directly. Only
# do that for direct dependencies that are not defined as deps, and use the
# importpath to find which.
- if ctx.rule.kind == "go_test":
+ if ctx.rule.kind in ["go_test", "go_transition_test"]:
deps_targets = [
dep[GoArchive].data.importpath
for dep in ctx.rule.attr.deps
diff --git a/go/tools/gopackagesdriver/bazel.go b/go/tools/gopackagesdriver/bazel.go
index 881ccc70..c2e5290c 100644
--- a/go/tools/gopackagesdriver/bazel.go
+++ b/go/tools/gopackagesdriver/bazel.go
@@ -138,15 +138,13 @@ func (b *Bazel) Query(ctx context.Context, args ...string) ([]string, error) {
if err != nil {
return nil, fmt.Errorf("bazel query failed: %w", err)
}
- return strings.Split(strings.TrimSpace(output), "\n"), nil
-}
-func (b *Bazel) QueryLabels(ctx context.Context, args ...string) ([]string, error) {
- output, err := b.run(ctx, "query", args...)
- if err != nil {
- return nil, fmt.Errorf("bazel query failed: %w", err)
+ trimmedOutput := strings.TrimSpace(output)
+ if len(trimmedOutput) == 0 {
+ return nil, nil
}
- return strings.Split(strings.TrimSpace(output), "\n"), nil
+
+ return strings.Split(trimmedOutput, "\n"), nil
}
func (b *Bazel) WorkspaceRoot() string {
diff --git a/go/tools/gopackagesdriver/bazel_json_builder.go b/go/tools/gopackagesdriver/bazel_json_builder.go
index 14f00188..c1e3ca29 100644
--- a/go/tools/gopackagesdriver/bazel_json_builder.go
+++ b/go/tools/gopackagesdriver/bazel_json_builder.go
@@ -35,7 +35,7 @@ func (b *BazelJSONBuilder) fileQuery(filename string) string {
fp, _ := filepath.Rel(b.bazel.WorkspaceRoot(), filename)
filename = fp
}
- return fmt.Sprintf(`kind("go_library|go_test", same_pkg_direct_rdeps("%s"))`, filename)
+ return fmt.Sprintf(`kind("go_library|go_test|go_transition_test", same_pkg_direct_rdeps("%s"))`, filename)
}
func (b *BazelJSONBuilder) packageQuery(importPath string) string { For others looking to fix this, you should just be able to use this as a |
What version of rules_go are you using?
v0.29.0
What version of gazelle are you using?
v0.24.0
What version of Bazel are you using?
4.2.1
Does this issue reproduce with the latest releases of all the above?
I am using the latest versions already.
What operating system and processor architecture are you using?
Intel Mac
Any other potentially useful information about your toolchain?
I have created the initial setup here: https://gist.github.com/rohitagarwal003/d9087ca9f87271b1b4f1d392a9dea593.
If you download all those files in a directory named
mypkg
and runbazel run //:gazelle
from there, the updatedBUILD.bazel
will not work correctly with VSCode.BUILD.bazel
file generated by gazelle that doesn't work with VSCodeError:
package mypkg_test; expected mypkg compiler(MismatchedPkgName)
BUILD.bazel
file that does workcc @steeve @linzhp
The text was updated successfully, but these errors were encountered: