Module: Solargraph::GemPins

Defined in:
lib/solargraph/gem_pins.rb

Overview

A utility for building gem pins from a combination of YARD and RBS documentation.

Class Method Summary collapse

Class Method Details

.build(gemspec) ⇒ Array<Pin::Base>

Build an array of pins from a gem specification. The process starts with YARD, enhances the resulting pins with RBS definitions, and appends RBS pins that don’t exist in the YARD mapping.

Parameters:

  • gemspec (Gem::Specification)

Returns:



16
17
18
19
20
# File 'lib/solargraph/gem_pins.rb', line 16

def self.build(gemspec)
  yard_pins = build_yard_pins(gemspec)
  rbs_map = RbsMap.from_gemspec(gemspec)
  combine yard_pins, rbs_map
end

.combine(yard_pins, rbs_map) ⇒ Array<Pin::Base>

Parameters:

Returns:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/solargraph/gem_pins.rb', line 25

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