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

Develop strategy for indexing declarations made in C / native extensions

Open vinistock opened this issue 1 year ago • 4 comments

We currently index all Ruby files bundled with the Ruby installation, but that doesn't cover all declarations available. Core classes like Array or String are defined in C and thus we miss those declarations. We also miss gem declarations that are made in native extensions.

We need to consider the performance, accuracy and maintenance costs of a few different approaches to decide how we're going to handle this:

  • RDoc uses regexes to extract declarations from C files directly. The problem with that is that the C files aren't always included in Ruby installations, so those files may not be there
  • We could read the RDoc index objects, but that is also dependent on the installation since Ruby may be installed without documentation
  • We can read and process RBS files. However, we'll miss gems that don't include RBS signatures
  • We could also bundle empty declarations for the Core library in Ruby files, which is essentially what RBS signatures are. This would involve some manual work to create these files and we would need to ensure they are up to date based on Ruby versions
  • Some other idea?

### Tasks
- [x] [Index Core classes using RBS](https://github.com/Shopify/ruby-lsp/pull/2132)
- [x] [Extract includes, prepends and extends and insert those as well](https://github.com/Shopify/ruby-lsp/pull/2148)
- [ ] Index Core methods using RBS https://github.com/Shopify/ruby-lsp/pull/2157
- [ ] Index Core constants using RBS
- [ ] [Provide basic RBS support](https://github.com/Shopify/ruby-lsp/issues/1206)
- [ ] Index return types using RBS

vinistock avatar Jan 29 '24 18:01 vinistock

This issue is being marked as stale because there was no activity in the last 2 months

github-actions[bot] avatar Mar 30 '24 12:03 github-actions[bot]

As per the team discussion earlier today, we will move ahead with using RBS declarations for indexing core class (String, Integer, etc).

andyw8 avatar Jun 03 '24 17:06 andyw8

This branch includes a super simple script for how to retrieve declarations which I paired on with Soutaro during RubyKaigi.

My understanding of it is that we can basically just iterate over the declarations that the code returns and then build our index's entries and push them.

vinistock avatar Jun 03 '24 17:06 vinistock

I've updated the description with tasks related to RBS.

andyw8 avatar Jun 06 '24 19:06 andyw8