From 12f8d0d2391e510c090c45b4513543733c895dc9 Mon Sep 17 00:00:00 2001 From: Alexander Momchilov Date: Fri, 26 Jul 2024 14:30:27 -0400 Subject: [PATCH 1/3] Add tests for NullClient --- test/ruby_lsp_rails/runner_client_test.rb | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/ruby_lsp_rails/runner_client_test.rb b/test/ruby_lsp_rails/runner_client_test.rb index 3fd910b6..9ffdf5cb 100644 --- a/test/ruby_lsp_rails/runner_client_test.rb +++ b/test/ruby_lsp_rails/runner_client_test.rb @@ -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 From 07a4d9631bd9387f11e1747c9892be4065622f16 Mon Sep 17 00:00:00 2001 From: Alexander Momchilov Date: Fri, 26 Jul 2024 14:30:59 -0400 Subject: [PATCH 2/3] Fix `NullClient#send_notification` crash --- lib/ruby_lsp/ruby_lsp_rails/runner_client.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb b/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb index 5c52b7b5..94579d34 100644 --- a/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb +++ b/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb @@ -181,7 +181,8 @@ def send_message(request, params = nil) # The server connection died end - alias_method :send_notification, :send_message + 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])) } def read_response From 180ca757f93971cb5bdda3b54de1c9b09b2bd203 Mon Sep 17 00:00:00 2001 From: Alexander Momchilov Date: Fri, 26 Jul 2024 14:31:10 -0400 Subject: [PATCH 3/3] Misc. improvements --- lib/ruby_lsp/ruby_lsp_rails/runner_client.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb b/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb index 94579d34..642eeb25 100644 --- a/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb +++ b/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb @@ -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 @@ -181,10 +181,11 @@ def send_message(request, params = nil) # The server connection died end + # 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