diff --git a/test/requests/definition_expectations_test.rb b/test/requests/definition_expectations_test.rb index e3f005f08a..5845300aac 100644 --- a/test/requests/definition_expectations_test.rb +++ b/test/requests/definition_expectations_test.rb @@ -7,6 +7,12 @@ class DefinitionExpectationsTest < ExpectationsTestRunner expectations_tests RubyLsp::Requests::Definition, "definition" + # Skip add-on loading by default — only test_definition_addons needs it + def with_server(source = nil, uri = Kernel.URI("file:///fake.rb"), stub_no_typechecker: false, load_addons: false, + &block) + super + end + def run_expectations(source) # We need to pretend that Sorbet is not a dependency or else we can't properly test with_server(source, stub_no_typechecker: true) do |server, uri| @@ -229,7 +235,7 @@ def test_definition_addons begin create_definition_addon - with_server(source, stub_no_typechecker: true) do |server, uri| + with_server(source, stub_no_typechecker: true, load_addons: true) do |server, uri| server.global_state.index.index_file( URI::Generic.from_path( load_path_entry: "#{Dir.pwd}/lib", diff --git a/test/requests/diagnostics_expectations_test.rb b/test/requests/diagnostics_expectations_test.rb index b8c4663dd7..fd049728c5 100644 --- a/test/requests/diagnostics_expectations_test.rb +++ b/test/requests/diagnostics_expectations_test.rb @@ -14,7 +14,7 @@ def run_expectations(source) }) @global_state.register_formatter( "rubocop_internal", - RubyLsp::Requests::Support::RuboCopFormatter.new, + self.class.cached_rubocop_formatter, ) document = RubyLsp::RubyDocument.new( @@ -81,4 +81,10 @@ def map_diagnostics(diagnostics) ) end.to_json end + + class << self + def cached_rubocop_formatter + @cached_rubocop_formatter ||= RubyLsp::Requests::Support::RuboCopFormatter.new + end + end end diff --git a/test/requests/formatting_expectations_test.rb b/test/requests/formatting_expectations_test.rb index aadab9d41d..7516f6ad94 100644 --- a/test/requests/formatting_expectations_test.rb +++ b/test/requests/formatting_expectations_test.rb @@ -11,7 +11,7 @@ def run_expectations(source) @global_state.formatter = "rubocop_internal" @global_state.register_formatter( "rubocop_internal", - RubyLsp::Requests::Support::RuboCopFormatter.new, + self.class.cached_rubocop_formatter, ) document = RubyLsp::RubyDocument.new( source: source, @@ -37,4 +37,10 @@ def assert_expectations(source, expected) def initialize_params(_expected) end + + class << self + def cached_rubocop_formatter + @cached_rubocop_formatter ||= RubyLsp::Requests::Support::RuboCopFormatter.new + end + end end diff --git a/test/requests/hover_expectations_test.rb b/test/requests/hover_expectations_test.rb index 5b9144c69e..ad80a65418 100644 --- a/test/requests/hover_expectations_test.rb +++ b/test/requests/hover_expectations_test.rb @@ -7,6 +7,12 @@ class HoverExpectationsTest < ExpectationsTestRunner expectations_tests RubyLsp::Requests::Hover, "hover" + # Skip add-on loading by default — only test_hover_addons needs it + def with_server(source = nil, uri = Kernel.URI("file:///fake.rb"), stub_no_typechecker: false, load_addons: false, + &block) + super + end + def run_expectations(source) position = @__params&.first || { character: 0, line: 0 } @@ -356,7 +362,7 @@ class Post begin create_hover_addon - with_server(source, stub_no_typechecker: true) do |server, uri| + with_server(source, stub_no_typechecker: true, load_addons: true) do |server, uri| server.process_message( id: 1, method: "textDocument/hover", diff --git a/test/requests/support/expectations_test_runner.rb b/test/requests/support/expectations_test_runner.rb index 1c64c72758..e63fb31803 100644 --- a/test/requests/support/expectations_test_runner.rb +++ b/test/requests/support/expectations_test_runner.rb @@ -8,10 +8,14 @@ class ExpectationsTestRunner < Minitest::Test TEST_PRISM_FIXTURES = File.join(TEST_FIXTURES_DIR, "prism/test/prism/fixtures/**", "*.txt") def setup - @global_state = RubyLsp::GlobalState.new + @global_state = self.class.shared_global_state end class << self + def shared_global_state + @shared_global_state ||= RubyLsp::GlobalState.new + end + def expectations_tests(handler_class, expectation_suffix) class_eval(<<~RB, __FILE__, __LINE__ + 1) module ExpectationsRunnerMethods