-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: feature: alternative 'references' query that reports implied references to struct fields (etc) #66356
Comments
This is interesting. We could definitely match this reference, and I think it would be useful. We should experiment with doing this. Tentatively putting in the v0.17.0 milestone, as v0.16 is filling up. CC @adonovan |
FWIW the inlay hints show the field names so the info is already wired in somewhere :) |
By design gopls' references algorithm reports the locations of identifiers that reference a given symbol, whereas in your example there is no field identifier. So the operation is working as intended. The algorithm does not report all of the many kinds of implicit references that arise in other places, which, in addition to your example, include references:
We have had other discussions about and requests for different kinds of 'references' queries, that are not invoked through the usual LSP 'references' operation. For example: show all the places where this struct field or slice element is accessed, even implicitly. It is easy to define the queries as code actions ("Source actions..." in VS Code); the main challenge is the lack of a way to communicate to the client that the result of this operation is a list of annotated source locations that should be displayed using essentially the same UI elements as a true references query. I think we should lobby for the inclusion of such a feature into LSP. |
Thank you for the thorough reply. I understand your point and agree with most examples, but don't agree using "identifier is spelled-out" should be a hard rule, and think each case is worth examining from the point of "does this bring value to the user" and "is that value worth the work/complexity". Maybe the intended use case can motivate some rule bending? It is finding all assignments to a field, which ATM cannot be easily done as you need to check all field references + all struct references. And doing that second search is not intuitive at all IMO.
I agree, having more than one type of symbol search would definitely be useful. |
Many users would be surprised if they asked to see references to "foo" and the result included a line of text that doesn't contain foo. A better UX for this feature would be a query report that annotates the location with a comment such as "implicit selection of field foo". But again that requires LSP changes. |
At least in that case you're presented with information so you ask yourself a question. The current situation doesn't confront you to anything and you're very likely to miss some instances of what you're looking for. Anyways feel free to close or rescope to something else if you don't plan on implementing what I opened the issue for originally. |
I've filed microsoft/language-server-protocol#1911 upstream for LSP support for generalized reference queries. |
gopls version
gopls 0.14.2 from nixpkgs:
/nix/store/1spk3fici3mrggasy75w31y0yvqlrk08-gopls-0.14.2/bin/gopls
go env
What did you do?
What did you see happen?
Seaching for references of
field
doesn't detect theT
literal.What did you expect to see?
A list with the literal included.
Editor and settings
N/A
Logs
No response
The text was updated successfully, but these errors were encountered: