Open Earlopain opened 5 months ago
Gave this one a quick shot but I quickly realized that my simple suggestion above doesn't really cut it. Addons would have to duplicate a large chunk of what DeclarationListener
does which I don't think would be particularly great, plus it wouldn't benefit from fixes/enhancements from ruby-lsp in that area.
We want to allow addons to also contribute to the index by providing another extension point in the indexing mechanism, which is the way to move forward with support for stuff like this. We will be exploring it soon.
Essentially, we will need to allow addons to register for handling DSLs during indexing and then invoke the addons exactly in that spot in on_call_node_enter
with enough context to make it useful.
Looking forward to that. Rails provides some methods where this would be very useful (like enum declarations) and with the index continuosly getting better the cases where it doesn't work start to feel weird (this is a compliment 😄)
Yeah, definitely! The idea is that addons will have the ability to bake the logic for configurations style DSLs, improving the knowledge in the index.
A good example is association methods. When we find a belongs_to :user
, we know which methods have to be inserted in the index.
@vinistock are you thinking this would be a new kind of Entry
, e.g. Entry::DynamicMethod
?
Ideally not because then everything else should work by default (resolution, completion candidates, etc). Do you see a reason for having a separate entry for it?
I've repurposed the issue for general metaprogramming stuff. scope
is one I also remembered existing, and two from activestorage. Surely there are more, feel free to add.
Add-ons can now contribute to the index: https://shopify.github.io/ruby-lsp/add-ons.html#enhancing-features
I make occasional use of
delegate
in my code, which is rails specific: https://api.rubyonrails.org/classes/Module.html#method-i-delegateAre addons able to contribute to the index? I don't think this addon currently does that. From the code in
ruby-lsp
,DeclarationListener.on_call_node_enter
seems like the place where it handles buildin things like that.Perhaps addons should to be able to hook into
index_single
to register a dispatcher of their own and contribute to the index?