You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The form struct {T} is unique in the Go grammar in that the identifier T is both a reference (to a type) and a declaration (of a field). When gopls responds to a references query on the identifier, it chooses arbitrarily to the interpret it as a field, and does not report references to the type. I think it should report the union of both.
The text was updated successfully, but these errors were encountered:
adonovan
added
gopls
Issues related to the Go language server, gopls.
Tools
This label describes issues relating to any tools in the x/tools repository.
labels
Oct 12, 2023
If the embedded type is popular (e.g. "bytes.Buffer"), you could lose the field references in the sea of type references. Maybe we can keep the field references before type references in the results? Or is there some other way for the LSP client to distinguish them?
That's a good point. There's a related situation in renaming where an embedded field couples a field and a type: renaming a reference to the the type must of course rename the field, but renaming a reference to the field probably shouldn't rename the type as well. So, the renaming tool gives an error hinting that, if the bigger renaming was intended, it should be initiated on a reference to the type. But I don't see any way that 'references' can return a hint along with the smaller result. Ordering field refs before type refs is all we can hope for; or leaving things as they are.
Ordering field refs before type refs is all we can hope for; or leaving things as they are.
I'm not sure if all clients preserve the ordering of references, though I think most do.
I do think that this is inconsistent behavior, but probably not a high priority.
The form
struct {T}
is unique in the Go grammar in that the identifier T is both a reference (to a type) and a declaration (of a field). When gopls responds to a references query on the identifier, it chooses arbitrarily to the interpret it as a field, and does not report references to the type. I think it should report the union of both.The text was updated successfully, but these errors were encountered: