From 68f5824ed1314f84838fa7516f395d74ae17725a Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Tue, 30 Jul 2024 23:38:02 +0100 Subject: [PATCH] Fix definition listener's sorbet early return condition The condition missed the return so it's not working. The test still passed because the definition candidate was rejected by the check in `handle_method_definition` method instead. This commit fixes the condition and tweaks the test to make sure the listener is working as expected. --- lib/ruby_lsp/listeners/definition.rb | 4 +--- test/requests/definition_expectations_test.rb | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) 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