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
8 changes: 7 additions & 1 deletion test/requests/definition_expectations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion test/requests/diagnostics_expectations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
8 changes: 7 additions & 1 deletion test/requests/formatting_expectations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
8 changes: 7 additions & 1 deletion test/requests/hover_expectations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion test/requests/support/expectations_test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading