-
Notifications
You must be signed in to change notification settings - Fork 153
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
Refactor listener registration #829
Conversation
|
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 like the approach better 👍
Just a nitpick on the PR name: I feel calling it Refactor
is a bit misleading because it actually changes the interface for extensions.
I expect https://github.com/Shopify/ruby-lsp/blob/main/SERVER_EXTENSIONS.md should also be updated? |
e01a655
to
7a1189d
Compare
Good point. Changed the documentation to reflect the changes. I'll hold off merging this for a bit to get some bug fixes out before having to bump to |
Motivation
Allowing extensions to perform listener registration using class methods does not give the LSP enough control to deactivate extensions properly. It also doesn't allow extensions to perform store ahead of time configuration in the
Extension
instance and pass that to their listeners.This PR proposes a refactor in how listener registration happens. Instead of registering listener classes that we instantiate from the LSP, we invert the responsibility and require the extensions to implement factory methods that will create the listener instances based on parameters. This allows extensions to use information stored in the
Extension
instance in their listeners and also allows us to easily disable extensions, since the factory methods are invoked on every request.Example
Implementation
There are tradeoffs with each approach, so I'd love to hear opinions on this. The idea is that we'd need to provide empty factory methods from the base
Extension
class that are overridden to do the right thing if your extension needs it. I don't love invoking a bunch of empty methods, but I couldn't come up with an alternative.There's also the question of formatters. Those are still registered at a class level since a factory method doesn't make much sense for them. We just need to know an identifier and an instance of the formatter.
Automated Tests
Adapted tests.