Skip to content

Commit d3f6586

Browse files
committed
Avoid need for special VOID return
1 parent 77dc960 commit d3f6586

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

lib/ruby_lsp/ruby_lsp_rails/server.rb

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
module RubyLsp
1010
module Rails
1111
class Server
12-
VOID = Object.new
13-
1412
def initialize
1513
# Grab references to the original pipes so that we can change the default output device further down
1614
@stdin = $stdin
@@ -44,35 +42,35 @@ def start
4442
json = @stdin.read(headers[/Content-Length: (\d+)/i, 1].to_i)
4543

4644
request = JSON.parse(json, symbolize_names: true)
47-
response = execute(request.fetch(:method), request[:params])
48-
next if response == VOID
45+
execute(request.fetch(:method), request[:params])
4946

50-
json_response = response.to_json
51-
@stdout.write("Content-Length: #{json_response.length}\r\n\r\n#{json_response}")
47+
# json_response = response.to_json
48+
# @stdout.write("Content-Length: #{json_response.length}\r\n\r\n#{json_response}")
5249
end
5350
end
5451

52+
def write_response(response)
53+
json_response = response.to_json
54+
@stdout.write("Content-Length: #{json_response.length}\r\n\r\n#{json_response}")
55+
end
56+
5557
def execute(request, params)
5658
case request
5759
when "shutdown"
5860
@running = false
59-
VOID
6061
when "model"
61-
resolve_database_info_from_model(params.fetch(:name))
62+
write_response(resolve_database_info_from_model(params.fetch(:name)))
6263
when "association_target_location"
63-
resolve_association_target(params)
64+
write_response(resolve_association_target(params))
6465
when "reload"
6566
::Rails.application.reloader.reload!
66-
VOID
6767
when "route_location"
68-
route_location(params.fetch(:name))
68+
write_response(route_location(params.fetch(:name)))
6969
when "route_info"
70-
resolve_route_info(params)
71-
else
72-
VOID
70+
write_response(resolve_route_info(params))
7371
end
7472
rescue => e
75-
{ error: e.full_message(highlight: false) }
73+
write_response({ error: e.full_message(highlight: false) })
7674
end
7775

7876
private

0 commit comments

Comments
 (0)