Class: Solargraph::Pin::Base

Inherits:
Object
  • Object
show all
Includes:
Logging, Common, Conversions, Documenting
Defined in:
lib/solargraph/pin/base.rb

Overview

The base class for map pins.

Constant Summary

Constants included from Logging

Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS

Instance Attribute Summary collapse

Attributes included from Common

#context

Instance Method Summary collapse

Methods included from Logging

log_level, logger

Methods included from Documenting

#documentation, normalize_indentation, strip_html_comments

Methods included from Conversions

#completion_item, #detail, #link_documentation, #reset_conversions, #resolve_completion_item, #signature_help, #text_documentation

Methods included from Common

#binder, #closure=, #each_closure, #namespace

Constructor Details

#initialize(location: nil, type_location: nil, closure: nil, source: nil, name: '', comments: '', docstring: nil, directives: nil, combine_priority: nil) ⇒ Base

Returns a new instance of Base.

Parameters:

  • location (Solargraph::Location, nil) (defaults to: nil)
  • type_location (Solargraph::Location, nil) (defaults to: nil)
  • closure (Solargraph::Pin::Closure, nil) (defaults to: nil)
  • name (String) (defaults to: '')
  • comments (String, nil) (defaults to: '')
  • source (Symbol, nil) (defaults to: nil)
  • docstring (YARD::Docstring, nil) (defaults to: nil)
  • directives (::Array<YARD::Tags::Directive>, nil) (defaults to: nil)
  • combine_priority (::Numeric, nil) (defaults to: nil)

    See attr_reader for combine_priority



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/solargraph/pin/base.rb', line 49

def initialize location: nil, type_location: nil, closure: nil, source: nil, name: '', comments: '',
               docstring: nil, directives: nil, combine_priority: nil
  @location = location
  @type_location = type_location
  @closure = closure
  @name = name
  @comments = comments
  @source = source
  @identity = nil
  @docstring = docstring
  @directives = directives
  @combine_priority = combine_priority
  # @type [ComplexType, ComplexType::UniqueType, nil]
  @binder = nil

  assert_source_provided
  assert_location_provided
end

Instance Attribute Details

#code_objectYARD::CodeObjects::Base (readonly)

Returns:

  • (YARD::CodeObjects::Base)


14
15
16
# File 'lib/solargraph/pin/base.rb', line 14

def code_object
  @code_object
end

#combine_priorityObject (readonly)

Returns the value of attribute combine_priority.



34
35
36
# File 'lib/solargraph/pin/base.rb', line 34

def combine_priority
  @combine_priority
end

#directives::Array<YARD::Tags::Directive>

@sg-ignore parse_comments will always set @directives

Returns:

  • (::Array<YARD::Tags::Directive>)


532
533
534
535
# File 'lib/solargraph/pin/base.rb', line 532

def directives
  parse_comments unless @directives
  @directives
end

#docstringYARD::Docstring

Returns:

  • (YARD::Docstring)


525
526
527
528
# File 'lib/solargraph/pin/base.rb', line 525

def docstring
  parse_comments unless @docstring
  @docstring ||= Solargraph::Source.parse_docstring('').to_docstring
end

#locationSolargraph::Location? (readonly)

Returns:



17
18
19
# File 'lib/solargraph/pin/base.rb', line 17

def location
  @location
end

#nameString (readonly)

Returns:

  • (String)


23
24
25
# File 'lib/solargraph/pin/base.rb', line 23

def name
  @name
end

#pathString (readonly)

Returns:

  • (String)


26
27
28
# File 'lib/solargraph/pin/base.rb', line 26

def path
  @path
end

#return_typeComplexType

The pin’s return type.

Returns:



520
521
522
# File 'lib/solargraph/pin/base.rb', line 520

def return_type
  @return_type ||= ComplexType::UNDEFINED
end

#source::Symbol

Returns:

  • (::Symbol)


29
30
31
# File 'lib/solargraph/pin/base.rb', line 29

def source
  @source
end

#type_locationSolargraph::Location? (readonly)

Returns:



20
21
22
# File 'lib/solargraph/pin/base.rb', line 20

def type_location
  @type_location
end

Instance Method Details

#==(other) ⇒ Object

