-
Notifications
You must be signed in to change notification settings - Fork 172
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
Support on_call_node_leave
events in index enhancement
#2754
Conversation
This matches the naming of Prism listener's events. But more importantly, allows adding a new `on_call_node_leave` method.
We'll need to also update |
d2f60ea
to
cfd9a01
Compare
Done 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
@@ -324,7 +326,7 @@ module RubyLsp | |||
class Addon < ::RubyLsp::Addon | |||
def activate(global_state, message_queue) | |||
# Register the enhancement as part of the indexing process | |||
@index.register_enhancement(MyIndexingEnhancement.new) | |||
@index.register_enhancement(MyIndexingEnhancement.new(@index)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed when updating ruby-lsp-rails in Shopify/ruby-lsp-rails#495 that it's a bit odd to pass @index
to @index
. What if we change this so that we just pass the class, i.e. @index.register_enhancement(MyIndexingEnhancement)
, and let register_enhancement
instantiate it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that but it means addon authors will lose the ability to customize their enhancements' constructor and the data it could hold.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it odd to pass the index?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the basic case it seems like unnecessary argument passing, when you could do something like:
@index.register_enhancement(MyIndexingEnhancement)
with
def register_enhancement(enhancement_class)
@enhancements << enhancement_class.new(self)
end
but as @st0012 says, it does allow for more flexibility.
Motivation
For addons to build data structure that mimic scopes defined by DSLs (e.g. RSpec's context blocks), Ruby LSP's index enhancement needs to allow listening to
on_call_node_leave
events too.Implementation
Enhancement
to a class instead of a module and change its interfaceson_call_node
toon_call_node_enter
so it aligns with Prism's dispatcher event name and will allow aon_call_node_leave
event tooon_call_node_leave
event to index enhancementAutomated Tests
Manual Tests