Class: Solargraph::Pin::Parameter

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

Instance Attribute Summary collapse

Attributes inherited from LocalVariable

#presence

Attributes inherited from BaseVariable

#assignment

Attributes inherited from Base

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

Attributes included from Common

#closure, #location

Instance Method Summary collapse

Methods inherited from LocalVariable

#visible_at?

Methods inherited from BaseVariable

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

Methods inherited from Base

#==, #comments, #completion_item_kind, #deprecated?, #directives, #docstring, #filename, #identity, #infer, #inspect, #macros, #maybe_directives?, #nearly?, #probe, #probed?, #proxied?, #proxy, #realize, #symbol_kind, #to_s, #variable?

Methods included from Conversions

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

Methods included from Common

#binder, #comments, #context, #name, #namespace, #path

Constructor Details

#initialize(decl: :arg, asgn_code: nil, return_type: nil, **splat) ⇒ Parameter

Returns a new instance of Parameter.



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

def initialize decl: :arg, asgn_code: nil, return_type: nil, **splat
  super(**splat)
  @asgn_code = asgn_code
  @decl = decl
  @return_type = return_type
end

Instance Attribute Details

#asgn_codeString (readonly)

Returns:

  • (String)


10
11
12
# File 'lib/solargraph/pin/parameter.rb', line 10

def asgn_code
  @asgn_code
end

#declSymbol (readonly)

Returns:



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

def decl
  @decl
end

Instance Method Details

#block?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/solargraph/pin/parameter.rb', line 35

def block?
  [:block, :blockarg].include?(decl)
end

#documentationObject



90
91
92
93
94
# File 'lib/solargraph/pin/parameter.rb', line 90

def documentation
  tag = param_tag
  return '' if tag.nil? || tag.text.nil?
  tag.text
end

#fullObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/solargraph/pin/parameter.rb', line 39

def full
  case decl
  when :optarg
    "#{name} = #{asgn_code || '?'}"
  when :kwarg
    "#{name}:"
  when :kwoptarg
    "#{name}: #{asgn_code || '?'}"
  when :restarg
    "*#{name}"
  when :kwrestarg
    "**#{name}"
  when :block, :blockarg
    "&#{name}"
  else
    name
  end
end

#indexInteger

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

Returns:

  • (Integer)


80
81
82
# File 'lib/solargraph/pin/parameter.rb', line 80

def index
  closure.parameter_names.index(name)
end

#keyword?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/solargraph/pin/parameter.rb', line 19

def keyword?
  [:kwarg, :kwoptarg].include?(decl)
end

#kwrestarg?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/solargraph/pin/parameter.rb', line 23

def kwrestarg?
  decl == :kwrestarg || (assignment && [:HASH, :hash].include?(assignment.type))
end

#rest?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/solargraph/pin/parameter.rb', line 31

def rest?
  decl == :restarg || decl == :kwrestarg
end

#restarg?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/solargraph/pin/parameter.rb', line 27

def restarg?
  decl == :restarg
end

#return_typeObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/solargraph/pin/parameter.rb', line 58

def return_type
  if @return_type.nil?
    @return_type = ComplexType::UNDEFINED
    found = param_tag
    @return_type = ComplexType.try_parse(*found.types) unless found.nil? or found.types.nil?
    if @return_type.undefined?
      if decl == :restarg
        @return_type = ComplexType.try_parse('Array')
      elsif decl == :kwrestarg
        @return_type = ComplexType.try_parse('Hash')
      elsif decl == :blockarg
        @return_type = ComplexType.try_parse('Proc')
      end
    end
  end
  super
  @return_type
end

#try_merge!(pin) ⇒ Object



96
97
98
99
# File 'lib/solargraph/pin/parameter.rb', line 96

def try_merge! pin
  return false unless super && closure == pin.closure
  true
end

#typify(api_map) ⇒ Object

Parameters:



85
86
87
88
# File 'lib/solargraph/pin/parameter.rb', line 85

def typify api_map
  return return_type.qualify(api_map, closure.context.namespace) unless return_type.undefined?
  closure.is_a?(Pin::Block) ? typify_block_param(api_map) : typify_method_param(api_map)
end