Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: 'references' on embedded field returns refs only to field, not type #63521

Open
adonovan opened this issue Oct 12, 2023 · 5 comments
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

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.

@adonovan 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
@gopherbot gopherbot added this to the Unreleased milestone Oct 12, 2023
@muirdm
Copy link

muirdm commented Oct 13, 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?

@adonovan
Copy link
Member Author

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.

@muirdm
Copy link

muirdm commented Oct 13, 2023

any way that 'references' can return a hint along with the smaller result

Could gopls issue a notification or whatever that shows up for the user?

@adonovan
Copy link
Member Author

Good question. We should experiment.

@findleyr
Copy link
Contributor

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.

@findleyr findleyr modified the milestones: Unreleased, gopls/backlog Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants