Shopify / ruby-lsp-rails

A Ruby LSP addon for Rails
https://shopify.github.io/ruby-lsp-rails/
MIT License
515 stars 21 forks source link

Small issue with Go to Definition for callbacks #371

Open andyw8 opened 2 months ago

andyw8 commented 2 months ago

When using Go To Definition on code such as:

before_save :foo

It works fine on the callback name before_save, but try it on the symbol name :foo fails. Both should jump to the foo method definition.

I don't think it behaved like that previously, so this may be a regression.

vinistock commented 2 months ago

This is because of https://github.com/Shopify/ruby-lsp/pull/1981. We need to re-think the way we locate nodes as targets and how addons can accurately declare the ones they are interested in.

To correctly identify targets, there are many cases where you need two layers of information: a surrounding parent node (like the before_save call node) and the symbol argument.

Currently, if you register for call nodes, you can identify the callback properly, but it assigns the go to definition behaviour to the method call identifier. However, if you register for handling symbol nodes (or arguments node), then you don't have access to the surrounding call node.

I think we need to create a specialized Prism::Dispatcher that not only allows you to register for events, but keeps track of the "current context" of where a node is inserted.

andyw8 commented 1 month ago

For the above: https://github.com/Shopify/ruby-lsp/issues/2036