class Solargraph::Pin::BaseVariable

Attributes

assignment[R]

@return [Parser::AST::Node, nil]

Public Class Methods

new(assignment: nil, **splat) click to toggle source

@param assignment [Parser::AST::Node, nil]

Calls superclass method Solargraph::Pin::Base::new
# File lib/solargraph/pin/base_variable.rb, line 13
def initialize assignment: nil, **splat
  super(**splat)
  @assignment = assignment
end

Public Instance Methods

==(other) click to toggle source
Calls superclass method Solargraph::Pin::Base#==
# File lib/solargraph/pin/base_variable.rb, line 62
def == other
  return false unless super
  assignment == other.assignment
end
completion_item_kind() click to toggle source
# File lib/solargraph/pin/base_variable.rb, line 18
def completion_item_kind
  Solargraph::LanguageServer::CompletionItemKinds::VARIABLE
end
nil_assignment?() click to toggle source
# File lib/solargraph/pin/base_variable.rb, line 31
def nil_assignment?
  return_type.nil?
end
probe(api_map) click to toggle source
# File lib/solargraph/pin/base_variable.rb, line 39
def probe api_map
  return ComplexType::UNDEFINED if @assignment.nil?
  types = []
  returns_from(@assignment).each do |node|
    # Nil nodes may not have a location
    if node.nil? || node.type == :NIL || node.type == :nil
      types.push ComplexType::NIL
    else
      rng = Range.from_node(node)
      next if rng.nil?
      pos = rng.ending
      clip = api_map.clip_at(location.filename, pos)
      # Use the return node for inference. The clip might infer from the
      # first node in a method call instead of the entire call.
      chain = Parser.chain(node, nil, clip.in_block?)
      result = chain.infer(api_map, closure, clip.locals)
      types.push result unless result.undefined?
    end
  end
  return ComplexType::UNDEFINED if types.empty?
  ComplexType.try_parse(*types.map(&:tag))
end
return_type() click to toggle source
# File lib/solargraph/pin/base_variable.rb, line 27
def return_type
  @return_type ||= generate_complex_type
end
symbol_kind() click to toggle source

@return [Integer]

# File lib/solargraph/pin/base_variable.rb, line 23
def symbol_kind
  Solargraph::LanguageServer::SymbolKinds::VARIABLE
end
try_merge!(pin) click to toggle source
Calls superclass method Solargraph::Pin::Base#try_merge!
# File lib/solargraph/pin/base_variable.rb, line 67
def try_merge! pin
  return false unless super
  @assignment = pin.assignment
  @return_type = pin.return_type
  true
end
variable?() click to toggle source
# File lib/solargraph/pin/base_variable.rb, line 35
def variable?
  true
end

Private Instance Methods

generate_complex_type() click to toggle source

@return [ComplexType]

# File lib/solargraph/pin/base_variable.rb, line 77
def generate_complex_type
  tag = docstring.tag(:type)
  return ComplexType.try_parse(*tag.types) unless tag.nil? || tag.types.nil? || tag.types.empty?
  ComplexType.new
end