Class: Solargraph::Pin::Callable
Instance Attribute Summary collapse
Attributes inherited from Closure
#scope
Attributes inherited from Base
#code_object, #location, #name, #path, #source, #type_location
Attributes included from Common
#closure, #context, #location
Instance Method Summary
collapse
-
#arity_matches?(arguments, with_block) ⇒ Boolean
-
#block? ⇒ Boolean
-
#initialize(block: nil, return_type: nil, parameters: [], **splat) ⇒ Callable
constructor
A new instance of Callable.
-
#mandatory_positional_param_count ⇒ Object
-
#method_namespace ⇒ Object
-
#parameter_names ⇒ ::Array<String>
-
#resolve_generics_from_context(generics_to_resolve, arg_types = nil, return_type_context = nil, yield_arg_types = nil, yield_return_type_context = nil, resolved_generic_values: {}) ⇒ self
-
#resolve_generics_from_context_until_complete(generics_to_resolve, arg_types = nil, return_type_context = nil, yield_arg_types = nil, yield_return_type_context = nil, resolved_generic_values: {}) ⇒ self
-
#to_rbs ⇒ String
-
#transform_types {|| ... } ⇒ Array<String>, self
Methods inherited from Closure
#binder, #context, #gates, #generic_defaults, #generics, #rbs_generics
Methods inherited from Base
#==, #all_location_text, #all_rooted?, #assert_source_provided, #best_location, #comments, #completion_item_kind, #deprecated?, #desc, #directives, #docstring, #erase_generics, #filename, #identity, #infer, #inner_desc, #inspect, #macros, #maybe_directives?, #nearly?, #presence_certain?, #probe, #probed?, #proxied?, #proxy, #realize, #reset_generated!, #resolve_generics, #symbol_kind, #to_s, #try_merge!, #type_desc, #typify, #variable?
#documentation, normalize_indentation, strip_html_comments
#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, #comments, #name, #namespace, #path
Constructor Details
#initialize(block: nil, return_type: nil, parameters: [], **splat) ⇒ Callable
Returns a new instance of Callable.
17
18
19
20
21
22
|
# File 'lib/solargraph/pin/callable.rb', line 17
def initialize block: nil, return_type: nil, parameters: [], **splat
super(**splat)
@block = block
@return_type = return_type
@parameters = parameters
end
|
Instance Attribute Details
7
8
9
|
# File 'lib/solargraph/pin/callable.rb', line 7
def block
@block
end
|
#parameters ⇒ Object
Returns the value of attribute parameters.
9
10
11
|
# File 'lib/solargraph/pin/callable.rb', line 9
def parameters
@parameters
end
|
12
13
14
|
# File 'lib/solargraph/pin/callable.rb', line 12
def return_type
@return_type
end
|
Instance Method Details
#arity_matches?(arguments, with_block) ⇒ Boolean
122
123
124
125
126
127
128
129
|
# File 'lib/solargraph/pin/callable.rb', line 122
def arity_matches? arguments, with_block
argcount = arguments.length
parcount = mandatory_positional_param_count
parcount -= 1 if !parameters.empty? && parameters.last.block?
return false if block? && !with_block
return false if argcount < parcount && !(argcount == parcount - 1 && parameters.last.restarg?)
true
end
|
#block? ⇒ Boolean
140
141
142
|
# File 'lib/solargraph/pin/callable.rb', line 140
def block?
!!@block
end
|
#mandatory_positional_param_count ⇒ Object
131
132
133
|
# File 'lib/solargraph/pin/callable.rb', line 131
def mandatory_positional_param_count
parameters.count(&:arg?)
end
|
#method_namespace ⇒ Object
24
25
26
|
# File 'lib/solargraph/pin/callable.rb', line 24
def method_namespace
closure.namespace
end
|
#parameter_names ⇒ ::Array<String>
29
30
31
|
# File 'lib/solargraph/pin/callable.rb', line 29
def parameter_names
@parameter_names ||= parameters.map(&:name)
end
|
#resolve_generics_from_context(generics_to_resolve, arg_types = nil, return_type_context = nil, yield_arg_types = nil, yield_return_type_context = nil, resolved_generic_values: {}) ⇒ self
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/solargraph/pin/callable.rb', line 41
def resolve_generics_from_context(generics_to_resolve,
arg_types = nil,
return_type_context = nil,
yield_arg_types = nil,
yield_return_type_context = nil,
resolved_generic_values: {})
callable = super(generics_to_resolve, return_type_context, resolved_generic_values: resolved_generic_values)
callable.parameters = callable.parameters.each_with_index.map do |param, i|
if arg_types.nil?
param.dup
else
param.resolve_generics_from_context(generics_to_resolve,
arg_types[i],
resolved_generic_values: resolved_generic_values)
end
end
callable.block = block.resolve_generics_from_context(generics_to_resolve,
yield_arg_types,
yield_return_type_context,
resolved_generic_values: resolved_generic_values) if callable.block?
callable
end
|
#resolve_generics_from_context_until_complete(generics_to_resolve, arg_types = nil, return_type_context = nil, yield_arg_types = nil, yield_return_type_context = nil, resolved_generic_values: {}) ⇒ self
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
98
99
100
101
102
103
|
# File 'lib/solargraph/pin/callable.rb', line 72
def resolve_generics_from_context_until_complete(generics_to_resolve,
arg_types = nil,
return_type_context = nil,
yield_arg_types = nil,
yield_return_type_context = nil,
resolved_generic_values: {})
return self if generics_to_resolve.empty?
last_resolved_generic_values = resolved_generic_values.dup
new_pin = resolve_generics_from_context(generics_to_resolve,
arg_types,
return_type_context,
yield_arg_types,
yield_return_type_context,
resolved_generic_values: resolved_generic_values)
if last_resolved_generic_values == resolved_generic_values
return new_pin.erase_generics(self.generics)
end
new_pin.resolve_generics_from_context_until_complete(generics_to_resolve,
arg_types,
return_type_context,
yield_arg_types,
yield_return_type_context,
resolved_generic_values: resolved_generic_values)
end
|
#to_rbs ⇒ String
136
137
138
|
# File 'lib/solargraph/pin/callable.rb', line 136
def to_rbs
rbs_generics + '(' + parameters.map { |param| param.to_rbs }.join(', ') + ') ' + (block.nil? ? '' : '{ ' + block.to_rbs + ' } ') + '-> ' + return_type.to_rbs
end
|
109
110
111
112
113
114
115
116
117
|
# File 'lib/solargraph/pin/callable.rb', line 109
def transform_types(&transform)
callable = super(&transform)
callable.block = block.transform_types(&transform) if block?
callable.parameters = parameters.map do |param|
param.transform_types(&transform)
end
callable
end
|