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

Add Request class to standardise request interface #1281

Merged
merged 1 commit into from
Jan 9, 2024

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Jan 5, 2024

Motivation

Instead of having some request classes implementing run method as interface, and other listener-based classes implementing response instead, we should standardise the interface to just response.

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

@st0012 st0012 added the chore Chore task label Jan 5, 2024
@st0012 st0012 self-assigned this Jan 5, 2024
@st0012 st0012 requested a review from a team as a code owner January 5, 2024 21:03
@st0012 st0012 requested review from egiurleo and KaanOzkan January 5, 2024 21:03
@st0012 st0012 force-pushed the standardise-request-interface branch from 72b0cf6 to b6ecb02 Compare January 5, 2024 21:05
@st0012 st0012 requested a review from vinistock January 5, 2024 21:05
Copy link
Contributor

@egiurleo egiurleo left a 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 😀

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.

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
Copy link
Member

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

Suggested change
klass if klass.ancestors.include?(Request) && !klass == Request
klass if klass < Request && !klass == Request

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.

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?

@st0012
Copy link
Member Author

st0012 commented Jan 9, 2024

Which at first glance makes me think like the initialize method is the thing running the request.

@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 Listener#response too, which would affect non-request listeners as well.

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.

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

@st0012 st0012 merged commit 82eaab9 into main Jan 9, 2024
30 of 36 checks passed
@st0012 st0012 deleted the standardise-request-interface branch January 9, 2024 15:45
@st0012 st0012 removed the chore Chore task label Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants