module Solargraph::GemPins

def self.build(gemspec)

Returns:
  • (Array) -

Parameters:
  • gemspec (Gem::Specification) --
def self.build(gemspec)
  yard_pins = build_yard_pins(gemspec)
  rbs_map = RbsMap.from_gemspec(gemspec)
  combine yard_pins, rbs_map
end

def self.combine(yard_pins, rbs_map)

Returns:
  • (Array) -

Parameters:
  • rbs_map (RbsMap) --
  • yard_pins (Array) --
def self.combine(yard_pins, rbs_map)
  in_yard = Set.new
  combined = yard_pins.map do |yard|
    in_yard.add yard.path
    next yard unless yard.is_a?(Pin::Method)
    rbs = rbs_map.path_pin(yard.path, Pin::Method)
    next yard unless rbs
    # @sg-ignore

    yard.class.new(
      location: yard.location,
      closure: yard.closure,
      name: yard.name,
      comments: yard.comments,
      scope: yard.scope,
      parameters: rbs.parameters,
      generics: rbs.generics,
      node: yard.node,
      signatures: yard.signatures,
      return_type: best_return_type(rbs.return_type, yard.return_type)
    )
  end
  in_rbs = rbs_map.pins.reject { |pin| in_yard.include?(pin.path) }
  combined + in_rbs
end

def best_return_type *choices

Returns:
  • (ComplexType) -

Parameters:
  • choices (Array) --
def best_return_type *choices
  choices.find { |pin| pin.defined? } || choices.first || ComplexType::UNDEFINED
end

def build_yard_pins(gemspec)

Returns:
  • (Array) -

Parameters:
  • gemspec (Gem::Specification) --
def build_yard_pins(gemspec)
  Yardoc.cache(gemspec) unless Yardoc.cached?(gemspec)
  yardoc = Yardoc.load!(gemspec)
  YardMap::Mapper.new(yardoc, gemspec).map
end