module Solargraph::Pin::Localized

Attributes

presence[R]

@return [Range]

Public Instance Methods

visible_at?(other_loc) click to toggle source

@param other_loc [Location]

# File lib/solargraph/pin/localized.rb, line 23
def visible_at?(other_loc)
  return false if location.filename != other_loc.filename
  presence.include?(other_loc.range.start)
end
visible_from?(other, position) click to toggle source

@param other [Pin::Base] The caller's block @param position [Position, Array(Integer, Integer)] The caller's position @return [Boolean]

# File lib/solargraph/pin/localized.rb, line 12
def visible_from?(other, position)
  position = Position.normalize(position)
  other.filename == filename &&
    match_tags(other.full_context.tag, full_context.tag) &&
    (other == closure ||
      (closure.location.range.contain?(other.location.range.start) && closure.location.range.contain?(other.location.range.ending))
    ) &&
    presence.contain?(position)
end

Private Instance Methods

match_tags(tag1, tag2) click to toggle source

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

# File lib/solargraph/pin/localized.rb, line 33
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