Skip to content

Commit 8694a4a

Browse files
committed
internal/lsp/source: don't find possible interface references to types
In CL 259998 we added the ability to find calls to methods through interfaces. That included very common interfaces like Stringer, which we judged unfortunate but possibly acceptable. We didn't consider the behavior when searching for references to a type. When searching for references to a type that happens to be a Stringer, the user almost certainly doesn't want to see all uses of the Stringer interface. Don't consider interface references to types. No tests; I don't think this is worth a regtest and the marker tests can't check a negative AFAIK. Fixes golang/go#42350. Change-Id: I0b929d8743f7f0b4e7543e8d35921a7cf3784bf5 Reviewed-on: https://go-review.googlesource.com/c/tools/+/268462 Trust: Heschi Kreinick <[email protected]> Run-TryBot: Heschi Kreinick <[email protected]> gopls-CI: kokoro <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 78b1585 commit 8694a4a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

internal/lsp/source/references.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ func references(ctx context.Context, snapshot Snapshot, qos []qualifiedObject, i
127127
}
128128
}
129129

130-
if includeInterfaceRefs {
130+
// When searching on type name, don't include interface references -- they
131+
// would be things like all references to Stringer for any type that
132+
// happened to have a String method.
133+
_, isType := declIdent.Declaration.obj.(*types.TypeName)
134+
if includeInterfaceRefs && !isType {
131135
declRange, err := declIdent.Range()
132136
if err != nil {
133137
return nil, err

0 commit comments

Comments
 (0)