Pin equality is determined using the #nearly? method and also requiring both pins to have the same location.

Parameters:

  • other (Object)


511
512
513
514
515
# File 'lib/solargraph/pin/base.rb', line 511

def == other
  return false unless nearly? other
  # @sg-ignore Should add more explicit type check on other
  comments == other.comments && location == other.location
end

#all_location_textString

Returns:

  • (String)


702
703
704
705
706
707
708
709
710
711
712
# File 'lib/solargraph/pin/base.rb', line 702

def all_location_text
  if location.nil? && type_location.nil?
    ''
  elsif !location.nil? && type_location.nil?
    " at #{location.inspect})"
  elsif !type_location.nil? && location.nil?
    " at #{type_location.inspect})"
  else
    " at (#{location.inspect} and #{type_location.inspect})"
  end
end

#all_rooted?Boolean

Returns:

  • (Boolean)


441
442
443
# File 'lib/solargraph/pin/base.rb', line 441

def all_rooted?
  !return_type || return_type.all_rooted?
end

#assert_location_providedvoid

This method returns an undefined value.



69
70
71
72
73
74
# File 'lib/solargraph/pin/base.rb', line 69

def assert_location_provided
  return unless best_location.nil? && %i[yardoc source rbs].include?(source)

  Solargraph.assert_or_log(:best_location,
                           "Neither location nor type_location provided - #{path} #{source} #{self.class}")
end

#assert_same(other, attr) ⇒ undefined

@sg-ignore

Parameters:

  • other (self)
  • attr (::Symbol)

Returns:

  • (undefined)


337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/solargraph/pin/base.rb', line 337

