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

Move listener registration to the extension activation #106

Closed
wants to merge 1 commit into from

Conversation

vinistock
Copy link
Member

Related to Shopify/ruby-lsp#813

We need to set a standard for registering feature enhancements always inside of activate or else disabling extensions becomes significantly more difficult.

This just moves our registrations there.

@vinistock vinistock added the chore Chore task label Jul 12, 2023
@vinistock vinistock added this to the 2023-Q3 milestone Jul 12, 2023
@vinistock vinistock self-assigned this Jul 12, 2023
@vinistock vinistock requested a review from a team as a code owner July 12, 2023 18:56
@vinistock vinistock requested review from Morriar and st0012 July 12, 2023 18:56
@vinistock vinistock force-pushed the vs/move_registration_to_activate branch from 7bb0944 to 08c95f9 Compare July 12, 2023 19:07
@@ -14,6 +14,9 @@ class Extension < ::RubyLsp::Extension

sig { override.void }
def activate
::RubyLsp::Requests::Hover.add_listener(RubyLsp::Rails::Hover)
Copy link

Choose a reason for hiding this comment

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

Since we only register classes and not instances, I wonder if this could be moved in the Listener itself:

class RubyLsp::Rails::CodeLens < ::RubyLsp::Listener
  listen_to ::RubyLsp::Requests::CodeLens

  # ...
end

Copy link
Member Author

Choose a reason for hiding this comment

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

That's an interesting approach, but it would lead to the same problem we're trying to avoid in this PR.

In order to disable an extension and avoid registering the listeners defined by it, we need the registration to happen in activate.

Basically, if the server extension is disabled, we just don't invoke activate. If the listener classes register themselves, then that will happen automatically when we require the Extension file and we'll have no way of stopping it.

@vinistock
Copy link
Member Author

Putting this on pause from now until we have more use cases to learn from.

@vinistock vinistock closed this Jul 17, 2023
@vinistock vinistock deleted the vs/move_registration_to_activate branch July 17, 2023 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Chore task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants