-
Notifications
You must be signed in to change notification settings - Fork 175
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
Make requests easier to extend #972
Conversation
9a211db
to
9c7ceb8
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.
Nice. This will really help ensuring consistency in extensible requests.
What's the breaking change though?
@@ -127,8 +127,10 @@ def name | |||
end | |||
|
|||
def create_code_lens_listener(uri, emitter, message_queue) | |||
raise "uri can't be nil" unless uri |
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.
Let's leverage Sorbet for this instead. We can just add a signature and we shouldn't need this check.
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've tried it but maybe I was doing something wrong because it's like wrestling with Sorbet with little benefit due to the dynamic class definition:
-
We need to add
extend T::Sig
toCodeLensExpectationsTest
instead of the extension test class. -
In this case, we need to add
override
to the signature ofcreate_code_lens_listener
. But Sorbet would complain that there's nothing to override about, which I think is also due to dynamic class definition?
-
If there's any runtime type checking error, it will be swallowed in
RubyLsp::Result
instead of being raised
So eventually I decided that it's not worth the effort here.
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.
Oh, right. Yeah, Sorbet doesn't play well with Class.new
.
9c7ceb8
to
dd25717
Compare
@@ -127,8 +127,10 @@ def name | |||
end | |||
|
|||
def create_code_lens_listener(uri, emitter, message_queue) | |||
raise "uri can't be nil" unless uri |
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.
Oh, right. Yeah, Sorbet doesn't play well with Class.new
.
This will allow `ExternalListener` to encapsulate response merging logic under `response`, which means we can always call `response` on the listener regardless of whether it's an extensible or not.
dd25717
to
e3abd29
Compare
Motivation
This is part of #808
Currently, to make a listener-based request extensible, we need to:
merge_response!
andmerge_external_listeners_responses!
merge_external_listeners_responses!
in theexecutor.rb
before accessing the responseIt's not easy to remember all of them at the same time. And when it's not implemented correctly, we'd rely on runtime information to figure out what's missing.
So with this change, I want to utilise Sorbet as much as possible, while reducing the APIs that need to be implemented.
Implementation
Listener
to the newExtensibleListener
class. Sorbet would then require a few more interfaces on its child class thanListener
's.ExtensibleListener#response
merge external responses automatically, I changedListener
's response interface to_response
. This will prevent individual listener classes from overriding theresponse
method when declaring itsResponseType
.ExtensibleListener
isListener
's child class but is abstract.One shortfall of this approach is that if
initialize_external_listener
uses ivars to initialise external listeners,super
needs to be called after the ivars are initialised. And this could not be type-checked. (Ideally we should prepend a module for such order-dependant requirement, but it's not supported by Sorbet)Automated Tests
All existing tests should pass
Manual Tests