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

Attributes inherited from Base

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

Attributes included from Common

#closure, #context, #location

Instance Method Summary collapse

Methods inherited from BaseVariable

#==, #completion_item_kind, #desc, #nil_assignment?, #probe, #return_type, #symbol_kind, #variable?

Methods inherited from Base

#==, #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, #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, **splat) ⇒ LocalVariable

Returns a new instance of LocalVariable.

Parameters:

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


12
13
14
15
16
# File 'lib/solargraph/pin/local_variable.rb', line 12

def initialize assignment: nil, presence: nil, **splat
  super(**splat)
  @assignment = assignment
  @presence = presence
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

#to_rbsString

Returns:

  • (String)


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

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

#try_merge!(pin) ⇒ Object

Parameters:

  • pin (self)


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

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

#visible_at?(other_closure, other_loc) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/solargraph/pin/local_variable.rb', line 27

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