Class: Solargraph::Pin::BaseVariable
- Inherits:
-
Base
- Object
- Base
- Solargraph::Pin::BaseVariable
show all
- Includes:
- ParserGem::NodeMethods
- Defined in:
- lib/solargraph/pin/base_variable.rb
Constant Summary
Constants included
from Logging
Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS
Instance Attribute Summary collapse
Attributes inherited from Base
#code_object, #combine_priority, #directives, #docstring, #location, #name, #path, #source, #type_location
Attributes included from Common
#context, #location
Instance Method Summary
collapse
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, #deprecated?, #desc, #dodgy_return_type_source?, #erase_generics, #filename, #identity, #infer, #inner_desc, #inspect, #macros, #maybe_directives?, #nearly?, #needs_consistent_name?, #prefer_rbs_location, #presence_certain?, #probed?, #proxied?, #proxy, #rbs_location?, #realize, #reset_generated!, #resolve_generics, #resolve_generics_from_context, #to_rbs, #to_s, #transform_types, #typify
Methods included from Logging
logger
#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, #closure, #comments, #name, #namespace, #path, #source
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
105
106
107
108
|
# File 'lib/solargraph/pin/base_variable.rb', line 105
def == other
return false unless super
assignment == other.assignment
end
|
#combine_with(other, attrs = {}) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/solargraph/pin/base_variable.rb', line 24
def combine_with(other, attrs={})
attrs.merge({
assignment: assert_same(other, :assignment),
mass_assignment: assert_same(other, :mass_assignment),
return_type: combine_return_type(other),
})
super(other, attrs)
end
|
#completion_item_kind ⇒ Object
#nil_assignment? ⇒ Boolean
46
47
48
49
50
|
# File 'lib/solargraph/pin/base_variable.rb', line 46
def nil_assignment?
return_type.nil?
end
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/solargraph/pin/base_variable.rb', line 82
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
42
43
44
|
# File 'lib/solargraph/pin/base_variable.rb', line 42
def return_type
@return_type ||= generate_complex_type
end
|
#return_types_from_node(parent_node, api_map) ⇒ ::Array<ComplexType>
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/solargraph/pin/base_variable.rb', line 59
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
|
#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
52
53
54
|
# File 'lib/solargraph/pin/base_variable.rb', line 52
def variable?
true
end
|