Class: Solargraph::Pin::MethodParameter

Inherits:
LocalVariable show all
Defined in:
lib/solargraph/pin/method_parameter.rb

Instance Attribute Summary

Attributes included from Localized

#block, #presence

Attributes inherited from BaseVariable

#assignment, #context

Attributes inherited from Base

#kind, #location, #name, #namespace, #path

Instance Method Summary collapse

Methods inherited from LocalVariable

#initialize, #kind

Methods included from Localized

#visible_from?

Methods inherited from BaseVariable

#==, #completion_item_kind, #infer, #initialize, #nil_assignment?, #signature, #symbol_kind, #variable?

Methods included from Source::NodeMethods

const_from, drill_signature, get_node_end_position, get_node_start_position, infer_literal_node_type, pack_name, resolve_node_signature, unpack_name

Methods inherited from Base

#==, #comments, #completion_item_kind, #context, #deprecated?, #directives, #docstring, #filename, #infer, #initialize, #macros, #maybe_directives?, #nearly?, #return_type, #symbol_kind, #to_s, #variable?

Methods included from Documenting

#documentation

Methods included from Conversions

#completion_item, #detail, #link_documentation, #reset_conversions, #resolve_completion_item, #signature_help

Constructor Details

This class inherits a constructor from Solargraph::Pin::LocalVariable

Instance Method Details

#indexInteger

The parameter’s zero-based location in the block’s signature.

Returns:

  • (Integer)


26
27
28
# File 'lib/solargraph/pin/method_parameter.rb', line 26

def index
  block.parameter_names.index(name)
end

#return_complex_typeObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/solargraph/pin/method_parameter.rb', line 4

def return_complex_type
  if @return_complex_type.nil?
    @return_complex_type = ComplexType.new
    found = nil
    params = block.docstring.tags(:param)
    params.each do |p|
      next unless p.name == name
      found = p
      break
    end
    if found.nil? and !index.nil?
      found = params[index] if params[index] && (params[index].name.nil? || params[index].name.empty?)
    end
    @return_complex_type = ComplexType.parse(*found.types) unless found.nil? or found.types.nil?
  end
  super
  @return_complex_type
end

#try_merge!(pin) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/solargraph/pin/method_parameter.rb', line 30

def try_merge! pin
  return false unless super
  # @todo This is a little expensive, but it's necessary because
  #   parameter data depends on the method's docstring.
  @return_complex_type = pin.return_complex_type
  reset_conversions
  true
end