Skip to content

Fix NullClient#send_notification #426

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

Merged
merged 3 commits into from
Jul 31, 2024
Merged

Conversation

amomchilov
Copy link
Contributor

Fixes #425

@amomchilov amomchilov added the bugfix This PR fixes an existing bug label Jul 26, 2024
@amomchilov amomchilov self-assigned this Jul 26, 2024
@amomchilov amomchilov requested a review from a team as a code owner July 26, 2024 18:32
alias_method :send_notification, :send_message
# Notifications are messages that do not expect a response
sig { params(request: String, params: T.nilable(T::Hash[Symbol, T.untyped])).void }
def send_notification(request, params = nil) = send_message(request, params)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I chose this over the alternatives, so subclasses don't have to remember to add their own alias/override.

It's unlikely that somebody would not want it to just mean the same thing as send_message, but if they did, they still have the freedom to override it different, if they would like.

end

test "#send_notification is a no-op" do
assert_nothing_raised { @client.send(:send_notification, "request", nil) }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Prior to the fix, this failed with:

Error:
RubyLsp::Rails::NullClientTest#test_#send_notification_is_a_no-op:
NoMethodError: undefined method `write' for nil
    lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:180:in `send_message'
    test/ruby_lsp_rails/runner_client_test.rb:111:in `block (2 levels) in <class:NullClientTest>'
    /Users/alex/.gem/ruby/3.3.0/gems/activesupport-7.1.3.3/lib/active_support/testing/assertions.rb:49:in `assert_nothing_raised'
    test/ruby_lsp_rails/runner_client_test.rb:111:in `block in <class:NullClientTest>'

@amomchilov amomchilov requested a review from KaanOzkan July 26, 2024 18:35
@andyw8
Copy link
Contributor

andyw8 commented Jul 26, 2024

For future safety, would it be better to have NullClient and RunnerClient implement a Client interface, and avoid the inheritance?

@andyw8 andyw8 removed their request for review July 30, 2024 20:12
@andyw8
Copy link
Contributor

andyw8 commented Jul 30, 2024

I've removed myself as reviewer for now, you can re-add me once the discussions are resolved.

@amomchilov amomchilov force-pushed the Alex/fix-NullClient-crasher branch from aa5b6ba to 180ca75 Compare July 31, 2024 16:27
@amomchilov
Copy link
Contributor Author

amomchilov commented Jul 31, 2024

@andyw8 I played around with it, but I don't think the result is particularly better. The two are just fairly overlapping. e3df69f

Perhaps there's room to extract a more minimal Transport interface, which only has send_message and receive_response, and then NullClient can go away. There would just be RunnerClient with a @transport that's either RunnerTransport or NullTransport. That's something I'd be happy to explore in another PR, if there's interest

@amomchilov amomchilov requested review from vinistock and andyw8 July 31, 2024 16:29
@amomchilov amomchilov merged commit 9cfc64d into main Jul 31, 2024
40 checks passed
@amomchilov amomchilov deleted the Alex/fix-NullClient-crasher branch July 31, 2024 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This PR fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calling send_notification too early causes a NoMethodError
3 participants