aboutsummaryrefslogtreecommitdiff
path: root/internal/lsp/source/references.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/lsp/source/references.go')
-rw-r--r--internal/lsp/source/references.go23
1 files changed, 8 insertions, 15 deletions
diff --git a/internal/lsp/source/references.go b/internal/lsp/source/references.go
index a9f0e1b2b..b5178e94b 100644
--- a/internal/lsp/source/references.go
+++ b/internal/lsp/source/references.go
@@ -24,22 +24,18 @@ type ReferenceInfo struct {
// References returns a list of references for a given identifier within a package.
func (i *IdentifierInfo) References(ctx context.Context) ([]*ReferenceInfo, error) {
- pkg := i.File.GetPackage(ctx)
- if pkg == nil || pkg.IsIllTyped() {
+ var references []*ReferenceInfo
+ if i.pkg == nil || i.pkg.IsIllTyped() {
return nil, fmt.Errorf("package for %s is ill typed", i.File.URI())
}
- pkgInfo := pkg.GetTypesInfo()
- if pkgInfo == nil {
- return nil, fmt.Errorf("package %s has no types info", pkg.PkgPath())
+ info := i.pkg.GetTypesInfo()
+ if info == nil {
+ return nil, fmt.Errorf("package %s has no types info", i.pkg.PkgPath())
}
-
// If the object declaration is nil, assume it is an import spec and do not look for references.
if i.decl.obj == nil {
- return []*ReferenceInfo{}, nil
+ return nil, fmt.Errorf("no references for an import spec")
}
-
- var references []*ReferenceInfo
-
if i.decl.wasImplicit {
// The definition is implicit, so we must add it separately.
// This occurs when the variable is declared in a type switch statement
@@ -51,8 +47,7 @@ func (i *IdentifierInfo) References(ctx context.Context) ([]*ReferenceInfo, erro
isDeclaration: true,
})
}
-
- for ident, obj := range pkgInfo.Defs {
+ for ident, obj := range info.Defs {
if obj == nil || obj.Pos() != i.decl.obj.Pos() {
continue
}
@@ -64,8 +59,7 @@ func (i *IdentifierInfo) References(ctx context.Context) ([]*ReferenceInfo, erro
isDeclaration: true,
})
}
-
- for ident, obj := range pkgInfo.Uses {
+ for ident, obj := range info.Uses {
if obj == nil || obj.Pos() != i.decl.obj.Pos() {
continue
}
@@ -76,6 +70,5 @@ func (i *IdentifierInfo) References(ctx context.Context) ([]*ReferenceInfo, erro
obj: obj,
})
}
-
return references, nil
}