lib/theme_check/language_server/server.rb in theme-check-1.7.2 vs lib/theme_check/language_server/server.rb in theme-check-1.8.0
- old
+ new
@@ -35,11 +35,11 @@
# The handler threads read messages from the queue
@number_of_threads = number_of_threads
@handlers = []
# The error queue holds blocks the main thread. When filled, we exit the program.
- @error = SizedQueue.new(1)
+ @error = SizedQueue.new(number_of_threads)
@should_raise_errors = should_raise_errors
end
def listen
@@ -92,12 +92,11 @@
rescue SignalException, DoneStreaming
0
rescue Exception => e # rubocop:disable Lint/RescueException
raise e if should_raise_errors
- @bridge.log(e)
- @bridge.log(e.backtrace)
+ @bridge.log("#{e.class}: #{e.message}\n#{e.backtrace.join("\n")}")
2
end
private
@@ -108,10 +107,19 @@
params = message['params']
if @handler.respond_to?(method_name)
@handler.send(method_name, id, params)
end
+
+ rescue DoneStreaming => e
+ raise e
+ rescue StandardError => e
+ is_request = id
+ raise e unless is_request
+ # Errors obtained in request handlers should be sent
+ # back as internal errors instead of closing the program.
+ @bridge.send_internal_error(id, e)
end
def handle_response(message)
id = message['id']
result = message['result']
@@ -133,10 +141,19 @@
# doing/emptying the queue. 👀 unit tests.
@handlers.each { |thread| thread.join(10) if thread.alive? }
# Hijack the status_code if an error occurred while cleaning up.
# 👀 unit tests.
- return status_code_from_error(@error.pop) unless @error.empty?
+ until @error.empty?
+ code = status_code_from_error(@error.pop)
+ # Promote the status_code to ERROR if one of the threads
+ # resulted in an error, otherwise leave the status_code as
+ # is. That's because one thread could end successfully in a
+ # DoneStreaming error while the other failed with an
+ # internal error. If we had an internal error, we should
+ # return with a status_code that fits.
+ status_code = code if code > status_code
+ end
status_code
ensure
@messenger.close_output
end
end