Class: Solargraph::Pin::BaseVariable
- Inherits:
-
Base
- Object
- Base
- Solargraph::Pin::BaseVariable
show all
- Includes:
- (rubyvm? ? Rubyvm::NodeMethods : Legacy(rubyvm? ? Rubyvm::NodeMethods : Legacy::NodeMethods)
- Defined in:
- lib/solargraph/pin/base_variable.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#code_object, #location, #name, #path
Attributes included from Common
#closure, #location
Instance Method Summary
collapse
Methods inherited from Base
#comments, #deprecated?, #directives, #docstring, #filename, #identity, #infer, #inspect, #macros, #maybe_directives?, #nearly?, #probed?, #proxied?, #proxy, #realize, #to_s, #typify
#documentation
#completion_item, #detail, #link_documentation, #reset_conversions, #resolve_completion_item, #signature_help, #text_documentation
Methods included from Common
#binder, #comments, #context, #name, #namespace, #path
Constructor Details
#initialize(assignment: nil, **splat) ⇒ BaseVariable
Returns a new instance of BaseVariable.
13
14
15
16
|
# File 'lib/solargraph/pin/base_variable.rb', line 13
def initialize assignment: nil, **splat
super(**splat)
@assignment = assignment
end
|
Instance Attribute Details
#assignment ⇒ Parser::AST::Node?
10
11
12
|
# File 'lib/solargraph/pin/base_variable.rb', line 10
def assignment
@assignment
end
|
Instance Method Details
#==(other) ⇒ Object
62
63
64
65
|
# File 'lib/solargraph/pin/base_variable.rb', line 62
def == other
return false unless super
assignment == other.assignment
end
|
#completion_item_kind ⇒ Object
#nil_assignment? ⇒ Boolean
31
32
33
|
# File 'lib/solargraph/pin/base_variable.rb', line 31
def nil_assignment?
return_type.nil?
end
|
#probe(api_map) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/solargraph/pin/base_variable.rb', line 39
def probe api_map
return ComplexType::UNDEFINED if @assignment.nil?
types = []
returns_from(@assignment).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, clip.in_block?)
result = chain.infer(api_map, closure, clip.locals)
types.push result unless result.undefined?
end
end
return ComplexType::UNDEFINED if types.empty?
ComplexType.try_parse(*types.map(&:tag))
end
|
#return_type ⇒ Object
27
28
29
|
# File 'lib/solargraph/pin/base_variable.rb', line 27
def return_type
@return_type ||= generate_complex_type
end
|
#try_merge!(pin) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/solargraph/pin/base_variable.rb', line 67
def try_merge! pin
return false unless super
@assignment = pin.assignment
@return_type = pin.return_type
true
end
|
#variable? ⇒ Boolean
35
36
37
|
# File 'lib/solargraph/pin/base_variable.rb', line 35
def variable?
true
end
|