def items_for_trigger(position:)
def items_for_trigger(position:)
node, *parents = source.find_nodes(line: position.line, column: position.column)
node ||= source.node
return [] unless node
items = []
context = typing.context_at(line: position.line, column: position.column)
case
when node.type == :send && node.children[0] == nil && at_end?(position, of: node.loc.selector)
# foo ←
prefix = node.children[1].to_s
method_items_for_receiver_type(context.self_type,
include_private: true,
prefix: prefix,
position: position,
items: items)
local_variable_items_for_context(context, position: position, prefix: prefix, items: items)
when node.type == :lvar && at_end?(position, of: node.loc)
# foo ← (lvar)
local_variable_items_for_context(context, position: position, prefix: node.children[0].name.to_s, items: items)
when node.type == :send && node.children[0] && at_end?(position, of: node.loc.selector)
# foo.ba ←
receiver_type = case (type = typing.type_of(node: node.children[0]))
when AST::Types::Self
context.self_type
else
type
end
prefix = node.children[1].to_s
method_items_for_receiver_type(receiver_type,
include_private: false,
prefix: prefix,
position: position,
items: items)
when node.type == :const && node.children[0] == nil && at_end?(position, of: node.loc)
# Foo ← (const)
prefix = node.children[1].to_s
method_items_for_receiver_type(context.self_type,
include_private: false,
prefix: prefix,
position: position,
items: items)
when node.type == :send && at_end?(position, of: node.loc.dot)
# foo.← ba
receiver_type = case (type = typing.type_of(node: node.children[0]))
when AST::Types::Self
context.self_type
else
type
end
method_items_for_receiver_type(receiver_type,
include_private: false,
prefix: "",
position: position,
items: items)
when node.type == :ivar && at_end?(position, of: node.loc)
# @fo ←
instance_variable_items_for_context(context, position: position, prefix: node.children[0].to_s, items: items)
else
method_items_for_receiver_type(context.self_type,
include_private: true,
prefix: "",
position: position,
items: items)
local_variable_items_for_context(context, position: position, prefix: "", items: items)
instance_variable_items_for_context(context, position: position, prefix: "", items: items)
end
items
end