diff --git a/lib/ruby_lsp/listeners/definition.rb b/lib/ruby_lsp/listeners/definition.rb index e7a2010582..13448f0e8a 100644 --- a/lib/ruby_lsp/listeners/definition.rb +++ b/lib/ruby_lsp/listeners/definition.rb @@ -54,9 +54,7 @@ def initialize(response_builder, global_state, language_id, uri, node_context, d sig { params(node: Prism::CallNode).void } def on_call_node_enter(node) # Sorbet can handle go to definition for methods invoked on self on typed true or higher - if (@sorbet_level == Document::SorbetLevel::True || @sorbet_level == Document::SorbetLevel::Strict) && - self_receiver?(node) - end + return if sorbet_level_true_or_higher?(@sorbet_level) && self_receiver?(node) message = node.message return unless message diff --git a/test/requests/definition_expectations_test.rb b/test/requests/definition_expectations_test.rb index af4a74dffc..c1c4ff1296 100644 --- a/test/requests/definition_expectations_test.rb +++ b/test/requests/definition_expectations_test.rb @@ -819,6 +819,10 @@ def bar end def test_definition_on_self_is_disabled_for_typed_true + # We need this stub to make sure the test is testing the early return inside on_call_node_enter + # not the one inside handle_method_definition + RubyLsp::Listeners::Definition.any_instance.stubs(:not_in_dependencies?).returns(false) + source = <<~RUBY # typed: true class Foo