Class: Solargraph::Pin::Base
Overview
The base class for map pins.
Instance Attribute Summary collapse
Attributes included from Common
#closure, #context
Instance Method Summary
collapse
#documentation, normalize_indentation, strip_html_comments
#completion_item, #detail, #link_documentation, #reset_conversions, #resolve_completion_item, #signature_help, #text_documentation
Methods included from Common
#binder, #namespace
Constructor Details
#initialize(location: nil, type_location: nil, closure: nil, name: '', comments: '') ⇒ Base
Returns a new instance of Base.
35
36
37
38
39
40
41
|
# File 'lib/solargraph/pin/base.rb', line 35
def initialize location: nil, type_location: nil, closure: nil, name: '', comments: ''
@location = location
@type_location = type_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
22
23
24
|
# File 'lib/solargraph/pin/base.rb', line 22
def name
@name
end
|
#path ⇒ String
25
26
27
|
# File 'lib/solargraph/pin/base.rb', line 25
def path
@path
end
|
146
147
148
|
# File 'lib/solargraph/pin/base.rb', line 146
def return_type
@return_type ||= ComplexType::UNDEFINED
end
|
#source ⇒ ::Symbol
28
29
30
|
# File 'lib/solargraph/pin/base.rb', line 28
def source
@source
end
|
19
20
21
|
# File 'lib/solargraph/pin/base.rb', line 19
def type_location
@type_location
end
|
Instance Method Details
#==(other) ⇒ Object
Pin equality is determined using the #nearly? method and also requiring both pins to have the same location.
122
123
124
125
|
# File 'lib/solargraph/pin/base.rb', line 122
def == other
return false unless nearly? other
== other. and location == other.location
end
|
#all_rooted? ⇒ Boolean
78
79
80
|
# File 'lib/solargraph/pin/base.rb', line 78
def all_rooted?
!return_type || return_type.all_rooted?
end
|
#best_location ⇒ Location?
115
116
117
|
# File 'lib/solargraph/pin/base.rb', line 115
def best_location
location || type_location
end
|
44
45
46
|
# File 'lib/solargraph/pin/base.rb', line 44
def
@comments ||= ''
end
|
#completion_item_kind ⇒ Integer
#deprecated? ⇒ Boolean
181
182
183
|
# File 'lib/solargraph/pin/base.rb', line 181
def deprecated?
@deprecated ||= docstring.has_tag?('deprecated')
end
|
#desc ⇒ String?
280
281
282
283
284
285
286
287
288
289
290
|
# File 'lib/solargraph/pin/base.rb', line 280
def desc
if path
if to_rbs
path + ' ' + to_rbs
else
path
end
else
to_rbs
end
end
|
#directives ⇒ ::Array<YARD::Tags::Directive>
157
158
159
160
|
# File 'lib/solargraph/pin/base.rb', line 157
def directives
unless defined?(@directives)
@directives
end
|
#docstring ⇒ YARD::Docstring
151
152
153
154
|
# File 'lib/solargraph/pin/base.rb', line 151
def docstring
unless defined?(@docstring)
@docstring ||= Solargraph::Source.parse_docstring('').to_docstring
end
|
#erase_generics(generics_to_erase) ⇒ self
84
85
86
87
|
# File 'lib/solargraph/pin/base.rb', line 84
def erase_generics(generics_to_erase)
return self if generics_to_erase.empty?
transform_types { |t| t.erase_generics(generics_to_erase) }
end
|
#filename ⇒ String?
90
91
92
93
|
# File 'lib/solargraph/pin/base.rb', line 90
def filename
return nil if location.nil?
location.filename
end
|
#identity ⇒ String
270
271
272
|
# File 'lib/solargraph/pin/base.rb', line 270
def identity
@identity ||= "#{closure.path}|#{name}"
end
|
Deprecated.
Use #typify and/or #probe instead
208
209
210
211
212
213
|
# File 'lib/solargraph/pin/base.rb', line 208
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
292
293
294
|
# File 'lib/solargraph/pin/base.rb', line 292
def inspect
"#<#{self.class} `#{self.desc}` at #{self.location.inspect}>"
end
|
#macros ⇒ ::Array<YARD::Tags::MacroDirective>
163
164
165
|
# File 'lib/solargraph/pin/base.rb', line 163
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.
175
176
177
178
|
# File 'lib/solargraph/pin/base.rb', line 175
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.
133
134
135
136
137
138
139
140
141
|
# File 'lib/solargraph/pin/base.rb', line 133
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.
201
202
203
|
# File 'lib/solargraph/pin/base.rb', line 201
def probe api_map
typify api_map
end
|
#probed? ⇒ Boolean
239
240
241
|
# File 'lib/solargraph/pin/base.rb', line 239
def probed?
@probed ||= false
end
|
#proxied? ⇒ Boolean
235
236
237
|
# File 'lib/solargraph/pin/base.rb', line 235
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.
262
263
264
265
266
267
|
# File 'lib/solargraph/pin/base.rb', line 262
def proxy return_type
result = dup
result.return_type = return_type
result.proxied = true
result
end
|
#realize(api_map) ⇒ self
245
246
247
248
249
250
251
252
253
254
|
# File 'lib/solargraph/pin/base.rb', line 245
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
|
#resolve_generics(definitions, context_type) ⇒ self
Determine the concrete type for each of the generic type parameters used in this method based on the parameters passed into the its class and return a new method pin.
73
74
75
76
|
# File 'lib/solargraph/pin/base.rb', line 73
def resolve_generics definitions, context_type
transformed = transform_types { |t| t.resolve_generics(definitions, context_type) if t }
transformed.erase_generics(definitions.generics)
end
|
#resolve_generics_from_context(generics_to_resolve, return_type_context = nil, resolved_generic_values: {}) ⇒ self
53
54
55
56
57
|
# File 'lib/solargraph/pin/base.rb', line 53
def resolve_generics_from_context(generics_to_resolve, return_type_context = nil, resolved_generic_values: {})
proxy return_type.resolve_generics_from_context(generics_to_resolve,
return_type_context,
resolved_generic_values: resolved_generic_values)
end
|
#symbol_kind ⇒ Integer?
101
102
103
|
# File 'lib/solargraph/pin/base.rb', line 101
def symbol_kind
nil
end
|
#to_rbs ⇒ String?
275
276
277
|
# File 'lib/solargraph/pin/base.rb', line 275
def to_rbs
return_type.to_rbs
end
|
#to_s ⇒ Object
105
106
107
|
# File 'lib/solargraph/pin/base.rb', line 105
def to_s
to_rbs
end
|
62
63
64
|
# File 'lib/solargraph/pin/base.rb', line 62
def transform_types(&transform)
proxy return_type.transform(&transform)
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.
221
222
223
224
225
226
227
228
229
230
231
232
233
|
# File 'lib/solargraph/pin/base.rb', line 221
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.
193
194
195
|
# File 'lib/solargraph/pin/base.rb', line 193
def typify api_map
return_type.qualify(api_map, namespace)
end
|
#variable? ⇒ Boolean
110
111
112
|
# File 'lib/solargraph/pin/base.rb', line 110
def variable?
false
end
|