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
-
.build(gemspec) ⇒ Array<Pin::Base>
Build an array of pins from a gem specification.
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.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/solargraph/gem_pins.rb', line 16 def self.build(gemspec) yard_pins = build_yard_pins(gemspec) rbs_map = RbsMap.from_gemspec(gemspec) 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) next yard unless rbs # @todo Could not include: attribute and anon_splat # @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 |