Class: Solargraph::Parser::Rubyvm::NodeProcessors::SclassNode

Inherits:
NodeProcessor::Base show all
Defined in:
lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb

Instance Attribute Summary

Attributes inherited from NodeProcessor::Base

#locals, #node, #pins, #region

Instance Method Summary collapse

Methods inherited from NodeProcessor::Base

#initialize

Constructor Details

This class inherits a constructor from Solargraph::Parser::NodeProcessor::Base

Instance Method Details

#processObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb', line 8

def process
  sclass = node.children[0]
  if sclass.is_a?(RubyVM::AbstractSyntaxTree::Node) && sclass.type == :SELF
    closure = region.closure
  elsif sclass.is_a?(RubyVM::AbstractSyntaxTree::Node) && %i[CDECL CONST].include?(sclass.type)
    names = [region.closure.namespace, region.closure.name]
    if names.last != sclass.children[0].to_s
      names << sclass.children[0].to_s
    end
    name = names.reject(&:empty?).join('::')
    closure = Solargraph::Pin::Namespace.new(name: name, location: region.closure.location)
  else
    return
  end
  pins.push Solargraph::Pin::Singleton.new(
    location: get_node_location(node),
    closure: closure
  )
  process_children region.update(visibility: :public, scope: :class, closure: pins.last)
end