Skip to content

Commit 3f280d9

Browse files
committed
Do not raise if response is empty
1 parent 77650f0 commit 3f280d9

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

lib/ruby_lsp/ruby_lsp_rails/runner_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def read_response
278278
raise IncompleteMessageError unless headers
279279

280280
content_length = headers[/Content-Length: (\d+)/i, 1].to_i
281-
raise EmptyMessageError if content_length.zero?
281+
return if content_length.zero?
282282

283283
@stdout.read(content_length)
284284
end

test/ruby_lsp_rails/launch_test.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# typed: true
2+
# frozen_string_literal: true
3+
4+
require "test_helper"
5+
6+
module RubyLsp
7+
module Rails
8+
class LaunchTest < ActiveSupport::TestCase
9+
test "launching the client succeeds" do
10+
outgoing_queue = Thread::Queue.new
11+
12+
client = RunnerClient.create_client(outgoing_queue)
13+
refute_instance_of(NullClient, client)
14+
15+
first = pop_log_notification(outgoing_queue, Constant::MessageType::LOG)
16+
assert_equal("Ruby LSP Rails booting server", first.params.message)
17+
18+
second = pop_log_notification(outgoing_queue, Constant::MessageType::LOG)
19+
assert_match("Finished booting Ruby LSP Rails server", second.params.message)
20+
21+
client.shutdown
22+
assert_predicate(client, :stopped?)
23+
outgoing_queue.close
24+
end
25+
end
26+
end
27+
end

test/ruby_lsp_rails/runner_client_test.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,22 @@ class RunnerClientTest < ActiveSupport::TestCase
8787
junk = %{\nputs "1\r\n\r\nhello"}
8888
File.write("test/dummy/config/application.rb", content + junk)
8989

90-
capture_subprocess_io do
91-
outgoing_queue = Thread::Queue.new
92-
client = RunnerClient.create_client(outgoing_queue)
90+
outgoing_queue = Thread::Queue.new
91+
92+
client = RunnerClient.create_client(outgoing_queue)
93+
response = client.model("User")
9394

94-
response = T.must(client.model("User"))
95-
assert(response.key?(:columns))
95+
unless response
96+
log = pop_log_notification(outgoing_queue, RubyLsp::Constant::MessageType::WARNING)
97+
flunk("Model returned nil: #{log.params.message}")
98+
end
99+
100+
begin
101+
assert(T.must(response).key?(:columns))
96102
ensure
97103
T.must(outgoing_queue).close
104+
FileUtils.mv("test/dummy/config/application.rb.bak", "test/dummy/config/application.rb")
98105
end
99-
ensure
100-
FileUtils.mv("test/dummy/config/application.rb.bak", "test/dummy/config/application.rb")
101106
end
102107

103108
test "delegate notification" do

test/test_helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,13 @@ def pop_result(server)
4848
)
4949
T.cast(result, RubyLsp::Result)
5050
end
51+
52+
def pop_log_notification(message_queue, type)
53+
log = message_queue.pop
54+
return log if log.params.type == type
55+
56+
log = message_queue.pop until log.params.type == type
57+
log
58+
end
5159
end
5260
end

0 commit comments

Comments
 (0)