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

super+click to open the Go to references popup window #1857

Open
1 task
LandazuriPaul opened this issue Oct 10, 2024 · 2 comments
Open
1 task

super+click to open the Go to references popup window #1857

LandazuriPaul opened this issue Oct 10, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@LandazuriPaul
Copy link

Extension Version

v2.32.3

Problem Statement

This extension is great and allows to explore references both ways, but the cmd+click feature is only enabled in one direction:

  • When cmd+click is applied on a symbol reference, it jumps directly to its definition, as expected.
  • When cmd+click is applied on a symbol definition, nothing happens.

Currently, we can still see the references popup by:

  • either right click > Go to References
  • or using the shift+F12 shortcut (by default)

Expected User Experience

Since this is the way VS Code behaves with all other languages, it would be great to be able to open the Go to References popup when cmd+clicking on the symbol definition.

This would greatly improve the Developer Experience when navigating TF files.

Proposal

Since the Go to References feature is already implemented in this extension (according to this issue it was introduced in 2021), it would be a matter of "linking" the cmd+click to it.

References

Help Wanted

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@LandazuriPaul LandazuriPaul added the enhancement New feature or request label Oct 10, 2024
@dbanck
Copy link
Member

dbanck commented Oct 18, 2024

Interesting feature request! Thanks for raising it. I tend to use this in Go all the time.

I'll document my brief research into this below.


When you cmd+click on a symbol reference, the editor fires a textDocument/definition request to the language server. The LS will then respond with a list of locations of definitions (if found).

When you right click > Go to References on a symbol definition, the editor will fire a textDocument/references request to the language server. The LS will then respond with a list of locations (if found).

In the Terraform extension, when you cmd+click on a symbol definition, the editor will fire a textDocument/definition request as usual, but our LS will respond with an Error for "textDocument/definition" (ID 13): [-32098] no reference origin found, because the symbol is not technically a symbol reference.

However, in the Go extension, the Go LS will not respond with an error. Instead it responds with the range of the clicked symbol:

[Trace - 15:32:45.171 PM] Sending request 'textDocument/definition - (57)'.
Params: {"textDocument":{"uri":"file:///.../scopes.go"},"position":{"line":11,"character":7}}

[Trace - 15:32:45.172 PM] Received response 'textDocument/definition - (57)' in 0ms.
Result: [{"uri":"file:///.../scopes.go","range":{"start":{"line":11,"character":1},"end":{"line":11,"character":10}}}]

This will trigger a textDocument/references request on the client for the same position. The LS will then respond with a list of locations (if found).

I wasn't able to find any information about this behavior in the LSP spec.


Proposal

  • Continue to check for reference origins on a textDocument/definition request first
  • If none are found, compute the range of the clicked symbol (turning the position into a range)
  • Respond with a simple []lsp.Location{} with a single entry for that symbol
  • Rely on the client to fire a textDocument/references request

@LandazuriPaul
Copy link
Author

Thank you very much for your response and thorough explanation @dbanck!

Your proposal definitely makes sense to me and I'm happy to help on a PR. I never collaborated on this repo or any VS Code extension, so for now I feel more like waiting for a potential draft, but once it's kicked off, I'm happy to test it, and participate on some parts of the implementation if it can be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants