class Solargraph::SourceMap


that can be queried.
An index of Pins and other ApiMap-related data for a single Source

def _locate_pin line, character, *klasses

Returns:
  • (Pin::Base, nil) -

Parameters:
  • klasses (Array) --
  • character (Integer) --
  • line (Integer) --
def _locate_pin line, character, *klasses
  position = Position.new(line, character)
  found = nil
  pins.each do |pin|
    # @todo Attribute pins should not be treated like closures, but

    #   there's probably a better way to handle it

    next if pin.is_a?(Pin::Method) && pin.attribute?
    found = pin if (klasses.empty? || klasses.any? { |kls| pin.is_a?(kls) } ) && pin.location.range.contain?(position)
    break if pin.location.range.start.line > line
  end
  # Assuming the root pin is always valid

  found || pins.first
end

def api_hash

Returns:
  • (Integer) -
def api_hash
  @api_hash ||= (pins_by_class(Pin::Constant) + pins_by_class(Pin::Namespace).select { |pin| pin.namespace.to_s > '' } + pins_by_class(Pin::Reference) + pins_by_class(Pin::Method).map(&:node) + locals).hash
end

def code

Returns:
  • (String) -
def code
  source.code
end

def convention_pins

Returns:
  • (Array) -
def convention_pins
  @convention_pins || []
end

def convention_pins=(pins)

Returns:
  • (Array) -

Parameters:
  • pins (Array) --
def convention_pins=(pins)
  # unmemoizing the document_symbols in case it was called from any of conventions

  @document_symbols = nil
  @convention_pins = pins
end

def cursor_at position

Returns:
  • (Source::Cursor) -

Parameters:
  • position (Position) --
def cursor_at position
  Source::Cursor.new(source, position)
end

def data

def data
  @data ||= Data.new(source)
end

def document_symbols

Returns:
  • (Array) -
def document_symbols
  @document_symbols ||= (pins + convention_pins).select do |pin|
    pin.path && !pin.path.empty?
  end
end

def environ

Returns:
  • (Environ) -
def environ
  @environ ||= Environ.new
end

def filename

Returns:
  • (String) -
def filename
  source.filename
end

def first_pin path

Returns:
  • (Pin::Base) -

Parameters:
  • path (String) --
def first_pin path
  pins.select { |p| p.path == path }.first
end

def initialize source

Parameters:
  • source (Source) --
def initialize source
  @source = source
  environ.merge Convention.for_local(self) unless filename.nil?
  self.convention_pins = environ.pins
  @pin_select_cache = {}
end

def load filename

Returns:
  • (SourceMap) -

Parameters:
  • filename (String) --
def load filename
  source = Solargraph::Source.load(filename)
  SourceMap.map(source)
end

def load_string code, filename = nil

Returns:
  • (SourceMap) -

Parameters:
  • filename (String, nil) --
  • code (String) --
def load_string code, filename = nil
  source = Solargraph::Source.load_string(code, filename)
  SourceMap.map(source)
end

def locals

Returns:
  • (Array) -
def locals
  data.locals
end

def locals_at(location)

Returns:
  • (Array) -

Parameters:
  • location (Location) --
def locals_at(location)
  return [] if location.filename != filename
  closure = locate_named_path_pin(location.range.start.line, location.range.start.character)
  locals.select { |pin| pin.visible_at?(closure, location) }
end

def locate_block_pin line, character

Returns:
  • (Pin::Namespace, Pin::Method, Pin::Block) -

Parameters:
  • character (Integer) --
  • line (Integer) --
def locate_block_pin line, character
  _locate_pin line, character, Pin::Namespace, Pin::Method, Pin::Block
end

def locate_named_path_pin line, character

Returns:
  • (Pin::Method, Pin::Namespace) -

Parameters:
  • character (Integer) --
  • line (Integer) --
def locate_named_path_pin line, character
  _locate_pin line, character, Pin::Namespace, Pin::Method
end

def locate_pins location

Returns:
  • (Array) -

Parameters:
  • location (Solargraph::Location) --
def locate_pins location
  # return nil unless location.start_with?("#{filename}:")

  (pins + locals).select { |pin| pin.location == location }
end

def map source

Returns:
  • (SourceMap) -

Parameters:
  • source (Source) --

Deprecated:
def map source
  new(source)
end

def pin_class_hash

def pin_class_hash
  @pin_class_hash ||= pins.to_set.classify(&:class).transform_values(&:to_a)
end

def pins

Returns:
  • (Array) -
def pins
  data.pins
end

def pins_by_class klass

Returns:
  • (Array) -

Parameters:
  • klass (Class) --
def pins_by_class klass
  @pin_select_cache[klass] ||= pin_class_hash.select { |key, _| key <= klass }.values.flatten
end

def query_symbols query

Returns:
  • (Array) -

Parameters:
  • query (String) --
def query_symbols query
  Pin::Search.new(document_symbols, query).results
end

def references name

Returns:
  • (Array) -

Parameters:
  • name (String) --
def references name
  source.references name
end

def requires

Returns:
  • (Array) -
def requires
  pins_by_class(Pin::Reference::Require)
end

def try_merge! other_map

Returns:
  • (Boolean) -

Parameters:
  • other_map (SourceMap) --

Other tags:
    Todo: - Candidate for deprecation
def try_merge! other_map
  return false if pins.length != other_map.pins.length || locals.length != other_map.locals.length || requires.map(&:name).uniq.sort != other_map.requires.map(&:name).uniq.sort
  pins.each_index do |i|
    return false unless pins[i].try_merge!(other_map.pins[i])
  end
  locals.each_index do |i|
    return false unless locals[i].try_merge!(other_map.locals[i])
  end
  @source = other_map.source
  true
end