You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does this issue reproduce with the latest releases of all the above?
Yes.
What operating system and processor architecture are you using?
amd64
What did you do?
Write some code which calls an external library function or type.
Go to definition of that external function or type.
Go to definition of something that is used within that external function or type, which would lead us to going to some other type or function within the same package.
What did you expect to see?
I can successfully jump to a different function.
What did you see instead?
The gopackagesdriver fails with (the filepath is taken from my editor when I go to definition once):
Looking at the code, I think that this part of the code may be extended to handle third-party dependencies, but I am not sure if there is a more elegant approach:
diff --git a/go/tools/gopackagesdriver/bazel_json_builder.go b/go/tools/gopackagesdriver/bazel_json_builder.go
index 14f00188..ac5cc878 100644
--- a/go/tools/gopackagesdriver/bazel_json_builder.go
+++ b/go/tools/gopackagesdriver/bazel_json_builder.go
@@ -19,6 +19,7 @@ import (
"fmt"
"path/filepath"
"strings"
+ "regexp"
)
type BazelJSONBuilder struct {
@@ -26,16 +27,25 @@ type BazelJSONBuilder struct {
requests []string
}
+var externalRe = regexp.MustCompile(".*/external/([^/]+)/(.*)/([^/]+.go)")
+
const (
RulesGoStdlibLabel = "@io_bazel_rules_go//:stdlib"
)
func (b *BazelJSONBuilder) fileQuery(filename string) string {
+ var label string
if filepath.IsAbs(filename) {
- fp, _ := filepath.Rel(b.bazel.WorkspaceRoot(), filename)
- filename = fp
+ label, _ = filepath.Rel(b.bazel.WorkspaceRoot(), filename)
}
- return fmt.Sprintf(`kind("go_library|go_test", same_pkg_direct_rdeps("%s"))`, filename)
+
+ if matches := externalRe.FindStringSubmatch(filename); len(matches) == 4 {
+ // if filepath is for a third party lib, we need to know, what external
+ // library this file is part of.
+ label = fmt.Sprintf("@%s//%s:%s", matches[1], matches[2], matches[3])
+ }
+
+ return fmt.Sprintf(`kind("go_library|go_test", same_pkg_direct_rdeps("%s"))`, label)
}
func (b *BazelJSONBuilder) packageQuery(importPath string) string {
The text was updated successfully, but these errors were encountered:
What version of rules_go are you using?
0.29.0
What version of gazelle are you using?
0.24.0
What version of Bazel are you using?
4.2.1
Does this issue reproduce with the latest releases of all the above?
Yes.
What operating system and processor architecture are you using?
amd64
What did you do?
What did you expect to see?
I can successfully jump to a different function.
What did you see instead?
The
gopackagesdriver
fails with (the filepath is taken from my editor when I go to definition once):Potential fix
Looking at the code, I think that this part of the code may be extended to handle third-party dependencies, but I am not sure if there is a more elegant approach:
The text was updated successfully, but these errors were encountered: