class RubyLsp::NodeContext
its namespace nesting, and the surrounding CallNode (e.g. a method call).
This class allows listeners to access contextual information about a node in the AST, such as its parent,
def fully_qualified_name
def fully_qualified_name @fully_qualified_name ||= @nesting.join("::") #: String? end
def handle_nesting_nodes(nodes)
def handle_nesting_nodes(nodes) nesting = [] surrounding_method = nil #: String? @nesting_nodes.each do |node| case node when Prism::ClassNode, Prism::ModuleNode nesting << node.constant_path.slice when Prism::SingletonClassNode nesting << "<Class:#{nesting.flat_map { |n| n.split("::") }.last}>" when Prism::DefNode surrounding_method = node.name.to_s next unless node.receiver.is_a?(Prism::SelfNode) nesting << "<Class:#{nesting.flat_map { |n| n.split("::") }.last}>" end end [nesting, surrounding_method] end
def initialize(node, parent, nesting_nodes, call_node)
def initialize(node, parent, nesting_nodes, call_node) @node = node @parent = parent @nesting_nodes = nesting_nodes @call_node = call_node nesting, surrounding_method = handle_nesting_nodes(nesting_nodes) @nesting = nesting #: Array[String] @surrounding_method = surrounding_method #: String? end
def locals_for_scope
def locals_for_scope locals = [] @nesting_nodes.each do |node| if node.is_a?(Prism::ClassNode) || node.is_a?(Prism::ModuleNode) || node.is_a?(Prism::SingletonClassNode) || node.is_a?(Prism::DefNode) locals.clear end locals.concat(node.locals) end locals end