@@ -109,10 +109,13 @@ func references(ctx context.Context, snapshot Snapshot, qos []qualifiedObject, i
109
109
searchPkgs = append (searchPkgs , qo .pkg )
110
110
for _ , pkg := range searchPkgs {
111
111
for ident , obj := range pkg .GetTypesInfo ().Uses {
112
- if obj != qo .obj {
113
- // If ident is not a use of qo.obj, skip it, with one exception: uses
114
- // of an embedded field can be considered references of the embedded
115
- // type name.
112
+ // For instantiated objects (as in methods or fields on instantiated
113
+ // types), we may not have pointer-identical objects but still want to
114
+ // consider them references.
115
+ if ! equalOrigin (obj , qo .obj ) {
116
+ // If ident is not a use of qo.obj, skip it, with one exception:
117
+ // uses of an embedded field can be considered references of the
118
+ // embedded type name
116
119
if ! includeEmbeddedRefs {
117
120
continue
118
121
}
@@ -167,6 +170,13 @@ func references(ctx context.Context, snapshot Snapshot, qos []qualifiedObject, i
167
170
return references , nil
168
171
}
169
172
173
+ // equalOrigin reports whether obj1 and obj2 have equivalent origin object.
174
+ // This may be the case even if obj1 != obj2, if one or both of them is
175
+ // instantiated.
176
+ func equalOrigin (obj1 , obj2 types.Object ) bool {
177
+ return obj1 .Pkg () == obj2 .Pkg () && obj1 .Pos () == obj2 .Pos () && obj1 .Name () == obj2 .Name ()
178
+ }
179
+
170
180
// interfaceReferences returns the references to the interfaces implemented by
171
181
// the type or method at the given position.
172
182
func interfaceReferences (ctx context.Context , s Snapshot , f FileHandle , pp protocol.Position ) ([]* ReferenceInfo , error ) {
0 commit comments