Class: Solargraph::Pin::Block
Instance Attribute Summary collapse
Attributes included from Breakable
#location
Attributes inherited from Callable
#block, #parameters, #return_type
Attributes inherited from Closure
#scope
Instance Method Summary
collapse
Methods inherited from Callable
#arity, #arity_matches?, #block?, #blockless_parameters, #choose_parameters, #combine_blocks, #combine_with, #full_type_arity, #generics, #mandatory_positional_param_count, #method_name, #method_namespace, #parameter_names, #parameters_to_rbs, #reset_generated!, #resolve_generics_from_context, #resolve_generics_from_context_until_complete, #to_rbs, #transform_types, #type_arity, #typify
Methods inherited from Closure
#combine_with, #generic_defaults, #generics, #rbs_generics, #to_rbs
Constructor Details
#initialize(receiver: nil, args: [], context: nil, node: nil, **splat) ⇒ Block
Returns a new instance of Block.
19
20
21
22
23
24
25
26
|
# File 'lib/solargraph/pin/block.rb', line 19
def initialize receiver: nil, args: [], context: nil, node: nil, **splat
super(**splat, parameters: args)
@receiver = receiver
@context = context
@return_type = ComplexType.parse('::Proc')
@node = node
@name = '<block>'
end
|
Instance Attribute Details
#node ⇒ Parser::AST::Node
12
13
14
|
# File 'lib/solargraph/pin/block.rb', line 12
def node
@node
end
|
#receiver ⇒ Parser::AST::Node
9
10
11
|
# File 'lib/solargraph/pin/block.rb', line 9
def receiver
@receiver
end
|
Instance Method Details
#binder ⇒ Object
34
35
36
37
|
# File 'lib/solargraph/pin/block.rb', line 34
def binder
out = @rebind if @rebind&.defined?
out ||= super
end
|
#context ⇒ Object
39
40
41
42
|
# File 'lib/solargraph/pin/block.rb', line 39
def context
@context = @rebind if @rebind&.defined?
super
end
|
#destructure_yield_types(yield_types, parameters) ⇒ ::Array<ComplexType>
48
49
50
51
52
53
54
55
|
# File 'lib/solargraph/pin/block.rb', line 48
def destructure_yield_types yield_types, parameters
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.with_index { |_, idx| yield_types[idx] || ComplexType::UNDEFINED }
end
|
#rebind(api_map) ⇒ void
This method returns an undefined value.
30
31
32
|
# File 'lib/solargraph/pin/block.rb', line 30
def rebind api_map
@rebind ||= maybe_rebind(api_map)
end
|
#typify_parameters(api_map) ⇒ ::Array<ComplexType>
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/solargraph/pin/block.rb', line 59
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)
meths.each do |meth|
next if meth.block.nil?
yield_types = meth.block.parameters.map(&:return_type)
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_type(chain.base.infer(api_map, self, locals)).qualify(api_map, *meth.gates)
end
end
end
return param_types if param_types.all?(&:defined?)
end
parameters.map { ComplexType::UNDEFINED }
end
|