Class: Solargraph::Pin::Parameter
- Inherits:
-
LocalVariable
- Object
- Base
- BaseVariable
- LocalVariable
- Solargraph::Pin::Parameter
- Defined in:
- lib/solargraph/pin/parameter.rb
Instance Attribute Summary collapse
-
#asgn_code ⇒ Object
readonly
Returns the value of attribute asgn_code.
-
#decl ⇒ Object
readonly
Returns the value of attribute decl.
Attributes included from Localized
Attributes inherited from BaseVariable
Attributes inherited from Base
#code_object, #location, #name, #path
Attributes included from Common
Instance Method Summary collapse
- #documentation ⇒ Object
- #full ⇒ Object
-
#index ⇒ Integer
The parameter’s zero-based location in the block’s signature.
-
#initialize(decl: :arg, asgn_code: nil, **splat) ⇒ Parameter
constructor
A new instance of Parameter.
- #keyword? ⇒ Boolean
- #kwrestarg? ⇒ Boolean
- #probe(api_map) ⇒ Object
- #rest? ⇒ Boolean
- #restarg? ⇒ Boolean
- #return_type ⇒ Object
- #try_merge!(pin) ⇒ Object
- #typify(api_map) ⇒ Object
Methods included from Localized
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_code ⇒ Object (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 |
#decl ⇒ Object (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
#documentation ⇒ Object
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 |
#full ⇒ Object
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 |
#index ⇒ Integer
The parameter’s zero-based location in the block’s signature.
73 74 75 |
# File 'lib/solargraph/pin/parameter.rb', line 73 def index closure.parameter_names.index(name) end |
#keyword? ⇒ Boolean
16 17 18 |
# File 'lib/solargraph/pin/parameter.rb', line 16 def keyword? [:kwarg, :kwoptarg].include?(decl) end |
#kwrestarg? ⇒ 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
28 29 30 |
# File 'lib/solargraph/pin/parameter.rb', line 28 def rest? decl == :restarg || decl == :kwrestarg end |
#restarg? ⇒ Boolean
24 25 26 |
# File 'lib/solargraph/pin/parameter.rb', line 24 def restarg? decl == :restarg end |
#return_type ⇒ Object
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 |