mirror of
https://github.com/golang/go
synced 2024-11-18 10:54:40 -07:00
internal/lsp: fix references for transitive dependencies
We need to search all transitive dependencies of a package, not just its immediate imports. Fixes golang/go#38100 Change-Id: I15b4dbe226ba851691ca0c95460c3648ede32f04 Reviewed-on: https://go-review.googlesource.com/c/tools/+/227030 Run-TryBot: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Rohan Challa <rohan@golang.org>
This commit is contained in:
parent
72cf467e29
commit
226fa68e9d
@ -247,11 +247,18 @@ func qualifiedObjsAtProtocolPos(ctx context.Context, s Snapshot, fh FileHandle,
|
||||
}
|
||||
objs = append(objs, obj)
|
||||
}
|
||||
// Get all of the transitive dependencies of the search package.
|
||||
pkgs := make(map[*types.Package]Package)
|
||||
pkgs[searchpkg.GetTypes()] = searchpkg
|
||||
for _, imp := range searchpkg.Imports() {
|
||||
pkgs[imp.GetTypes()] = imp
|
||||
var addPkg func(pkg Package)
|
||||
addPkg = func(pkg Package) {
|
||||
pkgs[pkg.GetTypes()] = pkg
|
||||
for _, imp := range pkg.Imports() {
|
||||
if _, ok := pkgs[imp.GetTypes()]; !ok {
|
||||
addPkg(imp)
|
||||
}
|
||||
}
|
||||
}
|
||||
addPkg(searchpkg)
|
||||
for _, obj := range objs {
|
||||
if obj.Parent() == types.Universe {
|
||||
return nil, fmt.Errorf("%w %q", errBuiltin, obj.Name())
|
||||
|
13
internal/lsp/testdata/lsp/primarymod/references/another/another.go
vendored
Normal file
13
internal/lsp/testdata/lsp/primarymod/references/another/another.go
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
// Package another has another type.
|
||||
package another
|
||||
|
||||
import (
|
||||
other "golang.org/x/tools/internal/lsp/references/other"
|
||||
)
|
||||
|
||||
func _() {
|
||||
xes := other.GetXes()
|
||||
for _, x := range xes {
|
||||
_ = x.Y //@mark(anotherXY, "Y"),refs("Y", typeXY, anotherXY, GetXesY)
|
||||
}
|
||||
}
|
@ -4,6 +4,14 @@ import (
|
||||
references "golang.org/x/tools/internal/lsp/references"
|
||||
)
|
||||
|
||||
func GetXes() []references.X {
|
||||
return []references.X{
|
||||
{
|
||||
Y: 1, //@mark(GetXesY, "Y"),refs("Y", typeXY, GetXesY, anotherXY)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func _() {
|
||||
references.Q = "hello" //@mark(assignExpQ, "Q")
|
||||
bob := func(_ string) {}
|
||||
|
@ -3,6 +3,10 @@ package refs
|
||||
|
||||
type i int //@mark(typeI, "i"),refs("i", typeI, argI, returnI, embeddedI)
|
||||
|
||||
type X struct {
|
||||
Y int //@mark(typeXY, "Y")
|
||||
}
|
||||
|
||||
func _(_ i) []bool { //@mark(argI, "i")
|
||||
return nil
|
||||
}
|
||||
|
2
internal/lsp/testdata/lsp/summary.txt.golden
vendored
2
internal/lsp/testdata/lsp/summary.txt.golden
vendored
@ -15,7 +15,7 @@ SuggestedFixCount = 6
|
||||
DefinitionsCount = 45
|
||||
TypeDefinitionsCount = 2
|
||||
HighlightsCount = 52
|
||||
ReferencesCount = 9
|
||||
ReferencesCount = 11
|
||||
RenamesCount = 24
|
||||
PrepareRenamesCount = 7
|
||||
SymbolsCount = 3
|
||||
|
Loading…
Reference in New Issue
Block a user