Support inherited methods in definition, hover and completion
Motivation
Step towards #899
Use the linearized ancestor information from #2024 to support inherited methods for definition, hover and completion.
Implementation
- Changed
resolve_methodto linearize ancestors lazily. Then we search ancestors in order and return the first methods we return, which ensures we jump to the right method - Adapted completion to consider all ancestors when filtering possible methods being invoked
Automated Tests
Added tests.
https://github.com/Shopify/ruby-lsp/assets/18742907/ad6ff4e5-33b2-4f79-ac88-93f0846bbdf1
So this should also allow us to improve Definition in ruby-lsp-rails, e.g. so that a callback method can be found even if defined in a parent controller?
Yes. And this will happen automatically, by making resolve_method smarter, it will return more accurate results without any changes needed in the Rails addon.
Can't we also handle go to and hover to super now?
We can, but we need the work that @andyw8 is doing here https://github.com/Shopify/ruby-lsp/pull/2099 so that we know which method we're currently inside of.