Skip to content

Commit 59ee419

Browse files
authored
Ensure finish event is emitted on test crashes (#3445)
1 parent 52e3713 commit 59ee419

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/ruby_lsp/test_reporters/lsp_reporter.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ module RubyLsp
99
class LspReporter
1010
include Singleton
1111

12+
#: bool
13+
attr_reader :invoked_shutdown
14+
1215
#: -> void
1316
def initialize
1417
port = ENV["RUBY_LSP_REPORTER_PORT"]
@@ -19,6 +22,8 @@ def initialize
1922
require "stringio"
2023
StringIO.new
2124
end #: IO | StringIO
25+
26+
@invoked_shutdown = false #: bool
2227
end
2328

2429
#: -> void
@@ -34,6 +39,8 @@ def shutdown
3439
# reporter, use `shutdown` instead
3540
#: -> void
3641
def internal_shutdown
42+
@invoked_shutdown = true
43+
3744
send_message("finish")
3845
@io.close
3946
end
@@ -161,4 +168,10 @@ def send_message(method_name, **params)
161168
File.write(File.join(".ruby-lsp", "coverage_result.json"), coverage_results.to_json)
162169
RubyLsp::LspReporter.instance.internal_shutdown
163170
end
171+
elsif ENV["RUBY_LSP_TEST_RUNNER"] && !ENV["RUBY_LSP_ENV"] == "test"
172+
at_exit do
173+
# If the test process crashed immediately without finishing the tests, we still need to tell the extension that the
174+
# execution ended so that it can clean up
175+
RubyLsp::LspReporter.instance.internal_shutdown unless RubyLsp::LspReporter.instance.invoked_shutdown
176+
end
164177
end

0 commit comments

Comments
 (0)