ruby-lsp icon indicating copy to clipboard operation
ruby-lsp copied to clipboard

Support inherited methods in definition, hover and completion

Open vinistock opened this issue 1 year ago • 2 comments

Motivation

Step towards #899

Use the linearized ancestor information from #2024 to support inherited methods for definition, hover and completion.

Implementation

  1. Changed resolve_method to linearize ancestors lazily. Then we search ancestors in order and return the first methods we return, which ensures we jump to the right method
  2. 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

vinistock avatar May 09 '24 20:05 vinistock

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?

andyw8 avatar May 10 '24 14:05 andyw8

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.

vinistock avatar May 10 '24 15:05 vinistock

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.

vinistock avatar May 30 '24 18:05 vinistock