Class: Solargraph::Pin::Signature

Inherits:
Callable show all
Defined in:
lib/solargraph/pin/signature.rb

Constant Summary

Constants included from Logging

Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS

Instance Attribute Summary collapse

Attributes inherited from Callable

#block, #parameters, #return_type

Attributes inherited from Closure

#scope

Attributes inherited from Base

#code_object, #combine_priority, #directives, #docstring, #name, #path, #return_type, #source

Attributes included from Common

#context

Instance Method Summary collapse

Methods inherited from Callable

#arity, #arity_matches?, #block?, #blockless_parameters, #choose_parameters, #combine_blocks, #combine_with, #mandatory_positional_param_count, #method_name, #method_namespace, #parameter_names, #resolve_generics_from_context, #resolve_generics_from_context_until_complete, #to_rbs, #transform_types

Methods inherited from Closure

#binder, #combine_with, #context, #gates, #generic_defaults, #rbs_generics, #to_rbs

Methods inherited from Base

#==, #all_location_text, #all_rooted?, #assert_location_provided, #assert_same, #assert_same_array_content, #assert_same_count, #assert_same_macros, #assert_source_provided, #best_location, #choose, #choose_longer, #choose_node, #choose_pin_attr, #choose_pin_attr_with_same_name, #choose_priority, #closure, #combine_directives, #combine_name, #combine_return_type, #combine_with, #comments, #completion_item_kind, #deprecated?, #desc, #erase_generics, #filename, #infer, #inner_desc, #inspect, #macros, #maybe_directives?, #nearly?, #needs_consistent_name?, #prefer_rbs_location, #presence_certain?, #probe, #probed?, #proxied?, #proxy, #rbs_location?, #realize, #reset_generated!, #resolve_generics, #resolve_generics_from_context, #symbol_kind, #to_rbs, #to_s, #transform_types, #type_desc, #variable?

Methods included from Logging

logger

Methods included from Documenting

#documentation, normalize_indentation, strip_html_comments

Methods included from Conversions

#completion_item, #completion_item_kind, #deprecated?, #detail, #link_documentation, #probed?, #proxied?, #reset_conversions, #resolve_completion_item, #signature_help, #text_documentation

Methods included from Common

#binder, #closure, #comments, #name, #namespace, #path, #return_type, #source

Constructor Details

#initialize(**splat) ⇒ Signature

Returns a new instance of Signature.



8
9
10
# File 'lib/solargraph/pin/signature.rb', line 8

def initialize **splat
  super(**splat)
end

Instance Attribute Details

#closure=(value) ⇒ Object (writeonly)

allow signature to be created before method pin, then set this to the method pin



6
7
8
# File 'lib/solargraph/pin/signature.rb', line 6

def closure=(value)
  @closure = value
end

Instance Method Details

#dodgy_return_type_source?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/solargraph/pin/signature.rb', line 22

def dodgy_return_type_source?
  super || closure&.dodgy_return_type_source?
end

#genericsObject



12
13
14
# File 'lib/solargraph/pin/signature.rb', line 12

def generics
  @generics ||= [].freeze
end

#identityObject



16
17
18
# File 'lib/solargraph/pin/signature.rb', line 16

def identity
  @identity ||= "signature#{object_id}"
end

#locationObject



30
31
32
# File 'lib/solargraph/pin/signature.rb', line 30

def location
  super || closure&.location
end

#type_locationObject



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

def type_location
  super || closure&.type_location
end

#typify(api_map) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/solargraph/pin/signature.rb', line 34

def typify api_map
  if return_type.defined?
    qualified = return_type.qualify(api_map, closure.namespace)
    logger.debug { "Signature#typify(self=#{self}) => #{qualified.rooted_tags.inspect}" }
    return qualified
  end
  return ComplexType::UNDEFINED if closure.nil?
  return ComplexType::UNDEFINED unless closure.is_a?(Pin::Method)
  # @sg-ignore need is_a? support
  # @type [Array<Pin::Method>]
  method_stack = closure.rest_of_stack api_map
  logger.debug { "Signature#typify(self=#{self}) - method_stack: #{method_stack}" }
  method_stack.each do |pin|
    sig = pin.signatures.find { |s| s.arity == self.arity }
    next unless sig
    unless sig.return_type.undefined?
      qualified = sig.return_type.qualify(api_map, closure.namespace)
      logger.debug { "Signature#typify(self=#{self}) => #{qualified.rooted_tags.inspect}" }
      return qualified
    end
  end
  out = super
  logger.debug { "Signature#typify(self=#{self}) => #{out}" }
  out
end