Class: Solargraph::Source::Chain::Call

Inherits:
Link
  • Object
show all
Includes:
ParserGem::NodeMethods
Defined in:
lib/solargraph/source/chain/call.rb

Overview

Handles both method calls and local variable references by first looking for a variable with the name ‘word’, then proceeding to method signature resolution if not found.

Direct Known Subclasses

QCall, ZSuper

Constant Summary

Constants included from Logging

Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS

Instance Attribute Summary collapse

Attributes inherited from Link

#last_context

Instance Method Summary collapse

Methods inherited from Link

#clone_body, #clone_head, #constant?, #desc, #head?, #inspect, #nullable?, #to_s, #undefined?

Methods included from Logging

log_level, logger

Methods included from Equality

#==, #eql?, #freeze, #hash

Constructor Details

#initialize(word, location = nil, arguments = [], block = nil) ⇒ Call

Returns a new instance of Call.

Parameters:

  • word (String)
  • location (Location, nil) (defaults to: nil)
  • arguments (::Array<Chain>) (defaults to: [])
  • block (Chain, nil) (defaults to: nil)


30
31
32
33
34
35
36
37
# File 'lib/solargraph/source/chain/call.rb', line 30

def initialize word, location = nil, arguments = [], block = nil
  super(word)

  @location = location
  @arguments = arguments
  @block = block
  fix_block_pass
end

Instance Attribute Details

#arguments::Array<Chain> (readonly)

Returns:



21
22
23
# File 'lib/solargraph/source/chain/call.rb', line 21

def arguments
  @arguments
end

#blockChain? (readonly)

Returns:



24
25
26
# File 'lib/solargraph/source/chain/call.rb', line 24

def block
  @block
end

#locationLocation (readonly)

Returns:



18
19
20
# File 'lib/solargraph/source/chain/call.rb', line 18

def location
  @location
end

#wordString (readonly)

Returns:

  • (String)


15
16
17
# File 'lib/solargraph/source/chain/call.rb', line 15

def word
  @word
end

Instance Method Details

#resolve(api_map, name_pin, locals) ⇒ Object

Parameters:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/solargraph/source/chain/call.rb', line 46

def resolve api_map, name_pin, locals
  return super_pins(api_map, name_pin) if word == 'super'
  return yield_pins(api_map, name_pin) if word == 'yield'
  found = api_map.var_at_location(locals, word, name_pin, location) if head?

  return inferred_pins([found], api_map, name_pin, locals) unless found.nil?
  binder = name_pin.binder
  # this is a q_call - i.e., foo&.bar - assume result of call
  # will be nil or result as if binder were not nil -
  # chain.rb#maybe_nil will add the nil type later, we just
  # need to worry about the not-nil case

  # @sg-ignore Need to handle duck-typed method calls on union types
  binder = binder.without_nil if nullable?
  # @sg-ignore Need to handle duck-typed method calls on union types
  pin_groups = binder.each_unique_type.map do |context|
    ns_tag = context.namespace == '' ? '' : context.namespace_type.tag
    stack = api_map.get_method_stack(ns_tag, word, scope: context.scope)
    [stack.first].compact
  end
  pin_groups = [] if !api_map.loose_unions && pin_groups.any?(&:empty?)
  pins = pin_groups.flatten.uniq(&:path)
  return [] if pins.empty?
  inferred_pins(pins, api_map, name_pin, locals)
end

#with_block?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/solargraph/source/chain/call.rb', line 39

def with_block?
  !!@block
end