mirror of
https://github.com/golang/go
synced 2024-11-18 16:54:43 -07:00
internal/lsp: only search for references in reverse dependencies
Updates golang/go#35597 Change-Id: I78e83ad0ee1ae3c59a7452c467b3abd34587a845 Reviewed-on: https://go-review.googlesource.com/c/tools/+/208657 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
89d49d945a
commit
a911d9008d
2
internal/lsp/cache/snapshot.go
vendored
2
internal/lsp/cache/snapshot.go
vendored
@ -94,7 +94,7 @@ func (s *snapshot) PackageHandles(ctx context.Context, f source.File) ([]source.
|
||||
cphs = results
|
||||
}
|
||||
if len(cphs) == 0 {
|
||||
return nil, errors.Errorf("no CheckPackageHandles for %s", f)
|
||||
return nil, errors.Errorf("no CheckPackageHandles for %s", f.URI())
|
||||
}
|
||||
return cphs, nil
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ import (
|
||||
"go/types"
|
||||
|
||||
"golang.org/x/tools/go/types/objectpath"
|
||||
"golang.org/x/tools/internal/lsp/telemetry"
|
||||
"golang.org/x/tools/internal/telemetry/log"
|
||||
"golang.org/x/tools/internal/telemetry/trace"
|
||||
errors "golang.org/x/xerrors"
|
||||
)
|
||||
@ -73,12 +75,22 @@ func (i *IdentifierInfo) References(ctx context.Context) ([]*ReferenceInfo, erro
|
||||
var searchpkgs []Package
|
||||
if i.Declaration.obj.Exported() {
|
||||
// Only search all packages if the identifier is exported.
|
||||
// TODO(matloob): This only needs to look into reverse-dependencies.
|
||||
// Avoid checking types of other packages.
|
||||
searchpkgs = i.Snapshot.KnownPackages(ctx)
|
||||
} else {
|
||||
searchpkgs = []Package{i.pkg}
|
||||
for _, id := range i.Snapshot.GetReverseDependencies(i.pkg.ID()) {
|
||||
cph, err := i.Snapshot.PackageHandle(ctx, id)
|
||||
if err != nil {
|
||||
log.Error(ctx, "References: no CheckPackageHandle", err, telemetry.Package.Of(id))
|
||||
continue
|
||||
}
|
||||
pkg, err := cph.Check(ctx)
|
||||
if err != nil {
|
||||
log.Error(ctx, "References: no Package", err, telemetry.Package.Of(id))
|
||||
continue
|
||||
}
|
||||
searchpkgs = append(searchpkgs, pkg)
|
||||
}
|
||||
}
|
||||
// Add the package in which the identifier is declared.
|
||||
searchpkgs = append(searchpkgs, i.pkg)
|
||||
for _, pkg := range searchpkgs {
|
||||
for ident, obj := range pkg.GetTypesInfo().Uses {
|
||||
if obj == nil || !(sameObj(obj, i.Declaration.obj)) {
|
||||
|
Loading…
Reference in New Issue
Block a user