def assert_same other, attr
  if other.nil?
    Solargraph.assert_or_log(:"combine_with_#{attr}_nil",
                             "Other was passed in nil in assert_same on #{self}")
    return send(attr)
  end
  val1 = send(attr)
  val2 = other.send(attr)
  return val1 if val1 == val2
  Solargraph.assert_or_log(:"combine_with_#{attr}",
                           "Inconsistent #{attr.inspect} values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
  val1
end

#assert_same_array_content(other, attr) ⇒ void

TODO:

strong typechecking should complain when there are no block-related tags

This method returns an undefined value.

Parameters:

  • other (self)
  • attr (::Symbol)


296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/solargraph/pin/base.rb', line 296

def assert_same_array_content(other, attr, &)
  arr1 = send(attr)
  raise "Expected #{attr} on #{self} to be an Enumerable, got #{arr1.class}" unless arr1.is_a?(::Enumerable)
  # @type arr1 [::Enumerable]
  arr2 = other.send(attr)
  raise "Expected #{attr} on #{other} to be an Enumerable, got #{arr2.class}" unless arr2.is_a?(::Enumerable)
  # @type arr2 [::Enumerable]

  # @type [undefined]
  values1 = arr1.map(&)
  # @type [undefined]
  values2 = arr2.map(&)
  # @sg-ignore
  return arr1 if values1 == values2
  Solargraph.assert_or_log(:"combine_with_#{attr}",
                           "Inconsistent #{attr.inspect} values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self values = #{values1}\nother values =#{attr} = #{values2}")
  arr1
end

#assert_same_count(other, attr) ⇒ ::Enumerable

Parameters:

  • other (self)
  • attr (::Symbol)

Returns:

  • (::Enumerable)


319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/solargraph/pin/base.rb', line 319

def assert_same_count other, attr
  # @type [::Enumerable]
  arr1 = send(attr)
  raise "Expected #{attr} on #{self} to be an Enumerable, got #{arr1.class}" unless arr1.is_a?(::Enumerable)
  # @type [::Enumerable]
  arr2 = other.send(attr)
  raise "Expected #{attr} on #{other} to be an Enumerable, got #{arr2.class}" unless arr2.is_a?(::Enumerable)
  return arr1 if arr1.count == arr2.count
  Solargraph.assert_or_log(:"combine_with_#{attr}",
                           "Inconsistent #{attr.inspect} count value between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{arr1.inspect}\nother.#{attr} = #{arr2.inspect}")
  arr1
end

#assert_same_macros(other) ⇒ void

This method returns an undefined value.

Parameters:

  • other (self)


285
286
287
288
289
290
# File 'lib/solargraph/pin/base.rb', line 285

def assert_same_macros other
  return unless source == :yardoc && other.source == :yardoc
  assert_same_count(other, :macros)
  # @param [YARD::Tags::MacroDirective]
  assert_same_array_content(other, :macros) { |macro| macro.tag.name }
end

#assert_source_providedvoid

This method returns an undefined value.



404
405
406
# File 'lib/solargraph/pin/base.rb', line 404

def assert_source_provided
  Solargraph.assert_or_log(:source, "source not provided - #{@path} #{@source} #{self.class}") if source.nil?
end

#best_locationLocation?

Returns:



479
480
481
# File 'lib/solargraph/pin/base.rb', line 479

def best_location
  location || type_location
end

#choose(other, attr) ⇒ undefined?

when choices are arbitrary, make sure the choice is consistent

@sg-ignore

Parameters:

Returns:

  • (undefined, nil)


240
241
242
243
244
245
246
247
248
249
250
# File 'lib/solargraph/pin/base.rb', line 240

def choose other, attr
  results = [self, other].map(&attr).compact
  # true and false are different classes and can't be sorted

  return true if results.any? { |r| [true, false].include?(r) }
  return results.first if results.any? { |r| r.is_a? AST::Node }
  results.min
rescue StandardError
  warn("Problem handling #{attr} for \n#{inspect}\n and \n#{other.inspect}\n\n#{send(attr).inspect} vs #{other.send(attr).inspect}")
  raise
end

#choose_longer(other, attr) ⇒ undefined

@sg-ignore

Parameters:

  • other (self)
  • attr (::Symbol)

Returns:

  • (undefined)


139
140
141
142
143
144
145
146
147
# File 'lib/solargraph/pin/base.rb', line 139

def choose_longer other, attr
  # @type [undefined]
  val1 = send(attr)
  # @type [undefined]
  val2 = other.send(attr)
  return val1 if val1 == val2
  return val2 if val1.nil?
  val1.length > val2.length ? val1 : val2
end

#choose_node(other, attr) ⇒ undefined

@sg-ignore

Parameters:

  • other (self)
  • attr (::Symbol)

Returns:

  • (undefined)


256
257
258
259
260
261
262
# File 'lib/solargraph/pin/base.rb', line 256

def choose_node other, attr
  if other.object_id < attr.object_id
    other.send(attr)
  else
    send(attr)
  end
end

#choose_pin_attr(other, attr) ⇒ undefined

@sg-ignore Missing @return tag for Solargraph::Pin::Base#choose_pin_attr

Parameters:

  • other (self)
  • attr (::Symbol)

Returns:

  • (undefined)


376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/solargraph/pin/base.rb', line 376

def choose_pin_attr other, attr
  # @type [Pin::Base, nil]
  val1 = send(attr)
  # @type [Pin::Base, nil]
  val2 = other.send(attr)
  if val1.class != val2.class
    # :nocov:
    Solargraph.assert_or_log(:"combine_with_#{attr}_class",
                             "Inconsistent #{attr.inspect} class values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
    return val1
    # :nocov:
  end
  # arbitrary way of choosing a pin
  [val1, val2].compact.max_by do |closure|
    [
      # maximize number of gates, as types in other combined pins may
      # depend on those gates

      # @sg-ignore Need better handling of #compact
      closure.gates.length,
      # use basename so that results don't vary system to system
      # @sg-ignore Need better handling of #compact
      File.basename(closure.best_location.to_s)
    ]
  end
end

#choose_pin_attr_with_same_name(other, attr) ⇒ undefined

@sg-ignore

Parameters:

  • other (self)
  • attr (::Symbol)

Returns:

  • (undefined)


355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/solargraph/pin/base.rb', line 355

def choose_pin_attr_with_same_name other, attr
  # @type [Pin::Base, nil]
  val1 = send(attr)
  # @type [Pin::Base, nil]
  val2 = other.send(attr)
  raise "Expected pin for #{attr} on\n#{inspect},\ngot #{val1.inspect}" unless val1.nil? || val1.is_a?(Pin::Base)
  unless val2.nil? || val2.is_a?(Pin::Base)
    raise "Expected pin for #{attr} on\n#{other.inspect},\ngot #{val2.inspect}"
  end
  if val1&.name != val2&.name
    Solargraph.assert_or_log(:"combine_with_#{attr}_name",
                             "Inconsistent #{attr.inspect} name values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
  end
  choose_pin_attr(other, attr)
end

#choose_priority(other) ⇒ self?

Returns either the pin chosen based on priority or nil A nil return means that the combination process must proceed

Parameters:

  • other (self)

Returns:

  • (self, nil)

    Returns either the pin chosen based on priority or nil A nil return means that the combination process must proceed



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/solargraph/pin/base.rb', line 119

def choose_priority other
  if combine_priority.nil? && !other.combine_priority.nil?
    return other
  elsif other.combine_priority.nil? && !combine_priority.nil?
    return self
  elsif !combine_priority.nil? && !other.combine_priority.nil?
    if combine_priority > other.combine_priority
      return self
    elsif combine_priority < other.combine_priority
      return other
    end
  end

  nil
end

#closurePin::Closure?

Returns:



77
78
79
80
81
82
83
# File 'lib/solargraph/pin/base.rb', line 77

def closure
  unless @closure
    Solargraph.assert_or_log(:closure,
                             "Closure not set on #{self.class} #{name.inspect} from #{source.inspect}")
  end
  @closure
end

#combine_closure(other) ⇒ Pin::Closure?

Parameters:

  • other (self)

Returns:



160
161
162
# File 'lib/solargraph/pin/base.rb', line 160

def combine_closure other
  choose_pin_attr_with_same_name(other, :closure)
end

#combine_directives(other) ⇒ ::Array<YARD::Tags::Directive>?

Parameters:

  • other (self)

Returns:

  • (::Array<YARD::Tags::Directive>, nil)


152
153
154
155
156
# File 'lib/solargraph/pin/base.rb', line 152

def combine_directives other
  return directives if other.directives.empty?
  return other.directives if directives.empty?
  (directives + other.directives).uniq
end

#combine_name(other) ⇒ String

@sg-ignore @type should override probed type

Parameters:

  • other (self)

Returns:

  • (String)


167
168
169
170
171
172
173
# File 'lib/solargraph/pin/base.rb', line 167

def combine_name other
  if needs_consistent_name? || other.needs_consistent_name?
    assert_same(other, :name)
  else
    choose(other, :name)
  end
end

#combine_return_type(other) ⇒ ComplexType

Parameters:

  • other (self)

Returns:



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/solargraph/pin/base.rb', line 200

def combine_return_type other
  if return_type.undefined?
    other.return_type
  elsif other.return_type.undefined?
    return_type
  elsif return_type.erased_version_of?(other.return_type)
    other.return_type
  elsif other.return_type.erased_version_of?(return_type)
    return_type
  elsif dodgy_return_type_source? && !other.dodgy_return_type_source?
    other.return_type
  elsif other.dodgy_return_type_source? && !dodgy_return_type_source?
    return_type
  else
    all_items = return_type.items + other.return_type.items
    if all_items.any?(&:selfy?) && all_items.any? do |item|
      item.rooted_tag == context.reduce_class_type.rooted_tag
    end
      # assume this was a declaration that should have said 'self'
      all_items.delete_if { |item| item.rooted_tag == context.reduce_class_type.rooted_tag }
    end
    ComplexType.new(all_items)
  end
end

#combine_with(other, attrs = {}) ⇒ self

Parameters:

  • other (self)
  • attrs (Hash{::Symbol => Object}) (defaults to: {})

Returns:

  • (self)


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/solargraph/pin/base.rb', line 89

def combine_with other, attrs = {}
  priority_choice = choose_priority(other)
  return priority_choice unless priority_choice.nil?

  type_location = choose(other, :type_location)
  location = choose(other, :location)
  combined_name = combine_name(other)
  new_attrs = {
    location: location,
    type_location: type_location,
    name: combined_name,
    closure: combine_closure(other),
    comments: choose_longer(other, :comments),
    source: :combined,
    docstring: choose(other, :docstring),
    directives: combine_directives(other),
    combine_priority: combine_priority
  }.merge(attrs)
  assert_same_macros(other)
  logger.debug do
    "Base#combine_with(path=#{path}) - other.comments=#{other.comments.inspect}, self.comments = #{comments}"
  end
  out = self.class.new(**new_attrs)
  out.reset_generated!
  out
end

#commentsString

Returns:

  • (String)


409
410
411
# File 'lib/solargraph/pin/base.rb', line 409

def comments
  @comments ||= ''
end

#completion_item_kindInteger

Returns:

  • (Integer)


460
461
462
# File 'lib/solargraph/pin/base.rb', line 460

def completion_item_kind
  LanguageServer::CompletionItemKinds::KEYWORD
end

#deprecated?Boolean

Returns:

  • (Boolean)


565
566
567
# File 'lib/solargraph/pin/base.rb', line 565

def deprecated?
  @deprecated ||= docstring.has_tag?('deprecated')
end

#descString

Returns:

  • (String)


692
693
694
# File 'lib/solargraph/pin/base.rb', line 692

def desc
  "[#{inner_desc}]"
end

#dodgy_return_type_source?Boolean

@sg-ignore need boolish support for ? methods

Returns:

  • (Boolean)


226
227
228
229
230
231
# File 'lib/solargraph/pin/base.rb', line 226

def dodgy_return_type_source?
  # uses a lot of 'Object' instead of 'self'
  location&.filename&.include?('core_ext/object/') ||
    # ditto
    location&.filename&.include?('stdlib/date/0/date.rbs')
end

#erase_generics(generics_to_erase) ⇒ self

Parameters:

  • generics_to_erase (::Array<String>)

Returns:

  • (self)


447
448
449
450
# File 'lib/solargraph/pin/base.rb', line 447

def erase_generics generics_to_erase
  return self if generics_to_erase.empty?
  transform_types { |t| t.erase_generics(generics_to_erase) }
end

#filenameString?

Returns:

  • (String, nil)


453
454
455
456
457
# File 'lib/solargraph/pin/base.rb', line 453

def filename
  return nil if location.nil?
  # @sg-ignore flow sensitive typing needs to handle attrs
  location.filename
end

#gatesArray<String>

The namespaces available for resolving the current namespace. Each gate should be a fully qualified namespace or the root namespace (i.e., an empty string.)

Example: Given the name ‘Bar’ and the gates [‘Foo’, ”], the fully qualified namespace should be ‘Foo::Bar’ or ‘Bar’.

Returns:

  • (Array<String>)


659
660
661
# File 'lib/solargraph/pin/base.rb', line 659

def gates
  @gates ||= closure&.gates || ['']
end

#identityString

Deprecated.

Returns:

  • (String)


647
648
649
# File 'lib/solargraph/pin/base.rb', line 647

def identity
  @identity ||= "#{closure&.path}|#{name}|#{location}"
end

#infer(api_map) ⇒ ComplexType, ComplexType::UniqueType

Deprecated.

Use #typify and/or #probe instead

Parameters:

Returns:



601
602
603
604
605
606
607
# File 'lib/solargraph/pin/base.rb', line 601

def infer api_map
  Solargraph.assert_or_log(:pin_infer,
                           'WARNING: Pin #infer methods are deprecated. Use #typify or #probe instead.')
  type = typify(api_map)
  return type unless type.undefined?
  probe api_map
end

#inner_descString

Returns:

  • (String)


685
686
687
688
689
# File 'lib/solargraph/pin/base.rb', line 685

def inner_desc
  closure_info = closure&.name.inspect
  binder_info = binder&.desc
  "name=#{name.inspect} return_type=#{type_desc}, context=#{context.rooted_tags}, closure=#{closure_info}, binder=#{binder_info}"
end

#inspectString

Returns:

  • (String)


697
698
699
# File 'lib/solargraph/pin/base.rb', line 697

def inspect
  "#<#{self.class} `#{inner_desc}`#{all_location_text} via #{source.inspect}>"
end

#macro_namesObject



542
543
544
545
# File 'lib/solargraph/pin/base.rb', line 542

def macro_names
  parse_comments unless @macro_names
  @macro_names ||= collect_macro_names
end

#macro_names?Boolean

Returns:

  • (Boolean)


547
548
549
# File 'lib/solargraph/pin/base.rb', line 547

def macro_names?
  macro_names.any?
end

#macros::Array<Solargraph::YardMap::Macro>

Returns:



538
539
540
# File 'lib/solargraph/pin/base.rb', line 538

def macros
  @macros ||= collect_macros
end

#macros_names?Boolean

Returns:

  • (Boolean)


586
587
588
# File 'lib/solargraph/pin/base.rb', line 586

def macros_names?
  macro_names.any?
end

#maybe_directives?Boolean

Perform a quick check to see if this pin possibly includes YARD directives. This method does not require parsing the comments.

After the comments have been parsed, this method will return false if no directives were found, regardless of whether it previously appeared possible.

Returns:

  • (Boolean)


559
560
561
562
# File 'lib/solargraph/pin/base.rb', line 559

def maybe_directives?
  return !@directives.empty? if defined?(@directives) && @directives
  @maybe_directives ||= comments.include?('@!')
end

#maybe_macros?Boolean

TODO:

Candidate for deprecation (see ApiMap#process_macros)

Returns:

  • (Boolean)


582
583
584
# File 'lib/solargraph/pin/base.rb', line 582

def maybe_macros?
  comments.include?('@macro')        
end

#nearly?(other) ⇒ Boolean

True if the specified pin is a near match to this one. A near match indicates that the pins contain mostly the same data. Any differences between them should not have an impact on the API surface.

Parameters:

Returns:

  • (Boolean)


489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# File 'lib/solargraph/pin/base.rb', line 489

def nearly? other
  instance_of?(other.class) &&
    # @sg-ignore Translate to something flow sensitive typing understands
    name == other.name &&
    # @sg-ignore flow sensitive typing needs to handle attrs
    (closure == other.closure || (closure && closure.nearly?(other.closure))) &&
    # @sg-ignore Translate to something flow sensitive typing understands
    (comments == other.comments ||
     # @sg-ignore Translate to something flow sensitive typing understands
     (((maybe_directives? == false && other.maybe_directives? == false) ||
       compare_directives(directives,
                          # @sg-ignore Translate to something flow sensitive typing understands
                          other.directives)) &&
       # @sg-ignore Translate to something flow sensitive typing understands
       compare_docstring_tags(docstring, other.docstring))
    )
end

#needs_consistent_name?Boolean

Returns:

  • (Boolean)


194
195
196
# File 'lib/solargraph/pin/base.rb', line 194

def needs_consistent_name?
  true
end

#prefer_rbs_location(other, attr) ⇒ undefined

@sg-ignore

Parameters:

  • other (self)
  • attr (::Symbol)

Returns:

  • (undefined)


268
269
270
271
272
273
274
275
276
# File 'lib/solargraph/pin/base.rb', line 268

def prefer_rbs_location other, attr
  if rbs_location? && !other.rbs_location?
    send(attr)
  elsif !rbs_location? && other.rbs_location?
    other.send(attr)
  else
    choose(other, attr)
  end
end

#presence_certain?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/solargraph/pin/base.rb', line 36

def presence_certain?
  true
end

#probe(api_map) ⇒ ComplexType, ComplexType::UniqueType

Infer the pin’s return type via static code analysis.

Parameters:

Returns:



594
595
596
# File 'lib/solargraph/pin/base.rb', line 594

def probe api_map
  typify api_map
end

#probed?Boolean

Returns:

  • (Boolean)


613
614
615
# File 'lib/solargraph/pin/base.rb', line 613

def probed?
  @probed ||= false
end

#proxied?Boolean

Returns:

  • (Boolean)


609
610
611
# File 'lib/solargraph/pin/base.rb', line 609

def proxied?
  @proxied ||= false
end

#proxy(return_type) ⇒ self

Return a proxy for this pin with the specified return type. Other than the return type and the #proxied? setting, the proxy should be a clone of the original.

Parameters:

Returns:

  • (self)


636
637
638
639
640
641
642
643
# File 'lib/solargraph/pin/base.rb', line 636

def proxy return_type
  result = dup
  result.return_type = return_type
  result.proxied = true
  # Macros should have been processed already
  result.macro_names.clear
  result
end

#rbs_location?Boolean

@sg-ignore need boolish support for ? methods

Returns:

  • (Boolean)


279
280
281
# File 'lib/solargraph/pin/base.rb', line 279

def rbs_location?
  type_location&.rbs?
end

#realize(api_map) ⇒ self

Parameters:

Returns:

  • (self)


619
620
621
622
623
624
625
626
627
628
# File 'lib/solargraph/pin/base.rb', line 619

def realize api_map
  return self if return_type.defined?
  type = typify(api_map)
  return proxy(type) if type.defined?
  type = probe(api_map)
  return self if type.undefined?
  result = proxy(type)
  result.probed = true
  result
end

#reset_generated!void

This method returns an undefined value.



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/solargraph/pin/base.rb', line 176

def reset_generated!
  # @return_type doesn't go here as subclasses tend to assign it
  # themselves in constructors, and they will deal with setting
  # it in any methods that call this
  #
  # @docstring also doesn't go here, as there is code which
  # directly manipulates docstring without editing comments
  # (e.g., Api::Map::Store#index processes overrides that way
  #
  # Same with @directives, @macros, @maybe_directives, which
  # regenerate docstring
  @deprecated = nil
  @context = nil
  @binder = nil
  @path = nil
  reset_conversions
end

#resolve_generics(definitions, context_type) ⇒ self

Determine the concrete type for each of the generic type parameters used in this method based on the parameters passed into the its class and return a new method pin.

Parameters:

  • definitions (Pin::Namespace)

    The module/class which uses generic types

  • context_type (ComplexType)

    The receiver type

Returns:

  • (self)


437
438
439
# File 'lib/solargraph/pin/base.rb', line 437

def resolve_generics definitions, context_type
  transform_types { |t| t&.resolve_generics(definitions, context_type) }
end

#resolve_generics_from_context(generics_to_resolve, return_type_context = nil, resolved_generic_values: {}) ⇒ self

Parameters:

Returns:

  • (self)


417
418
419
420
421
# File 'lib/solargraph/pin/base.rb', line 417

def resolve_generics_from_context generics_to_resolve, return_type_context = nil, resolved_generic_values: {}
  proxy return_type.resolve_generics_from_context(generics_to_resolve,
                                                  return_type_context,
                                                  resolved_generic_values: resolved_generic_values)
end

#symbol_kindInteger?

Returns:

  • (Integer, nil)


465
466
467
# File 'lib/solargraph/pin/base.rb', line 465

def symbol_kind
  nil
end

#to_rbsString?

Returns:

  • (String, nil)


664
665
666
# File 'lib/solargraph/pin/base.rb', line 664

def to_rbs
  return_type.to_rbs
end

#to_sObject



469
470
471
# File 'lib/solargraph/pin/base.rb', line 469

def to_s
  desc
end

#transform_types {|| ... } ⇒ self

Yield Parameters:

Yield Returns:

Returns:

  • (self)


426
427
428
# File 'lib/solargraph/pin/base.rb', line 426

def transform_types &transform
  proxy return_type.transform(&transform)
end

#type_descString?

Returns:

  • (String, nil)


669
670
671
672
673
674
675
676
677
678
679
680
681
682
# File 'lib/solargraph/pin/base.rb', line 669

def type_desc
  rbs = to_rbs
  # RBS doesn't have a way to represent a Class<x> type
  rbs = return_type.rooted_tags if return_type.name == 'Class'
  if path
    if rbs
      "#{path} #{rbs}"
    else
      path
    end
  else
    rbs
  end
end

#typify(api_map) ⇒ ComplexType, ComplexType::UniqueType

Get a fully qualified type from the pin’s return type.

The relative type is determined from YARD documentation (@return, @param, @type, etc.) and its namespaces are fully qualified using the provided ApiMap.

Parameters:

Returns:



577
578
579
# File 'lib/solargraph/pin/base.rb', line 577

def typify api_map
  return_type.qualify(api_map, *(closure&.gates || ['']))
end

#variable?Boolean

Returns:

  • (Boolean)


474
475
476
# File 'lib/solargraph/pin/base.rb', line 474

def variable?
  false
end