Class: Solargraph::Pin::Base
Overview
The base class for map pins.
Instance Attribute Summary collapse
Attributes included from Common
#closure
Instance Method Summary
collapse
#documentation
#completion_item, #detail, #link_documentation, #reset_conversions, #resolve_completion_item, #signature_help, #text_documentation
Methods included from Common
#binder, #context, #namespace
Constructor Details
#initialize(location: nil, closure: nil, name: '', comments: '') ⇒ Base
Returns a new instance of Base.
32
33
34
35
36
37
|
# File 'lib/solargraph/pin/base.rb', line 32
def initialize location: nil, closure: nil, name: '', comments: ''
@location = location
@closure = closure
@name = name
@comments =
end
|
Instance Attribute Details
#code_object ⇒ YARD::CodeObjects::Base
13
14
15
|
# File 'lib/solargraph/pin/base.rb', line 13
def code_object
@code_object
end
|
16
17
18
|
# File 'lib/solargraph/pin/base.rb', line 16
def location
@location
end
|
#name ⇒ String
19
20
21
|
# File 'lib/solargraph/pin/base.rb', line 19
def name
@name
end
|
#path ⇒ String
22
23
24
|
# File 'lib/solargraph/pin/base.rb', line 22
def path
@path
end
|
96
97
98
|
# File 'lib/solargraph/pin/base.rb', line 96
def return_type
@return_type ||= ComplexType::UNDEFINED
end
|
#source ⇒ ::Symbol
25
26
27
|
# File 'lib/solargraph/pin/base.rb', line 25
def source
@source
end
|
Instance Method Details
#==(other) ⇒ Object
Pin equality is determined using the #nearly? method and also requiring both pins to have the same location.
72
73
74
75
|
# File 'lib/solargraph/pin/base.rb', line 72
def == other
return false unless nearly? other
== other. and location == other.location
end
|
40
41
42
|
# File 'lib/solargraph/pin/base.rb', line 40
def
@comments ||= ''
end
|
#completion_item_kind ⇒ Integer
#deprecated? ⇒ Boolean
131
132
133
|
# File 'lib/solargraph/pin/base.rb', line 131
def deprecated?
@deprecated ||= docstring.has_tag?('deprecated')
end
|
#directives ⇒ Array<YARD::Tags::Directive>
107
108
109
110
|
# File 'lib/solargraph/pin/base.rb', line 107
def directives
unless defined?(@directives)
@directives
end
|
#docstring ⇒ YARD::Docstring
101
102
103
104
|
# File 'lib/solargraph/pin/base.rb', line 101
def docstring
unless defined?(@docstring)
@docstring ||= Solargraph::Source.parse_docstring('').to_docstring
end
|
#filename ⇒ String?
45
46
47
48
|
# File 'lib/solargraph/pin/base.rb', line 45
def filename
return nil if location.nil?
location.filename
end
|
#identity ⇒ Object
219
220
221
|
# File 'lib/solargraph/pin/base.rb', line 219
def identity
@identity ||= "#{closure.context.namespace}|#{name}"
end
|
Deprecated.
Use #typify and/or #probe instead
158
159
160
161
162
163
|
# File 'lib/solargraph/pin/base.rb', line 158
def infer api_map
Solargraph::Logging.logger.warn "WARNING: Pin #infer methods are deprecated. Use #typify or #probe instead."
type = typify(api_map)
return type unless type.undefined?
probe api_map
end
|
#inspect ⇒ Object
223
224
225
|
# File 'lib/solargraph/pin/base.rb', line 223
def inspect
"#<#{self.class} `#{self.path}` at #{self.location.inspect}>"
end
|
#macros ⇒ Array<YARD::Tags::MacroDirective>
113
114
115
|
# File 'lib/solargraph/pin/base.rb', line 113
def macros
@macros ||= collect_macros
end
|
#maybe_directives? ⇒ Boolean
Perform a quick check to see if this pin possibly includes YARD directives. This method does not require parsing the comments.
After the comments have been parsed, this method will return false if no directives were found, regardless of whether it previously appeared possible.
125
126
127
128
|
# File 'lib/solargraph/pin/base.rb', line 125
def maybe_directives?
return !@directives.empty? if defined?(@directives)
@maybe_directives ||= .include?('@!')
end
|
#nearly?(other) ⇒ Boolean
True if the specified pin is a near match to this one. A near match indicates that the pins contain mostly the same data. Any differences between them should not have an impact on the API surface.
83
84
85
86
87
88
89
90
91
|
# File 'lib/solargraph/pin/base.rb', line 83
def nearly? other
self.class == other.class &&
name == other.name &&
(closure == other.closure || (closure && closure.nearly?(other.closure))) &&
( == other. ||
(((maybe_directives? == false && other.maybe_directives? == false) || compare_directives(directives, other.directives)) &&
compare_docstring_tags(docstring, other.docstring))
)
end
|
Infer the pin’s return type via static code analysis.
151
152
153
|
# File 'lib/solargraph/pin/base.rb', line 151
def probe api_map
typify api_map
end
|
#probed? ⇒ Boolean
189
190
191
|
# File 'lib/solargraph/pin/base.rb', line 189
def probed?
@probed ||= false
end
|
#proxied? ⇒ Boolean
185
186
187
|
# File 'lib/solargraph/pin/base.rb', line 185
def proxied?
@proxied ||= false
end
|
#proxy(return_type) ⇒ self
Return a proxy for this pin with the specified return type. Other than the return type and the #proxied? setting, the proxy should be a clone of the original.
212
213
214
215
216
217
|
# File 'lib/solargraph/pin/base.rb', line 212
def proxy return_type
result = dup
result.return_type = return_type
result.proxied = true
result
end
|
#realize(api_map) ⇒ self
195
196
197
198
199
200
201
202
203
204
|
# File 'lib/solargraph/pin/base.rb', line 195
def realize api_map
return self if return_type.defined?
type = typify(api_map)
return proxy(type) if type.defined?
type = probe(api_map)
return self if type.undefined?
result = proxy(type)
result.probed = true
result
end
|
#symbol_kind ⇒ Integer?
56
57
58
|
# File 'lib/solargraph/pin/base.rb', line 56
def symbol_kind
nil
end
|
#to_s ⇒ Object
60
61
62
|
# File 'lib/solargraph/pin/base.rb', line 60
def to_s
name.to_s
end
|
#try_merge!(pin) ⇒ Boolean
Try to merge data from another pin. Merges are only possible if the pins are near matches (see the #nearly? method). The changes should not have any side effects on the API surface.
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/solargraph/pin/base.rb', line 171
def try_merge! pin
return false unless nearly?(pin)
@location = pin.location
@closure = pin.closure
return true if == pin.
@comments = pin.
@docstring = pin.docstring
@return_type = pin.return_type
@documentation = nil
@deprecated = nil
reset_conversions
true
end
|
Get a fully qualified type from the pin’s return type.
The relative type is determined from YARD documentation (@return, @param, @type, etc.) and its namespaces are fully qualified using the provided ApiMap.
143
144
145
|
# File 'lib/solargraph/pin/base.rb', line 143
def typify api_map
return_type.qualify(api_map, namespace)
end
|
#variable? ⇒ Boolean
65
66
67
|
# File 'lib/solargraph/pin/base.rb', line 65
def variable?
false
end
|