Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods generated through metaprogramming to the index #403

Open
10 tasks
Earlopain opened this issue Jun 30, 2024 · 8 comments
Open
10 tasks

Add methods generated through metaprogramming to the index #403

Earlopain opened this issue Jun 30, 2024 · 8 comments

Comments

@Earlopain
Copy link
Contributor

Earlopain commented Jun 30, 2024

I make occasional use of delegate in my code, which is rails specific: https://api.rubyonrails.org/classes/Module.html#method-i-delegate

Are 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?

Tasks

@Earlopain
Copy link
Contributor Author

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.

@vinistock
Copy link
Member

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.

@Earlopain
Copy link
Contributor Author

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 😄)

@vinistock
Copy link
Member

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.

@andyw8
Copy link
Contributor

andyw8 commented Jul 2, 2024

@vinistock are you thinking this would be a new kind of Entry, e.g. Entry::DynamicMethod ?

@vinistock
Copy link
Member

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?

@Earlopain Earlopain changed the title Add methods generated through delegate to the index Add methods generated through metaprogramming to the index Jul 3, 2024
@Earlopain
Copy link
Contributor Author

Earlopain commented Jul 3, 2024

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.

@andyw8
Copy link
Contributor

andyw8 commented Oct 23, 2024

Add-ons can now contribute to the index: https://shopify.github.io/ruby-lsp/add-ons.html#enhancing-features

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants