Open LandazuriPaul opened 1 month ago
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.
textDocument/definition
request first[]lsp.Location{}
with a single entry for that symboltextDocument/references
requestThank 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.
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:cmd+click
is applied on a symbol reference, it jumps directly to its definition, as expected.cmd+click
is applied on a symbol definition, nothing happens.Currently, we can still see the references popup by:
right click > Go to References
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 whencmd+click
ing 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" thecmd+click
to it.References
651 : this is where the feature was requested.
Help Wanted
Community Note