Class: Solargraph::Pin::LocalVariable

Inherits:
BaseVariable show all
Defined in:
lib/solargraph/pin/local_variable.rb

Direct Known Subclasses

Parameter

Constant Summary

Constants included from Logging

Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS

Instance Attribute Summary collapse

Attributes inherited from BaseVariable

#assignment, #mass_assignment

Attributes inherited from Base

#code_object, #combine_priority, #directives, #docstring, #location, #name, #path, #return_type, #source, #type_location

Attributes included from Common

#context, #location

Instance Method Summary collapse

Methods inherited from BaseVariable

#==, #completion_item_kind, #nil_assignment?, #probe, #return_type, #return_types_from_node, #symbol_kind, #type_desc, #variable?

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, #completion_item_kind, #deprecated?, #desc, #dodgy_return_type_source?, #erase_generics, #filename, #identity, #infer, #inner_desc, #inspect, #macros, #maybe_directives?, #nearly?, #needs_consistent_name?, #prefer_rbs_location, #probe, #probed?, #proxied?, #proxy, #rbs_location?, #realize, #reset_generated!, #resolve_generics, #resolve_generics_from_context, #symbol_kind, #to_s, #transform_types, #type_desc, #typify, #variable?

Methods included from Logging

logger

Methods included from Documenting

#documentation, normalize_indentation, strip_html_comments

Methods included from Conversions

#completion_item, #completion_item_kind, #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, #return_type, #source

Constructor Details

#initialize(assignment: nil, presence: nil, presence_certain: false, **splat) ⇒ LocalVariable



17
18
19
20
21
22
# File 'lib/solargraph/pin/local_variable.rb', line 17

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

Instance Attribute Details

#presenceRange (readonly)



7
8
9
# File 'lib/solargraph/pin/local_variable.rb', line 7

def presence
  @presence
end

Instance Method Details

#combine_with(other, attrs = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/solargraph/pin/local_variable.rb', line 24

def combine_with(other, attrs={})
  new_attrs = {
    assignment: assert_same(other, :assignment),
    presence_certain: assert_same(other, :presence_certain?),
  }.merge(attrs)
  # @sg-ignore Wrong argument type for

  #   Solargraph::Pin::Base#assert_same: other expected

  #   Solargraph::Pin::Base, received self

  new_attrs[:presence] = assert_same(other, :presence) unless attrs.key?(:presence)

  super(other, new_attrs)
end

#presence_certain?Boolean



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

def presence_certain?
  @presence_certain
end

#to_rbsString



46
47
48
# File 'lib/solargraph/pin/local_variable.rb', line 46

def to_rbs
  (name || '(anon)') + ' ' + (return_type&.to_rbs || 'untyped')
end

#visible_at?(other_closure, other_loc) ⇒ Boolean



39
40
41
42
43
# File 'lib/solargraph/pin/local_variable.rb', line 39

def visible_at?(other_closure, other_loc)
  location.filename == other_loc.filename &&
    presence.include?(other_loc.range.start) &&
    match_named_closure(other_closure, closure)
end