Class: Solargraph::Pin::Parameter
Instance Attribute Summary collapse
#presence
Attributes inherited from BaseVariable
#assignment, #mass_assignment
Attributes inherited from Base
#code_object, #location, #name, #path, #source, #type_location
Attributes included from Common
#closure, #context, #location
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_rooted?, #best_location, #comments, #completion_item_kind, #deprecated?, #desc, #directives, #docstring, #erase_generics, #filename, #identity, #infer, #inspect, #macros, #maybe_directives?, #nearly?, #presence_certain?, #probe, #probed?, #proxied?, #proxy, #realize, #resolve_generics, #resolve_generics_from_context, #symbol_kind, #to_s, #transform_types, #type_desc, #variable?
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(decl: :arg, asgn_code: nil, **splat) ⇒ Parameter
14
15
16
17
18
|
# File 'lib/solargraph/pin/parameter.rb', line 14
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
|
#decl ⇒ ::Symbol
7
8
9
|
# File 'lib/solargraph/pin/parameter.rb', line 7
def decl
@decl
end
|
Instance Method Details
#arg? ⇒ Boolean
28
29
30
|
# File 'lib/solargraph/pin/parameter.rb', line 28
def arg?
decl == :arg
end
|
#block? ⇒ Boolean
40
41
42
|
# File 'lib/solargraph/pin/parameter.rb', line 40
def block?
[:block, :blockarg].include?(decl)
end
|
#compatible_arg?(atype, api_map) ⇒ Boolean
118
119
120
121
122
123
|
# File 'lib/solargraph/pin/parameter.rb', line 118
def compatible_arg?(atype, api_map)
ptype = typify api_map
ptype.undefined? || ptype.can_assign?(api_map, atype) || ptype.generic?
end
|
#documentation ⇒ Object
125
126
127
128
129
|
# File 'lib/solargraph/pin/parameter.rb', line 125
def documentation
tag = param_tag
return '' if tag.nil? || tag.text.nil?
tag.text
end
|
#full ⇒ String
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/solargraph/pin/parameter.rb', line 62
def full
case decl
when :optarg
"#{name} = #{asgn_code || '?'}"
when :kwarg
"#{name}:"
when :kwoptarg
"#{name}: #{asgn_code || '?'}"
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.
104
105
106
107
108
|
# File 'lib/solargraph/pin/parameter.rb', line 104
def index
method_pin = closure
method_pin.parameter_names.index(name)
end
|
#keyword? ⇒ Boolean
20
21
22
|
# File 'lib/solargraph/pin/parameter.rb', line 20
def keyword?
[:kwarg, :kwoptarg].include?(decl)
end
|
#kwrestarg? ⇒ Boolean
24
25
26
|
# File 'lib/solargraph/pin/parameter.rb', line 24
def kwrestarg?
decl == :kwrestarg || (assignment && [:HASH, :hash].include?(assignment.type))
end
|
#rest? ⇒ Boolean
36
37
38
|
# File 'lib/solargraph/pin/parameter.rb', line 36
def rest?
decl == :restarg || decl == :kwrestarg
end
|
#restarg? ⇒ Boolean
32
33
34
|
# File 'lib/solargraph/pin/parameter.rb', line 32
def restarg?
decl == :restarg
end
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/solargraph/pin/parameter.rb', line 82
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/solargraph/pin/parameter.rb', line 44
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
|
#try_merge!(pin) ⇒ Object
132
133
134
135
|
# File 'lib/solargraph/pin/parameter.rb', line 132
def try_merge! pin
return false unless super && closure == pin.closure
true
end
|
#typify(api_map) ⇒ Object
111
112
113
114
|
# File 'lib/solargraph/pin/parameter.rb', line 111
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
|