Skip to content

Commit

Permalink
Trigger autoload definition request on symbol nodes instead of call n…
Browse files Browse the repository at this point in the history
…odes
  • Loading branch information
st0012 committed Jul 31, 2024
1 parent 0106252 commit 3222d95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions lib/ruby_lsp/listeners/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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 }
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/requests/definition_expectations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3222d95

Please sign in to comment.