class Solargraph::Pin::LocalVariable

Attributes

presence[R]

@return [Range]

Public Class Methods

new(assignment: nil, presence: nil, **splat) click to toggle source
Calls superclass method Solargraph::Pin::BaseVariable::new
# File lib/solargraph/pin/local_variable.rb, line 9
def initialize assignment: nil, presence: nil, **splat
  super(**splat)
  @assignment = assignment
  @presence = presence
end

Public Instance Methods

try_merge!(pin) click to toggle source
# File lib/solargraph/pin/local_variable.rb, line 15
def try_merge! pin
  return false unless super
  @presence = pin.presence
  true
end
visible_at?(other_closure, other_loc) click to toggle source

@param other_closure [Pin::Closure] @param other_loc [Location]

# File lib/solargraph/pin/local_variable.rb, line 23
def visible_at?(other_closure, other_loc)
  return true if location.filename == other_loc.filename &&
    presence.include?(other_loc.range.start) &&
    match_named_closure(other_closure, closure)
end

Private Instance Methods

match_named_closure(needle, haystack) click to toggle source
# File lib/solargraph/pin/local_variable.rb, line 43
def match_named_closure needle, haystack
  return true if needle == haystack || haystack.is_a?(Pin::Block)
  cursor = haystack
  until cursor.nil?
    return true if needle.path == cursor.path
    return false if cursor.path && !cursor.path.empty?
    cursor = cursor.closure
  end
  false
end
match_tags(tag1, tag2) click to toggle source

@param tag1 [String] @param tag2 [String] @return [Boolean]

# File lib/solargraph/pin/local_variable.rb, line 34
def match_tags tag1, tag2
  # @todo This is an unfortunate hack made necessary by a discrepancy in
  #   how tags indicate the root namespace. The long-term solution is to
  #   standardize it, whether it's `Class<>`, an empty string, or
  #   something else.
  tag1 == tag2 ||
    (['', 'Class<>'].include?(tag1) && ['', 'Class<>'].include?(tag2))
end