Class: Solargraph::Pin::Closure
- Inherits:
-
Base
- Object
- Base
- Solargraph::Pin::Closure
show all
- Defined in:
- lib/solargraph/pin/closure.rb
Constant Summary
Constants included
from Logging
Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS
Instance Attribute Summary collapse
Attributes inherited from Base
#code_object, #directives, #docstring, #location, #name, #path, #return_type, #source, #type_location
Attributes included from Common
#closure, #location
Instance Method Summary
collapse
Methods inherited from Base
#==, #all_location_text, #all_rooted?, #assert_same, #assert_same_array_content, #assert_same_count, #assert_same_macros, #assert_source_provided, #best_location, #choose, #choose_longer, #choose_node, #choose_pin_attr, #choose_pin_attr_with_same_name, #combine_directives, #combine_name, #combine_return_type, #comments, #completion_item_kind, #deprecated?, #desc, #dodgy_return_type_source?, #erase_generics, #filename, #identity, #infer, #inner_desc, #inspect, #macros, #maybe_directives?, #nearly?, #needs_consistent_name?, #prefer_rbs_location, #presence_certain?, #probe, #probed?, #proxied?, #proxy, #rbs_location?, #realize, #reset_generated!, #resolve_generics, #resolve_generics_from_context, #symbol_kind, #to_s, #transform_types, #type_desc, #typify, #variable?
Methods included from Logging
logger
#documentation, normalize_indentation, strip_html_comments
#completion_item, #completion_item_kind, #deprecated?, #detail, #link_documentation, #probed?, #proxied?, #reset_conversions, #resolve_completion_item, #signature_help, #text_documentation
Methods included from Common
#comments, #name, #namespace, #path, #return_type
Constructor Details
#initialize(scope: :class, generics: nil, generic_defaults: {}, **splat) ⇒ Closure
11
12
13
14
15
16
|
# File 'lib/solargraph/pin/closure.rb', line 11
def initialize scope: :class, generics: nil, generic_defaults: {}, **splat
super(**splat)
@scope = scope
@generics = generics
@generic_defaults = generic_defaults
end
|
Instance Attribute Details
#scope ⇒ ::Symbol
7
8
9
|
# File 'lib/solargraph/pin/closure.rb', line 7
def scope
@scope
end
|
Instance Method Details
#binder ⇒ Object
45
46
47
|
# File 'lib/solargraph/pin/closure.rb', line 45
def binder
@binder || context
end
|
#combine_with(other, attrs = {}) ⇒ self
26
27
28
29
30
31
32
|
# File 'lib/solargraph/pin/closure.rb', line 26
def combine_with(other, attrs={})
new_attrs = {
scope: assert_same(other, :scope),
generics: generics.empty? ? other.generics : generics,
}.merge(attrs)
super(other, new_attrs)
end
|
#context ⇒ Object
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/solargraph/pin/closure.rb', line 34
def context
@context ||= begin
result = super
if scope == :instance
result.reduce_class_type
else
result
end
end
end
|
#gates ⇒ ::Array<String>
50
51
52
53
54
|
# File 'lib/solargraph/pin/closure.rb', line 50
def gates
closure ? closure.gates : ['']
end
|
#generic_defaults ⇒ Object
18
19
20
|
# File 'lib/solargraph/pin/closure.rb', line 18
def generic_defaults
@generic_defaults ||= {}
end
|
#generics ⇒ ::Array<String>
57
58
59
|
# File 'lib/solargraph/pin/closure.rb', line 57
def generics
@generics ||= docstring.tags(:generic).map(&:name)
end
|
#rbs_generics ⇒ String
67
68
69
70
71
|
# File 'lib/solargraph/pin/closure.rb', line 67
def rbs_generics
return '' if generics.empty?
'[' + generics.map { |gen| gen.to_s }.join(', ') + '] '
end
|
#to_rbs ⇒ String
62
63
64
|
# File 'lib/solargraph/pin/closure.rb', line 62
def to_rbs
rbs_generics + return_type.to_rbs
end
|