Develop strategy for indexing declarations made in C / native extensions
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
This issue is being marked as stale because there was no activity in the last 2 months
As per the team discussion earlier today, we will move ahead with using RBS declarations for indexing core class (String, Integer, etc).
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.
I've updated the description with tasks related to RBS.