class Solargraph::Pin::BaseVariable
Attributes
@return [Parser::AST::Node, nil]
Public Class Methods
Source
# File lib/solargraph/pin/base_variable.rb, line 17 def initialize assignment: nil, return_type: nil, mass_assignment: nil, **splat super(**splat) @assignment = assignment # @type [nil, ::Array(Parser::AST::Node, Integer)] @mass_assignment = nil @return_type = return_type end
@param return_type [ComplexType, nil] @param mass_assignment [::Array(Parser::AST::Node, Integer), nil] @param assignment [Parser::AST::Node, nil]
Calls superclass method
Solargraph::Pin::Base::new
Public Instance Methods
Source
# File lib/solargraph/pin/base_variable.rb, line 106 def == other return false unless super # @sg-ignore Should add type check on other assignment == other.assignment end
@param other [Object]
Calls superclass method
Solargraph::Pin::Base#==
Source
# File lib/solargraph/pin/base_variable.rb, line 25 def combine_with(other, attrs={}) new_attrs = attrs.merge({ assignment: assert_same(other, :assignment), mass_assignment: assert_same(other, :mass_assignment), return_type: combine_return_type(other), }) super(other, new_attrs) end
Calls superclass method
Solargraph::Pin::Base#combine_with
Source
# File lib/solargraph/pin/base_variable.rb, line 34 def completion_item_kind Solargraph::LanguageServer::CompletionItemKinds::VARIABLE end
Source
# File lib/solargraph/pin/base_variable.rb, line 47 def nil_assignment? # this will always be false - should it be return_type == # ComplexType::NIL or somesuch? return_type.nil? end
Source
# File lib/solargraph/pin/base_variable.rb, line 83 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
@param api_map [ApiMap] @return [ComplexType]
Source
# File lib/solargraph/pin/base_variable.rb, line 43 def return_type @return_type ||= generate_complex_type end
Source
# File lib/solargraph/pin/base_variable.rb, line 60 def return_types_from_node(parent_node, api_map) types = [] value_position_nodes_only(parent_node).each do |node| # Nil nodes may not have a location 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) # Use the return node for inference. The clip might infer from the # first node in a method call instead of the entire call. 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
@param parent_node [Parser::AST::Node] @param api_map [ApiMap] @return [::Array<ComplexType>]
Source
# File lib/solargraph/pin/base_variable.rb, line 39 def symbol_kind Solargraph::LanguageServer::SymbolKinds::VARIABLE end
@return [Integer]
Source
# File lib/solargraph/pin/base_variable.rb, line 112 def type_desc "#{super} = #{assignment&.type.inspect}" end
Private Instance Methods
Source
# File lib/solargraph/pin/base_variable.rb, line 119 def generate_complex_type tag = docstring.tag(:type) return ComplexType.try_parse(*tag.types) unless tag.nil? || tag.types.nil? || tag.types.empty? ComplexType.new end
@return [ComplexType]