Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

module RubyLsp
class Server < BaseServer
NON_REPORTABLE_SETUP_ERRORS = [Bundler::GemNotFound, Bundler::GitError].freeze #: Array[singleton(StandardError)]

# Only for testing
#: GlobalState
attr_reader :global_state
Expand Down Expand Up @@ -315,7 +317,7 @@ def run_initialize(message)

global_state_notifications.each { |notification| send_message(notification) }

if @setup_error
if @setup_error && NON_REPORTABLE_SETUP_ERRORS.none? { |error_class| @setup_error.is_a?(error_class) }
send_message(Notification.telemetry(
type: "error",
errorMessage: @setup_error.message,
Expand Down
31 changes: 31 additions & 0 deletions test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,21 @@ def test_errors_include_telemetry_data
assert_match("mocha/exception_raiser.rb", data[:backtrace])
end

def test_gem_not_found_setup_error_does_not_send_telemetry
RubyLsp::Notification.expects(:telemetry).never
run_initialize_server_with_setup_error(Bundler::GemNotFound.new("Could not find gem 'foo'"))
end

def test_git_error_setup_error_does_not_send_telemetry
RubyLsp::Notification.expects(:telemetry).never
run_initialize_server_with_setup_error(Bundler::GitError.new("Revision abc123 does not exist"))
end

def test_other_setup_errors_are_reported_to_telemetry
RubyLsp::Notification.expects(:telemetry).once
run_initialize_server_with_setup_error(StandardError.new("something unexpected"))
end

def test_handles_editor_indexing_settings
capture_io do
@server.process_message({
Expand Down Expand Up @@ -1714,6 +1729,22 @@ def test_launch_bundle_compose_forwards_argv_to_launcher

private

def run_initialize_server_with_setup_error(error)
server = RubyLsp::Server.new(test_mode: true, setup_error: error)
capture_subprocess_io do
server.process_message({
id: 1,
method: "initialize",
params: {
initializationOptions: { enabledFeatures: [] },
capabilities: { general: { positionEncodings: ["utf-8"] } },
},
})
end
ensure
server&.run_shutdown
end

def wait_for_indexing
message = @server.pop_response
until message.is_a?(RubyLsp::Notification) && message.method == "$/progress" &&
Expand Down
Loading