Class: Solargraph::Pin::BaseVariable

Inherits:
Base
  • Object
show all
Includes:
Source::NodeMethods
Defined in:
lib/solargraph/pin/base_variable.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#code_object, #kind, #location, #name, #path

Attributes included from Common

#closure, #location

Instance Method Summary collapse

Methods included from Source::NodeMethods

const_from, drill_signature, get_node_end_position, get_node_start_position, infer_literal_node_type, pack_name, resolve_node_signature, returns_from, unpack_name

Methods inherited from Base

#comments, #deprecated?, #directives, #docstring, #filename, #infer, #inspect, #macros, #maybe_directives?, #nearly?, #probed?, #proxied?, #proxy, #realize, #to_s, #typify

Methods included from Documenting

#documentation

Methods included from Conversions

#completion_item, #detail, #link_documentation, #reset_conversions, #resolve_completion_item, #signature_help

Methods included from Common

#binder, #comments, #context, #kind, #name, #namespace, #path

Constructor Details

#initialize(assignment: nil, **splat) ⇒ BaseVariable


8
9
10
11
# File 'lib/solargraph/pin/base_variable.rb', line 8

def initialize assignment: nil, **splat
  super(splat)
  @assignment = assignment
end

Instance Attribute Details

#assignmentObject (readonly)

Returns the value of attribute assignment


6
7
8
# File 'lib/solargraph/pin/base_variable.rb', line 6

def assignment
  @assignment
end

Instance Method Details

#==(other) ⇒ Object


53
54
55
56
# File 'lib/solargraph/pin/base_variable.rb', line 53

def == other
  return false unless super
  assignment == other.assignment
end

#completion_item_kindObject


17
18
19
# File 'lib/solargraph/pin/base_variable.rb', line 17

def completion_item_kind
  Solargraph::LanguageServer::CompletionItemKinds::VARIABLE
end

#nil_assignment?Boolean


30
31
32
# File 'lib/solargraph/pin/base_variable.rb', line 30

def nil_assignment?
  return_type.nil?
end

#probe(api_map) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/solargraph/pin/base_variable.rb', line 38

def probe api_map
  return ComplexType::UNDEFINED if @assignment.nil?
  types = []
  returns_from(@assignment).each do |node|
    chain = Source::NodeChainer.chain(node, filename)
    next if chain.links.first.word == name
    clip = api_map.clip_at(location.filename, location.range.start)
    locals = clip.locals - [self]
    result = chain.infer(api_map, closure, locals)
    types.push result unless result.undefined?
  end
  return ComplexType::UNDEFINED if types.empty?
  ComplexType.try_parse(*types.map(&:tag))
end

#return_typeObject


26
27
28
# File 'lib/solargraph/pin/base_variable.rb', line 26

def return_type
  @return_type ||= generate_complex_type
end

#signatureObject


13
14
15
# File 'lib/solargraph/pin/base_variable.rb', line 13

def signature
  @signature ||= resolve_node_signature(@assignment)
end

#symbol_kindInteger


22
23
24
# File 'lib/solargraph/pin/base_variable.rb', line 22

def symbol_kind
  Solargraph::LanguageServer::SymbolKinds::VARIABLE
end

#try_merge!(pin) ⇒ Object


58
59
60
61
62
63
# File 'lib/solargraph/pin/base_variable.rb', line 58

def try_merge! pin
  return false unless super
  @assignment = pin.assignment
  @return_type = pin.return_type
  true
end

#variable?Boolean


34
35
36
# File 'lib/solargraph/pin/base_variable.rb', line 34

def variable?
  true
end