-
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
Add Request class to standardise request interface #1281
Conversation
72b0cf6
to
b6ecb02
Compare
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.
Really cool how the architecture and patterns in this codebase are consolidating over time 😀
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.
What do you think about standardizing requests with run
instead of response
?
In terms of communicating the intent, I think it makes sense to use run
for requests and response
for listeners. We run requests, it's the thing that executes them.
But for listeners, their execution is orchestrated by the dispatcher, so we don't run them. The dispatcher emits the events and then we just inspect the response.
Using response
for requests results in
Request.new(...).response
Which at first glance makes me think like the initialize
method is the thing running the request.
With the separation of requests and listeners to be separate entities, I'd still keep run
for the request interfaces and response
for the listeners.
What do you think?
@@ -56,7 +56,7 @@ def run_task | |||
klass_name = klass.name | |||
next unless klass_name | |||
|
|||
klass if klass_name.match?(/RubyLsp::Requests::\w[^:]+$/) && !klass_name.include?("Support") | |||
klass if klass.ancestors.include?(Request) && !klass == Request |
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 think we can do
klass if klass.ancestors.include?(Request) && !klass == Request | |
klass if klass < Request && !klass == Request |
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.
What do you think about standardizing requests with run
instead of response
?
In terms of communicating the intent, I think it makes sense to use run
for requests and response
for listeners. We run requests, it's the thing that executes them.
But for listeners, their execution is orchestrated by the dispatcher, so we don't run them. The dispatcher emits the events and then we just inspect the response.
Using response
for requests results in
Request.new(...).response
Which at first glance makes me think like the initialize
method is the thing running the request.
With the separation of requests and listeners to be separate entities, I'd still keep run
for the request interfaces and response
for the listeners.
What do you think?
@vinistock It make sense. But if we change it before completely splitting Listener and Request, it'd be a big change as we'd need rename |
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.
Chatted with Stan on a call. This is temporary step until the separation between requests and listeners is complete, just to ensure consistency while we get there.
All good, but still think we can change the ancestors check
Motivation
Instead of having some request classes implementing
run
method as interface, and other listener-based classes implementingresponse
instead, we should standardise the interface to justresponse
.Since I made a similar change in #1247 as well, merging this first will also make it easier to review.
Implementation
We can enforce the interface by making all request classes to inherit an abstract
Request
class.Note: after doing a major refactor in #1247, the only commonality shared between all request classes is that they all implement a method to return the result. I don't think there's more that we could put into the
Request
class atm.Automated Tests
All existing tests should pass.
Manual Tests