scalameta / metals

Scala language server with rich IDE features 🚀
https://scalameta.org/metals/
Apache License 2.0
2.07k stars 323 forks source link

Fallback to "show usages" from "Goto definition" if reference is definition itself. #755

Closed rossoha closed 5 years ago

rossoha commented 5 years ago

Is your feature request related to a problem? Please describe. It's not related to a problem.

Describe the solution you'd like Simply feature is a "fallback" for "go to" in cases when you click root definition itself. Instead of ignoring this request (cause it's a definition but not a reference), it would be nice to show a list of usages/references ("peek references" in VSCode is an example).

Describe alternatives you've considered no, so far

Additional context

Search terms: "find usages", "show usages", "peek references"

gabro commented 5 years ago

👍 on this. @olafurpg proposed exactly the same thing in an offline discussion some time ago.

We can't properly fall back to a different request (i.e. convert textDocument/definition to textDocument/references) because LSP doesn't have a mechanism to do it.

However, it should be possible to implement this by responding to the textDocument/definition request with an array of Location which represent the references instead of the actual definition.

Since this is a bit of a stretch over the LSP spec, my only concern would be to make sure editors handle the array of Location correctly (e.g., make sure no editors take shortcuts like showing the first result or something like that)

olafurpg commented 5 years ago

Thank you for reporting! @tanishiking, @tgodzik and me looked into implementing this feature at the Spree in Lausanne today and we should be able to support this feature in the near future :)

tgodzik commented 5 years ago

Fixed in https://github.com/scalameta/metals/pull/775