Skip to content

Commit

Permalink
Fix definition listener's sorbet early return condition
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
st0012 committed Jul 30, 2024
1 parent 24076cb commit 68f5824
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/ruby_lsp/listeners/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/requests/definition_expectations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 68f5824

Please sign in to comment.