Class: Solargraph::Pin::Parameter

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

Instance Attribute Summary collapse

Attributes included from Localized

#presence

Attributes inherited from BaseVariable

#assignment

Attributes inherited from Base

#code_object, #location, #name, #path

Attributes included from Common

#closure, #location

Instance Method Summary collapse

Methods included from Localized

#visible_at?, #visible_from?

Methods inherited from BaseVariable

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

Methods inherited from Base

#==, #comments, #completion_item_kind, #deprecated?, #directives, #docstring, #filename, #identity, #infer, #inspect, #macros, #maybe_directives?, #nearly?, #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, **splat) ⇒ Parameter

Returns a new instance of Parameter.



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

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

Instance Attribute Details

#asgn_codeObject (readonly)

Returns the value of attribute asgn_code.



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

def asgn_code
  @asgn_code
end

#declObject (readonly)

Returns the value of attribute decl.



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

def decl
  @decl
end

Instance Method Details

#documentationObject



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

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

#fullObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/solargraph/pin/parameter.rb', line 32

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)


73
74
75
# File 'lib/solargraph/pin/parameter.rb', line 73

def index
  closure.parameter_names.index(name)
end

#keyword?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/solargraph/pin/parameter.rb', line 16

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

#kwrestarg?Boolean

Returns:

  • (Boolean)


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

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

#probe(api_map) ⇒ Object



94
95
96
# File 'lib/solargraph/pin/parameter.rb', line 94

def probe api_map
  typify api_map
end

#rest?Boolean

Returns:

  • (Boolean)


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

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

#restarg?Boolean

Returns:

  • (Boolean)


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

def restarg?
  decl == :restarg
end

#return_typeObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/solargraph/pin/parameter.rb', line 51

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



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

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

#typify(api_map) ⇒ Object

Parameters:



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

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