Class: Solargraph::Pin::Block
- Defined in:
- lib/solargraph/pin/block.rb
Instance Attribute Summary collapse
- #node ⇒ Parser::AST::Node readonly
- #receiver ⇒ Parser::AST::Node readonly
Attributes inherited from Closure
Attributes inherited from Base
#code_object, #location, #name, #path, #return_type, #source
Attributes included from Common
Instance Method Summary collapse
- #binder ⇒ Object
- #destructure_yield_types(yield_types, parameters) ⇒ ::Array<ComplexType>
-
#initialize(receiver: nil, args: [], context: nil, node: nil, **splat) ⇒ Block
constructor
A new instance of Block.
- #parameter_names ⇒ ::Array<String>
- #parameters ⇒ ::Array<Parameter>
- #rebind(api_map) ⇒ void
- #typify_parameters(api_map) ⇒ ::Array<ComplexType>
Methods inherited from Closure
#context, #gates, #generics, #generics_as_rbs
Methods inherited from Base
#==, #comments, #completion_item_kind, #deprecated?, #desc, #directives, #docstring, #erase_generics, #filename, #identity, #infer, #inspect, #macros, #maybe_directives?, #nearly?, #probe, #probed?, #proxied?, #proxy, #realize, #resolve_generics, #resolve_generics_from_context, #symbol_kind, #to_rbs, #to_s, #transform_types, #try_merge!, #typify, #variable?
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
#comments, #name, #namespace, #path, #return_type
Constructor Details
#initialize(receiver: nil, args: [], context: nil, node: nil, **splat) ⇒ Block
Returns a new instance of Block.
16 17 18 19 20 21 22 23 |
# File 'lib/solargraph/pin/block.rb', line 16 def initialize receiver: nil, args: [], context: nil, node: nil, **splat super(**splat) @receiver = receiver @context = context @parameters = args @return_type = ComplexType.parse('::Proc') @node = node end |
Instance Attribute Details
#node ⇒ Parser::AST::Node (readonly)
10 11 12 |
# File 'lib/solargraph/pin/block.rb', line 10 def node @node end |
#receiver ⇒ Parser::AST::Node (readonly)
7 8 9 |
# File 'lib/solargraph/pin/block.rb', line 7 def receiver @receiver end |
Instance Method Details
#binder ⇒ Object
31 32 33 |
# File 'lib/solargraph/pin/block.rb', line 31 def binder @rebind&.defined? ? @rebind : closure.binder end |
#destructure_yield_types(yield_types, parameters) ⇒ ::Array<ComplexType>
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/solargraph/pin/block.rb', line 49 def destructure_yield_types(yield_types, parameters) return yield_types if yield_types.length == parameters.length # yielding a tuple into a block will destructure the tuple if yield_types.length == 1 yield_type = yield_types.first return yield_type.all_params if yield_type.tuple? && yield_type.all_params.length == parameters.length end parameters.map { ComplexType::UNDEFINED } end |
#parameter_names ⇒ ::Array<String>
41 42 43 |
# File 'lib/solargraph/pin/block.rb', line 41 def parameter_names @parameter_names ||= parameters.map(&:name) end |
#parameters ⇒ ::Array<Parameter>
36 37 38 |
# File 'lib/solargraph/pin/block.rb', line 36 def parameters @parameters ||= [] end |
#rebind(api_map) ⇒ void
This method returns an undefined value.
27 28 29 |
# File 'lib/solargraph/pin/block.rb', line 27 def rebind api_map @rebind ||= maybe_rebind(api_map) end |
#typify_parameters(api_map) ⇒ ::Array<ComplexType>
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/solargraph/pin/block.rb', line 69 def typify_parameters(api_map) chain = Parser.chain(receiver, filename, node) clip = api_map.clip_at(location.filename, location.range.start) locals = clip.locals - [self] meths = chain.define(api_map, closure, locals) # @todo Convert logic to use signatures meths.each do |meth| next if meth.block.nil? yield_types = meth.block.parameters.map(&:return_type) # 'arguments' is what the method says it will yield to the # block; 'parameters' is what the block accepts argument_types = destructure_yield_types(yield_types, parameters) param_types = argument_types.each_with_index.map do |arg_type, idx| param = parameters[idx] param_type = chain.base.infer(api_map, param, locals) unless arg_type.nil? if arg_type.generic? && param_type.defined? namespace_pin = api_map.get_namespace_pins(meth.namespace, closure.namespace).first arg_type.resolve_generics(namespace_pin, param_type) else arg_type.self_to(chain.base.infer(api_map, self, locals).namespace).qualify(api_map, meth.context.namespace) end end end return param_types if param_types.all?(&:defined?) end parameters.map { ComplexType::UNDEFINED } end |