Class: Solargraph::Pin::BaseVariable
- Inherits:
-
Base
- Object
- Base
- Solargraph::Pin::BaseVariable
show all
- Includes:
- ParserGem::NodeMethods
- Defined in:
- lib/solargraph/pin/base_variable.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#code_object, #location, #name, #path, #source, #type_location
Attributes included from Common
#closure, #context, #location
Instance Method Summary
collapse
Methods inherited from Base
#all_rooted?, #best_location, #comments, #deprecated?, #desc, #directives, #docstring, #erase_generics, #filename, #identity, #infer, #inspect, #macros, #maybe_directives?, #nearly?, #presence_certain?, #probed?, #proxied?, #proxy, #realize, #resolve_generics, #resolve_generics_from_context, #to_rbs, #to_s, #transform_types, #typify
#documentation, normalize_indentation, strip_html_comments
#completion_item, #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(assignment: nil, return_type: nil, **splat) ⇒ BaseVariable
Returns a new instance of BaseVariable.
16
17
18
19
20
21
22
|
# File 'lib/solargraph/pin/base_variable.rb', line 16
def initialize assignment: nil, return_type: nil, **splat
super(**splat)
@assignment = assignment
@mass_assignment = nil
@return_type = return_type
end
|
Instance Attribute Details
#assignment ⇒ Parser::AST::Node?
10
11
12
|
# File 'lib/solargraph/pin/base_variable.rb', line 10
def assignment
@assignment
end
|
#mass_assignment ⇒ Object
Returns the value of attribute mass_assignment.
12
13
14
|
# File 'lib/solargraph/pin/base_variable.rb', line 12
def mass_assignment
@mass_assignment
end
|
Instance Method Details
#==(other) ⇒ Object
97
98
99
100
|
# File 'lib/solargraph/pin/base_variable.rb', line 97
def == other
return false unless super
assignment == other.assignment
end
|
#completion_item_kind ⇒ Object
#nil_assignment? ⇒ Boolean
38
39
40
41
42
|
# File 'lib/solargraph/pin/base_variable.rb', line 38
def nil_assignment?
return_type.nil?
end
|
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/solargraph/pin/base_variable.rb', line 74
def probe api_map
unless @assignment.nil?
types = return_types_from_node(@assignment, api_map)
return ComplexType.new(types.uniq) unless types.empty?
end
unless @mass_assignment.nil?
mass_node, index = @mass_assignment
types = return_types_from_node(mass_node, api_map)
types.map! do |type|
if type.tuple?
type.all_params[index]
elsif ['::Array', '::Set', '::Enumerable'].include?(type.rooted_name)
type.all_params.first
end
end.compact!
return ComplexType.new(types.uniq) unless types.empty?
end
ComplexType::UNDEFINED
end
|
#return_type ⇒ Object
33
34
35
|
# File 'lib/solargraph/pin/base_variable.rb', line 33
def return_type
@return_type ||= generate_complex_type
end
|
#return_types_from_node(parent_node, api_map) ⇒ ::Array<ComplexType>
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/solargraph/pin/base_variable.rb', line 51
def return_types_from_node(parent_node, api_map)
types = []
value_position_nodes_only(parent_node).each do |node|
if node.nil? || node.type == :NIL || node.type == :nil
types.push ComplexType::NIL
else
rng = Range.from_node(node)
next if rng.nil?
pos = rng.ending
clip = api_map.clip_at(location.filename, pos)
chain = Parser.chain(node, nil, nil)
result = chain.infer(api_map, closure, clip.locals).self_to_type(closure.context)
types.push result unless result.undefined?
end
end
types
end
|
#try_merge!(pin) ⇒ Object
103
104
105
106
107
108
|
# File 'lib/solargraph/pin/base_variable.rb', line 103
def try_merge! pin
return false unless super
@assignment = pin.assignment
@return_type = pin.return_type
true
end
|
#type_desc ⇒ Object
110
111
112
|
# File 'lib/solargraph/pin/base_variable.rb', line 110
def type_desc
"#{super} = #{assignment&.type.inspect}"
end
|
#variable? ⇒ Boolean
44
45
46
|
# File 'lib/solargraph/pin/base_variable.rb', line 44
def variable?
true
end
|