Class: Solargraph::Source::Chain::Constant

Inherits:
Link
  • Object
show all
Defined in:
lib/solargraph/source/chain/constant.rb

Constant Summary

Constants included from Logging

Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS

Instance Attribute Summary

Attributes inherited from Link

#last_context, #word

Instance Method Summary collapse

Methods inherited from Link

#clone_body, #clone_head, #constant?, #desc, #head?, #inspect, #nullable?, #to_s, #undefined?

Methods included from Logging

logger

Methods included from Equality

#==, #eql?, #equality_fields, #freeze, #hash

Constructor Details

#initialize(word) ⇒ Constant

Returns a new instance of Constant.



7
8
9
# File 'lib/solargraph/source/chain/constant.rb', line 7

def initialize word
  @word = word
end

Instance Method Details

#resolve(api_map, name_pin, locals) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/solargraph/source/chain/constant.rb', line 11

def resolve api_map, name_pin, locals
  return [Pin::ROOT_PIN] if word.empty?
  if word.start_with?('::')
    base = word[2..-1]
    gates = ['']
  else
    base = word
    gates = crawl_gates(name_pin)
  end
  parts = base.split('::')
  gates.each do |gate|
    # @todo 'Wrong argument type for
    #   Solargraph::Source::Chain::Constant#deep_constant_type:
    #   gate expected String, received generic<Elem>' is because
    #   we lose 'rooted' information in the 'Chain::Array' class
    #   internally, leaving ::Array#each shadowed when it
    #   shouldn't be.
    type = deep_constant_type(gate, api_map)
    # Use deep inference to resolve root
    parts[0..-2].each do |sym|
      pins = api_map.get_constants('', type.namespace).select{ |pin| pin.name == sym }
      type = first_pin_type(pins, api_map)
      break if type.undefined?
    end
    next if type.undefined?
    result = api_map.get_constants('', type.namespace).select { |pin| pin.name == parts.last }
    return result unless result.empty?
  end
  []
end