I've get caught by this missing feature almost daily: when a doc link points to a selector (as in // [Foo.Bar] is a Baz), why don't we support jump-to-definition when Bar is a field?! I don't see anything in https://go.dev/doc/comment#doclinks that indicates field selectors are not allowed.

In the code, we explicitly filter to *types.Func with no explanation. I'm going to remove that filtering...

Comment From: gopherbot

Change https://go.dev/cl/696435 mentions this issue: gopls: support jump to definition for field links in comments

Comment From: IlyasYOY

Hey @findleyr,

I dug into the gopls source and found the part that’s filtering out field links: https://github.com/golang/tools/blob/477e0ab10b915acca369e11d2c353c61fb4b37ba/gopls/internal/golang/comment.go#L195-L199

The comment‑link resolver uses LookupFieldOrMethod, which can return either a *types.Func or a *types.Var (for fields). At the moment we only accept the *types.Func case, so links such as // [Foo.Bar] where Bar is a struct field never resolve.

I think the fix is simply to extend the type switch to also handle *types.Var when it represents a field. This matches the contract of LookupFieldOrMethod (see the comment in the go/types package) and would enable jump‑to‑definition for field doc‑links without affecting the existing behavior for functions.

Would you like me to open a PR with this change, or would you prefer to take a look yourself first? Happy to help either way!

Comment From: findleyr

@IlyasYOY my CL in the comment above does just that. The fix is straightforward, as you say... I just don't know why we were filtering in the first place.

Comment From: adonovan

@IlyasYOY my CL in the comment above does just that. The fix is straightforward, as you say... I just don't know why we were filtering in the first place.

See my comment in https://go.dev/cl/696435: I suspect it was my (mis)reading of the underspecified commentary in the go/doc/comment package.