From 4afb033261db4108cb50036f337ad2c8c3653b5e Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Wed, 31 Jul 2024 16:13:32 +0100 Subject: [PATCH] Fix definition listener's sorbet early return condition (#2392) * 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. * Update test/requests/definition_expectations_test.rb Co-authored-by: Andy Waite --------- Co-authored-by: Andy Waite --- 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 e7a201058..13448f0e8 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 af4a74dff..a41059019 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 expectation 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.expects(:not_in_dependencies?).never + source = <<~RUBY # typed: true class Foo