Class: Solargraph::Pin::BlockParameter
- Inherits:
-
Base
- Object
- Base
- Solargraph::Pin::BlockParameter
show all
- Includes:
- Localized
- Defined in:
- lib/solargraph/pin/block_parameter.rb
Instance Attribute Summary collapse
Attributes included from Localized
#presence
Attributes inherited from Base
#location, #name, #namespace, #path
Instance Method Summary
collapse
Methods included from Localized
#visible_from?
Methods inherited from Base
#==, #comments, #deprecated?, #directives, #docstring, #filename, #macros, #maybe_directives?, #return_type, #to_s, #variable?
#documentation
#completion_item, #detail, #link_documentation, #reset_conversions, #resolve_completion_item, #signature_help
Constructor Details
#initialize(location, namespace, name, comments, block) ⇒ BlockParameter
Returns a new instance of BlockParameter.
9
10
11
12
13
|
# File 'lib/solargraph/pin/block_parameter.rb', line 9
def initialize location, namespace, name, , block
super(location, namespace, name, )
@block = block
@presence = block.location.range
end
|
Instance Attribute Details
7
8
9
|
# File 'lib/solargraph/pin/block_parameter.rb', line 7
def block
@block
end
|
Instance Method Details
#completion_item_kind ⇒ Integer
#context ⇒ Object
65
66
67
|
# File 'lib/solargraph/pin/block_parameter.rb', line 65
def context
block
end
|
#index ⇒ Integer
The parameter’s zero-based location in the block’s signature.
33
34
35
|
# File 'lib/solargraph/pin/block_parameter.rb', line 33
def index
block.parameters.index(self)
end
|
#infer(api_map) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/solargraph/pin/block_parameter.rb', line 70
def infer api_map
return return_complex_type unless return_complex_type.undefined?
chain = Source::NodeChainer.chain(block.receiver, filename)
clip = api_map.clip_at(location.filename, location.range.start)
locals = clip.locals - [self]
meths = chain.define(api_map, block, locals)
meths.each do |meth|
if (Solargraph::CoreFills::METHODS_WITH_YIELDPARAM_SUBTYPES.include?(meth.path))
bmeth = chain.base.define(api_map, context, locals).first
return ComplexType::UNDEFINED if bmeth.nil? or bmeth.return_complex_type.undefined? or bmeth.return_complex_type.subtypes.empty?
return bmeth.return_complex_type.subtypes.first.qualify(api_map, bmeth.context.namespace)
else
yps = meth.docstring.tags(:yieldparam)
unless yps[index].nil? or yps[index].types.nil? or yps[index].types.empty?
return ComplexType.parse(yps[index].types[0]).first
end
end
end
ComplexType::UNDEFINED
end
|
#kind ⇒ Integer
16
17
18
|
# File 'lib/solargraph/pin/block_parameter.rb', line 16
def kind
Pin::BLOCK_PARAMETER
end
|
#nearly?(other) ⇒ Boolean
37
38
39
40
|
# File 'lib/solargraph/pin/block_parameter.rb', line 37
def nearly? other
return false unless super
block.nearly?(other.block)
end
|
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/solargraph/pin/block_parameter.rb', line 51
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
end
@return_complex_type = ComplexType.parse(*found.types) unless found.nil? or found.types.nil?
end
@return_complex_type
end
|
#try_merge!(other) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/solargraph/pin/block_parameter.rb', line 42
def try_merge! other
return false unless super
@block = other.block
@presence = other.block.location.range
@return_complex_type = nil
true
end
|