Class: Solargraph::Source::Chain::Call
- Inherits:
-
Chain::Link
- Object
- Chain::Link
- Solargraph::Source::Chain::Call
- 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.
Instance Attribute Summary collapse
- #arguments ⇒ ::Array<Chain> readonly
- #block ⇒ Chain? readonly
- #location ⇒ Location? readonly
- #word ⇒ String readonly
Instance Method Summary collapse
-
#initialize(word, location = nil, arguments = [], block = nil) ⇒ Call
constructor
A new instance of Call.
- #resolve(api_map, name_pin, locals) ⇒ Object
- #with_block? ⇒ Boolean
Constructor Details
#initialize(word, location = nil, arguments = [], block = nil) ⇒ Call
Returns a new instance of Call.
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)
21 22 23 |
# File 'lib/solargraph/source/chain/call.rb', line 21 def arguments @arguments end |
#block ⇒ Chain? (readonly)
24 25 26 |
# File 'lib/solargraph/source/chain/call.rb', line 24 def block @block end |
#location ⇒ Location? (readonly)
18 19 20 |
# File 'lib/solargraph/source/chain/call.rb', line 18 def location @location end |
#word ⇒ String (readonly)
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
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
39 40 41 |
# File 'lib/solargraph/source/chain/call.rb', line 39 def with_block? !!@block end |