Skip to content

Commit

Permalink
Merge pull request #426 from Shopify/Alex/fix-NullClient-crasher
Browse files Browse the repository at this point in the history
Fix `NullClient#send_notification`
  • Loading branch information
amomchilov authored Jul 31, 2024
2 parents d55243d + 180ca75 commit 9cfc64d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/ruby_lsp/ruby_lsp_rails/runner_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def make_request(request, params = nil)
read_response
end

sig { params(request: String, params: T.nilable(T::Hash[Symbol, T.untyped])).void }
sig { overridable.params(request: String, params: T.nilable(T::Hash[Symbol, T.untyped])).void }
def send_message(request, params = nil)
message = { method: request }
message[:params] = params if params
Expand All @@ -181,9 +181,11 @@ def send_message(request, params = nil)
# The server connection died
end

alias_method :send_notification, :send_message
# Notifications are like messages, but one-way, with no response sent back.
sig { params(request: String, params: T.nilable(T::Hash[Symbol, T.untyped])).void }
def send_notification(request, params = nil) = send_message(request, params)

sig { returns(T.nilable(T::Hash[Symbol, T.untyped])) }
sig { overridable.returns(T.nilable(T::Hash[Symbol, T.untyped])) }
def read_response
headers = @stdout.gets("\r\n\r\n")
raise IncompleteMessageError unless headers
Expand Down
28 changes: 28 additions & 0 deletions test/ruby_lsp_rails/runner_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,33 @@ class RunnerClientTest < ActiveSupport::TestCase
FileUtils.mv("test/dummy/config/application.rb.bak", "test/dummy/config/application.rb")
end
end

class NullClientTest < ActiveSupport::TestCase
setup { @client = NullClient.new }

test "#shutdown is a no-op" do
assert_nothing_raised { @client.shutdown }
end

test "#stopped? is always true" do
assert_predicate @client, :stopped?
end

test "#rails_root is just the current working directory" do
assert_equal Dir.pwd, @client.rails_root
end

test "#send_message is a no-op" do
assert_nothing_raised { @client.send(:send_message, "request", nil) }
end

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

test "#read_response is a no-op" do
assert_nothing_raised { @client.send(:read_response) }
end
end
end
end

0 comments on commit 9cfc64d

Please sign in to comment.