diff --git a/lib/ruby_lsp/listeners/definition.rb b/lib/ruby_lsp/listeners/definition.rb index dcdd461cf..0fb5ed0a6 100644 --- a/lib/ruby_lsp/listeners/definition.rb +++ b/lib/ruby_lsp/listeners/definition.rb @@ -46,6 +46,7 @@ def initialize(response_builder, global_state, language_id, uri, node_context, d :on_instance_variable_or_write_node_enter, :on_instance_variable_target_node_enter, :on_string_node_enter, + :on_symbol_node_enter, :on_super_node_enter, :on_forwarding_super_node_enter, ) @@ -67,11 +68,7 @@ def on_call_node_enter(node) inferrer_receiver_type = nil end - if message == "autoload" && node.receiver.nil? - handle_autoload_definition(node) - else - handle_method_definition(message, inferrer_receiver_type) - end + handle_method_definition(message, inferrer_receiver_type) end sig { params(node: Prism::StringNode).void } @@ -85,6 +82,17 @@ def on_string_node_enter(node) handle_require_definition(node, name) end + sig { params(node: Prism::SymbolNode).void } + def on_symbol_node_enter(node) + enclosing_call = @node_context.call_node + return unless enclosing_call + + name = enclosing_call.name + return unless name == :autoload + + handle_autoload_definition(enclosing_call) + end + sig { params(node: Prism::BlockArgumentNode).void } def on_block_argument_node_enter(node) expression = node.expression diff --git a/test/requests/definition_expectations_test.rb b/test/requests/definition_expectations_test.rb index 97e0cef7c..55fe55663 100644 --- a/test/requests/definition_expectations_test.rb +++ b/test/requests/definition_expectations_test.rb @@ -367,7 +367,7 @@ class Bar; end server.process_message( id: 1, method: "textDocument/definition", - params: { textDocument: { uri: uri }, position: { character: 3, line: 3 } }, + params: { textDocument: { uri: uri }, position: { character: 12, line: 3 } }, ) response = server.pop_response.response