Class: Solargraph::Pin::LocalVariable

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

Direct Known Subclasses

Parameter

Instance Attribute Summary collapse

Attributes inherited from BaseVariable

#assignment, #mass_assignment

Attributes inherited from Base

#code_object, #location, #name, #path, #return_type, #source, #type_location

Attributes included from Common

#closure, #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_rooted?, #best_location, #comments, #completion_item_kind, #deprecated?, #desc, #directives, #docstring, #erase_generics, #filename, #identity, #infer, #inspect, #macros, #maybe_directives?, #nearly?, #probe, #probed?, #proxied?, #proxy, #realize, #resolve_generics, #resolve_generics_from_context, #symbol_kind, #to_s, #transform_types, #type_desc, #typify, #variable?

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, #comments, #name, #namespace, #path, #return_type

Constructor Details

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

Returns a new instance of LocalVariable.

Parameters:

  • assignment (AST::Node, nil) (defaults to: nil)
  • presence (Range, nil) (defaults to: nil)
  • presence_certain (Boolean) (defaults to: false)
  • splat (Hash)


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)

Returns:



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

def presence
  @presence
end

Instance Method Details

#presence_certain?Boolean

Returns:

  • (Boolean)


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

def presence_certain?
  @presence_certain
end

#to_rbsString

Returns:

  • (String)


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

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

#try_merge!(pin) ⇒ Object

Parameters:

  • pin (self)


25
26
27
28
29
# File 'lib/solargraph/pin/local_variable.rb', line 25

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

#visible_at?(other_closure, other_loc) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/solargraph/pin/local_variable.rb', line 33

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