Skip to content

Commit dba7666

Browse files
authored
Avoid sending add-on load error messages in test mode (#3662)
Avoid sending add-on load error messages in test mode (#3662) ### Motivation Whenever we eagerly bump our version due to a breaking change, all add-ons that exist in our bundle (like Tapioca) may start failing to load because they haven't handled the breaking changes yet. That causes our tests to fail because some log notifications are added to the outgoing queue. We shouldn't fail our build because add-ons haven't handled the breaking changes yet. ### Implementation I started not sending any logs at all in test mode. ### Automated Tests For our test that actually checks for these, I used a stub to get the errors produced. Co-authored-by: vinistock <[email protected]>
1 parent 0d599e6 commit dba7666

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

lib/ruby_lsp/base_server.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ def process_message(message)
118118
raise AbstractMethodInvokedError
119119
end
120120

121+
#: -> bool?
122+
def test_mode?
123+
@test_mode
124+
end
125+
121126
#: -> void
122127
def run_shutdown
123128
@incoming_queue.clear

lib/ruby_lsp/server.rb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def load_addons(include_project_addons: true)
167167
return if @setup_error
168168

169169
errors = Addon.load_addons(@global_state, @outgoing_queue, include_project_addons: include_project_addons)
170+
return if test_mode?
170171

171172
if errors.any?
172173
send_log_message(
@@ -179,21 +180,13 @@ def load_addons(include_project_addons: true)
179180

180181
if errored_addons.any?
181182
send_message(
182-
Notification.new(
183-
method: "window/showMessage",
184-
params: Interface::ShowMessageParams.new(
185-
type: Constant::MessageType::WARNING,
186-
message: "Error loading add-ons:\n\n#{errored_addons.map(&:formatted_errors).join("\n\n")}",
187-
),
183+
Notification.window_show_message(
184+
"Error loading add-ons:\n\n#{errored_addons.map(&:formatted_errors).join("\n\n")}",
185+
type: Constant::MessageType::WARNING,
188186
),
189187
)
190188

191-
unless @test_mode
192-
send_log_message(
193-
errored_addons.map(&:errors_details).join("\n\n"),
194-
type: Constant::MessageType::WARNING,
195-
)
196-
end
189+
send_log_message(errored_addons.map(&:errors_details).join("\n\n"), type: Constant::MessageType::WARNING)
197190
end
198191
end
199192

test/server_test.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,14 +573,16 @@ def test_did_change_watched_files_processes_unique_change_entries
573573

574574
def test_workspace_addons
575575
create_test_addons
576+
577+
@server.stubs(:test_mode?).returns(false)
576578
@server.load_addons
577579

578580
@server.process_message({ id: 1, method: "rubyLsp/workspace/addons" })
579581

580-
addon_error_notification = @server.pop_response
582+
addon_error_notification = find_message(RubyLsp::Notification, "window/showMessage")
581583
assert_equal("window/showMessage", addon_error_notification.method)
582584
assert_equal("Error loading add-ons:\n\nBar:\n boom\n", addon_error_notification.params.message)
583-
addons_info = @server.pop_response.response
585+
addons_info = find_message(RubyLsp::Result, id: 1).response
584586
addons_info.delete_if { |addon_info| addon_info[:name] == "RuboCop" }
585587

586588
assert_equal("Foo", addons_info[0][:name])

0 commit comments

Comments
 (0)