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

Support on_call_node_leave events in index enhancement #2754

Merged
merged 5 commits into from
Oct 22, 2024

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Oct 22, 2024

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

  1. Convert Enhancement to a class instead of a module and change its interfaces
  2. Rename on_call_node to on_call_node_enter so it aligns with Prism's dispatcher event name and will allow a on_call_node_leave event too
  3. Support on_call_node_leave event to index enhancement

Automated Tests

Manual Tests

This matches the naming of Prism listener's events. But more importantly,
allows adding a new `on_call_node_leave` method.
@st0012 st0012 added enhancement New feature or request breaking-change Non-backward compatible change server This pull request should be included in the server gem's release notes labels Oct 22, 2024
@st0012 st0012 self-assigned this Oct 22, 2024
@st0012 st0012 requested a review from a team as a code owner October 22, 2024 16:00
@andyw8
Copy link
Contributor

andyw8 commented Oct 22, 2024

We'll need to also update jekyll/add-ons.markdown.

@vinistock vinistock removed the enhancement New feature or request label Oct 22, 2024
@st0012 st0012 force-pushed the update-indexing-enhancement-api branch from d2f60ea to cfd9a01 Compare October 22, 2024 19:46
@st0012 st0012 requested review from andyw8 and vinistock October 22, 2024 19:59
@st0012
Copy link
Member Author

st0012 commented Oct 22, 2024

We'll need to also update jekyll/add-ons.markdown.

Done 👍

Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@st0012 st0012 merged commit e0299e5 into main Oct 22, 2024
39 checks passed
@st0012 st0012 deleted the update-indexing-enhancement-api branch October 22, 2024 20:25
@@ -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))
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Non-backward compatible change server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants