Class: Solargraph::Pin::Parameter
Constant Summary
Constants included
from Logging
Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS
Instance Attribute Summary collapse
#presence
Attributes inherited from BaseVariable
#assignment, #mass_assignment
Attributes inherited from Base
#code_object, #combine_priority, #directives, #docstring, #name, #path, #source
Attributes included from Common
#context
Instance Method Summary
collapse
#presence_certain?, #visible_at?
#==, #completion_item_kind, #nil_assignment?, #probe, #return_types_from_node, #symbol_kind, #type_desc, #variable?
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, #comments, #completion_item_kind, #deprecated?, #desc, #dodgy_return_type_source?, #erase_generics, #filename, #identity, #infer, #inner_desc, #inspect, #macros, #maybe_directives?, #nearly?, #prefer_rbs_location, #presence_certain?, #probe, #probed?, #proxied?, #proxy, #rbs_location?, #realize, #reset_generated!, #resolve_generics, #resolve_generics_from_context, #symbol_kind, #to_s, #transform_types, #type_desc, #variable?
Methods included from Logging
logger
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, #closure, #comments, #name, #namespace, #path, #source
Constructor Details
#initialize(decl: :arg, asgn_code: nil, **splat) ⇒ Parameter
Returns a new instance of Parameter.
18
19
20
21
22
|
# File 'lib/solargraph/pin/parameter.rb', line 18
def initialize decl: :arg, asgn_code: nil, **splat
super(**splat)
@asgn_code = asgn_code
@decl = decl
end
|
Instance Attribute Details
#asgn_code ⇒ String
10
11
12
|
# File 'lib/solargraph/pin/parameter.rb', line 10
def asgn_code
@asgn_code
end
|
#closure=(value) ⇒ Object
allow this to be set to the method after the method itself has been created
14
15
16
|
# File 'lib/solargraph/pin/parameter.rb', line 14
def closure=(value)
@closure = value
end
|
#decl ⇒ ::Symbol
7
8
9
|
# File 'lib/solargraph/pin/parameter.rb', line 7
def decl
@decl
end
|
Instance Method Details
#arg? ⇒ Boolean
75
76
77
|
# File 'lib/solargraph/pin/parameter.rb', line 75
def arg?
decl == :arg
end
|
#arity_decl ⇒ String
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/solargraph/pin/parameter.rb', line 54
def arity_decl
name = (self.name || '(anon)')
type = (return_type&.to_rbs || 'untyped')
case decl
when :arg
""
when :optarg
"?"
when :kwarg
"#{name}:"
when :kwoptarg
"?#{name}:"
when :restarg
"*"
when :kwrestarg
"**"
else
"(unknown decl: #{decl})"
end
end
|
#block? ⇒ Boolean
87
88
89
|
# File 'lib/solargraph/pin/parameter.rb', line 87
def block?
[:block, :blockarg].include?(decl)
end
|
#combine_with(other, attrs = {}) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/solargraph/pin/parameter.rb', line 32
def combine_with(other, attrs={})
new_attrs = {
decl: assert_same(other, :decl),
presence: choose(other, :presence),
asgn_code: choose(other, :asgn_code),
}.merge(attrs)
super(other, new_attrs)
end
|
#compatible_arg?(atype, api_map) ⇒ Boolean
175
176
177
178
179
180
|
# File 'lib/solargraph/pin/parameter.rb', line 175
def compatible_arg?(atype, api_map)
ptype = typify api_map
ptype.undefined? || ptype.can_assign?(api_map, atype) || ptype.generic?
end
|
#documentation ⇒ Object
182
183
184
185
186
|
# File 'lib/solargraph/pin/parameter.rb', line 182
def documentation
tag = param_tag
return '' if tag.nil? || tag.text.nil?
tag.text
end
|
#full ⇒ String
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/solargraph/pin/parameter.rb', line 127
def full
full_name + case decl
when :optarg
" = #{asgn_code || '?'}"
when :kwoptarg
" #{asgn_code || '?'}"
else
''
end
end
|
#full_name ⇒ String
Returns the full name of the parameter, including any declarative symbols such as ‘*` or `:` indicating type of parameter. This is used in method signatures.
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/solargraph/pin/parameter.rb', line 111
def full_name
case decl
when :kwarg, :kwoptarg
"#{name}:"
when :restarg
"*#{name}"
when :kwrestarg
"**#{name}"
when :block, :blockarg
"&#{name}"
else
name
end
end
|
#index ⇒ Integer
The parameter’s zero-based location in the block’s signature.
161
162
163
164
165
|
# File 'lib/solargraph/pin/parameter.rb', line 161
def index
method_pin = closure
method_pin.parameter_names.index(name)
end
|
#keyword? ⇒ Boolean
41
42
43
|
# File 'lib/solargraph/pin/parameter.rb', line 41
def keyword?
[:kwarg, :kwoptarg].include?(decl)
end
|
#kwrestarg? ⇒ Boolean
45
46
47
|
# File 'lib/solargraph/pin/parameter.rb', line 45
def kwrestarg?
decl == :kwrestarg || (assignment && [:HASH, :hash].include?(assignment.type))
end
|
#location ⇒ Object
28
29
30
|
# File 'lib/solargraph/pin/parameter.rb', line 28
def location
super || closure&.type_location
end
|
#needs_consistent_name? ⇒ Boolean
49
50
51
|
# File 'lib/solargraph/pin/parameter.rb', line 49
def needs_consistent_name?
keyword?
end
|
#rest? ⇒ Boolean
83
84
85
|
# File 'lib/solargraph/pin/parameter.rb', line 83
def rest?
decl == :restarg || decl == :kwrestarg
end
|
#restarg? ⇒ Boolean
79
80
81
|
# File 'lib/solargraph/pin/parameter.rb', line 79
def restarg?
decl == :restarg
end
|
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/solargraph/pin/parameter.rb', line 139
def return_type
if @return_type.nil?
@return_type = ComplexType::UNDEFINED
found = param_tag
@return_type = ComplexType.try_parse(*found.types) unless found.nil? or found.types.nil?
if @return_type.undefined?
if decl == :restarg
@return_type = ComplexType.try_parse('::Array')
elsif decl == :kwrestarg
@return_type = ComplexType.try_parse('::Hash')
elsif decl == :blockarg
@return_type = ComplexType.try_parse('::Proc')
end
end
end
super
@return_type
end
|
#to_rbs ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/solargraph/pin/parameter.rb', line 91
def to_rbs
case decl
when :optarg
"?#{super}"
when :kwarg
"#{name}: #{return_type.to_rbs}"
when :kwoptarg
"?#{name}: #{return_type.to_rbs}"
when :restarg
"*#{super}"
when :kwrestarg
"**#{super}"
else
super
end
end
|
#type_location ⇒ Object
24
25
26
|
# File 'lib/solargraph/pin/parameter.rb', line 24
def type_location
super || closure&.type_location
end
|
#typify(api_map) ⇒ Object
168
169
170
171
|
# File 'lib/solargraph/pin/parameter.rb', line 168
def typify api_map
return return_type.qualify(api_map, closure.context.namespace) unless return_type.undefined?
closure.is_a?(Pin::Block) ? typify_block_param(api_map) : typify_method_param(api_map)
end
|