solargraph 0.58.1 → 0.59.0.dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.envrc +3 -0
- data/.github/workflows/linting.yml +4 -5
- data/.github/workflows/plugins.yml +40 -36
- data/.github/workflows/rspec.yml +45 -13
- data/.github/workflows/typecheck.yml +2 -2
- data/.rubocop_todo.yml +27 -49
- data/README.md +3 -3
- data/Rakefile +1 -0
- data/lib/solargraph/api_map/cache.rb +110 -110
- data/lib/solargraph/api_map/constants.rb +289 -279
- data/lib/solargraph/api_map/index.rb +204 -193
- data/lib/solargraph/api_map/source_to_yard.rb +109 -97
- data/lib/solargraph/api_map/store.rb +387 -384
- data/lib/solargraph/api_map.rb +1000 -945
- data/lib/solargraph/complex_type/conformance.rb +176 -0
- data/lib/solargraph/complex_type/type_methods.rb +242 -228
- data/lib/solargraph/complex_type/unique_type.rb +632 -482
- data/lib/solargraph/complex_type.rb +549 -444
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +93 -91
- data/lib/solargraph/convention/data_definition.rb +108 -105
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +62 -61
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +103 -102
- data/lib/solargraph/convention/struct_definition.rb +168 -164
- data/lib/solargraph/diagnostics/require_not_found.rb +54 -53
- data/lib/solargraph/diagnostics/rubocop.rb +119 -118
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +70 -68
- data/lib/solargraph/diagnostics/type_check.rb +56 -55
- data/lib/solargraph/doc_map.rb +200 -439
- data/lib/solargraph/equality.rb +34 -34
- data/lib/solargraph/gem_pins.rb +97 -98
- data/lib/solargraph/language_server/host/dispatch.rb +131 -130
- data/lib/solargraph/language_server/host/message_worker.rb +113 -112
- data/lib/solargraph/language_server/host/sources.rb +100 -99
- data/lib/solargraph/language_server/host.rb +883 -878
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +109 -114
- data/lib/solargraph/language_server/message/extended/document.rb +24 -23
- data/lib/solargraph/language_server/message/text_document/completion.rb +58 -56
- data/lib/solargraph/language_server/message/text_document/definition.rb +42 -40
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +28 -26
- data/lib/solargraph/language_server/message/text_document/formatting.rb +150 -148
- data/lib/solargraph/language_server/message/text_document/hover.rb +60 -58
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +25 -24
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +27 -25
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +25 -23
- data/lib/solargraph/library.rb +729 -683
- data/lib/solargraph/location.rb +87 -82
- data/lib/solargraph/logging.rb +57 -37
- data/lib/solargraph/parser/comment_ripper.rb +76 -69
- data/lib/solargraph/parser/flow_sensitive_typing.rb +483 -255
- data/lib/solargraph/parser/node_processor/base.rb +122 -92
- data/lib/solargraph/parser/node_processor.rb +63 -62
- data/lib/solargraph/parser/parser_gem/class_methods.rb +167 -149
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +191 -166
- data/lib/solargraph/parser/parser_gem/node_methods.rb +506 -486
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +22 -22
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +61 -59
- data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +24 -15
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +46 -46
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +60 -53
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +53 -23
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +41 -40
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +30 -29
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +61 -59
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +98 -98
- data/lib/solargraph/parser/parser_gem/node_processors/or_node.rb +22 -0
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +17 -17
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +39 -38
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +53 -52
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +296 -291
- data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +23 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +33 -29
- data/lib/solargraph/parser/parser_gem/node_processors.rb +74 -70
- data/lib/solargraph/parser/region.rb +75 -69
- data/lib/solargraph/parser/snippet.rb +17 -17
- data/lib/solargraph/pin/base.rb +761 -729
- data/lib/solargraph/pin/base_variable.rb +418 -126
- data/lib/solargraph/pin/block.rb +126 -104
- data/lib/solargraph/pin/breakable.rb +13 -9
- data/lib/solargraph/pin/callable.rb +278 -231
- data/lib/solargraph/pin/closure.rb +68 -72
- data/lib/solargraph/pin/common.rb +94 -79
- data/lib/solargraph/pin/compound_statement.rb +55 -0
- data/lib/solargraph/pin/conversions.rb +124 -123
- data/lib/solargraph/pin/delegated_method.rb +131 -120
- data/lib/solargraph/pin/documenting.rb +115 -114
- data/lib/solargraph/pin/instance_variable.rb +38 -34
- data/lib/solargraph/pin/keyword.rb +16 -20
- data/lib/solargraph/pin/local_variable.rb +31 -75
- data/lib/solargraph/pin/method.rb +720 -672
- data/lib/solargraph/pin/method_alias.rb +42 -34
- data/lib/solargraph/pin/namespace.rb +121 -115
- data/lib/solargraph/pin/parameter.rb +338 -275
- data/lib/solargraph/pin/proxy_type.rb +40 -39
- data/lib/solargraph/pin/reference/override.rb +47 -47
- data/lib/solargraph/pin/reference/superclass.rb +17 -15
- data/lib/solargraph/pin/reference.rb +41 -39
- data/lib/solargraph/pin/search.rb +62 -61
- data/lib/solargraph/pin/signature.rb +69 -61
- data/lib/solargraph/pin/symbol.rb +53 -53
- data/lib/solargraph/pin/until.rb +18 -18
- data/lib/solargraph/pin/while.rb +18 -18
- data/lib/solargraph/pin.rb +46 -44
- data/lib/solargraph/pin_cache.rb +665 -245
- data/lib/solargraph/position.rb +118 -119
- data/lib/solargraph/range.rb +112 -112
- data/lib/solargraph/rbs_map/conversions.rb +846 -823
- data/lib/solargraph/rbs_map/core_map.rb +65 -58
- data/lib/solargraph/rbs_map/stdlib_map.rb +72 -43
- data/lib/solargraph/rbs_map.rb +217 -163
- data/lib/solargraph/shell.rb +397 -352
- data/lib/solargraph/source/chain/call.rb +372 -337
- data/lib/solargraph/source/chain/constant.rb +28 -26
- data/lib/solargraph/source/chain/hash.rb +35 -34
- data/lib/solargraph/source/chain/if.rb +29 -28
- data/lib/solargraph/source/chain/instance_variable.rb +34 -13
- data/lib/solargraph/source/chain/literal.rb +53 -48
- data/lib/solargraph/source/chain/or.rb +31 -23
- data/lib/solargraph/source/chain.rb +294 -291
- data/lib/solargraph/source/change.rb +89 -82
- data/lib/solargraph/source/cursor.rb +172 -166
- data/lib/solargraph/source/source_chainer.rb +204 -194
- data/lib/solargraph/source/updater.rb +59 -55
- data/lib/solargraph/source.rb +524 -498
- data/lib/solargraph/source_map/clip.rb +237 -226
- data/lib/solargraph/source_map/data.rb +37 -34
- data/lib/solargraph/source_map/mapper.rb +282 -259
- data/lib/solargraph/source_map.rb +220 -212
- data/lib/solargraph/type_checker/problem.rb +34 -32
- data/lib/solargraph/type_checker/rules.rb +157 -84
- data/lib/solargraph/type_checker.rb +895 -814
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +257 -255
- data/lib/solargraph/workspace/gemspecs.rb +367 -0
- data/lib/solargraph/workspace/require_paths.rb +98 -97
- data/lib/solargraph/workspace.rb +362 -220
- data/lib/solargraph/yard_map/helpers.rb +45 -44
- data/lib/solargraph/yard_map/mapper/to_method.rb +134 -130
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +32 -31
- data/lib/solargraph/yard_map/mapper.rb +84 -79
- data/lib/solargraph/yardoc.rb +97 -87
- data/lib/solargraph.rb +126 -105
- data/rbs/fills/rubygems/0/dependency.rbs +193 -0
- data/rbs/fills/tuple/tuple.rbs +28 -0
- data/rbs/shims/ast/0/node.rbs +5 -0
- data/rbs/shims/diff-lcs/1.5/diff-lcs.rbs +11 -0
- data/rbs_collection.yaml +1 -1
- data/solargraph.gemspec +2 -1
- metadata +22 -17
- data/lib/solargraph/type_checker/checks.rb +0 -124
- data/lib/solargraph/type_checker/param_def.rb +0 -37
- data/lib/solargraph/yard_map/to_method.rb +0 -89
- data/sig/shims/ast/0/node.rbs +0 -5
- /data/{sig → rbs}/shims/ast/2.4/.rbs_meta.yaml +0 -0
- /data/{sig → rbs}/shims/ast/2.4/ast.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/builders/default.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/manifest.yaml +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/parser.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/polyfill.rbs +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/.rbs_meta.yaml +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/manifest.yaml +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/thor.rbs +0 -0
data/lib/solargraph/pin/base.rb
CHANGED
|
@@ -1,729 +1,761 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module Pin
|
|
5
|
-
# The base class for map pins.
|
|
6
|
-
#
|
|
7
|
-
class Base
|
|
8
|
-
include Common
|
|
9
|
-
include Conversions
|
|
10
|
-
include Documenting
|
|
11
|
-
include Logging
|
|
12
|
-
|
|
13
|
-
# @return [YARD::CodeObjects::Base]
|
|
14
|
-
attr_reader :code_object
|
|
15
|
-
|
|
16
|
-
# @return [Solargraph::Location, nil]
|
|
17
|
-
attr_reader :location
|
|
18
|
-
|
|
19
|
-
# @return [Solargraph::Location, nil]
|
|
20
|
-
attr_reader :type_location
|
|
21
|
-
|
|
22
|
-
# @return [String]
|
|
23
|
-
attr_reader :name
|
|
24
|
-
|
|
25
|
-
# @return [String]
|
|
26
|
-
attr_reader :path
|
|
27
|
-
|
|
28
|
-
# @return [::Symbol]
|
|
29
|
-
attr_accessor :source
|
|
30
|
-
|
|
31
|
-
# @type [::Numeric, nil] A priority for determining if pins should be combined or not
|
|
32
|
-
# A nil priority is considered the be the lowest. All code, yard & rbs pins have nil priority
|
|
33
|
-
# Between 2 pins, the one with the higher priority gets chosen. If the priorities are equal, they are combined.
|
|
34
|
-
attr_reader :combine_priority
|
|
35
|
-
|
|
36
|
-
def presence_certain?
|
|
37
|
-
true
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# @param location [Solargraph::Location, nil]
|
|
41
|
-
# @param type_location [Solargraph::Location, nil]
|
|
42
|
-
# @param closure [Solargraph::Pin::Closure, nil]
|
|
43
|
-
# @param name [String]
|
|
44
|
-
# @param comments [String]
|
|
45
|
-
# @param source [Symbol, nil]
|
|
46
|
-
# @param docstring [YARD::Docstring, nil]
|
|
47
|
-
# @param directives [::Array<YARD::Tags::Directive>, nil]
|
|
48
|
-
# @param combine_priority [::Numeric, nil] See attr_reader for combine_priority
|
|
49
|
-
def initialize location: nil, type_location: nil, closure: nil, source: nil, name: '', comments: '', docstring: nil, directives: nil, combine_priority: nil
|
|
50
|
-
@location = location
|
|
51
|
-
@type_location = type_location
|
|
52
|
-
@closure = closure
|
|
53
|
-
@name = name
|
|
54
|
-
@comments = comments
|
|
55
|
-
@source = source
|
|
56
|
-
@identity = nil
|
|
57
|
-
@docstring = docstring
|
|
58
|
-
@directives = directives
|
|
59
|
-
@combine_priority = combine_priority
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
#
|
|
82
|
-
# @
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
out.
|
|
106
|
-
out
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
# @
|
|
111
|
-
#
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
# @param
|
|
130
|
-
# @
|
|
131
|
-
# @
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
# @
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
# @return [
|
|
161
|
-
def
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
#
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
#
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
# @param
|
|
290
|
-
# @
|
|
291
|
-
#
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
#
|
|
295
|
-
arr1
|
|
296
|
-
|
|
297
|
-
#
|
|
298
|
-
arr2
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
#
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
# @return
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
#
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
# @return [
|
|
403
|
-
def
|
|
404
|
-
|
|
405
|
-
end
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
# @
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
end
|
|
417
|
-
|
|
418
|
-
# @
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
# @
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
end
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
#
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
#
|
|
500
|
-
#
|
|
501
|
-
#
|
|
502
|
-
#
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
# @return [
|
|
512
|
-
def
|
|
513
|
-
@
|
|
514
|
-
end
|
|
515
|
-
|
|
516
|
-
#
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
# @
|
|
523
|
-
# @return [
|
|
524
|
-
def
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
#
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
#
|
|
537
|
-
#
|
|
538
|
-
#
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
#
|
|
555
|
-
# @
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
#
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
# @
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
def
|
|
583
|
-
@
|
|
584
|
-
end
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
#
|
|
591
|
-
#
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
end
|
|
602
|
-
|
|
603
|
-
#
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
#
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
# @return [
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
end
|
|
683
|
-
end
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
#
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
# @return [Boolean]
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
# @
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module Pin
|
|
5
|
+
# The base class for map pins.
|
|
6
|
+
#
|
|
7
|
+
class Base
|
|
8
|
+
include Common
|
|
9
|
+
include Conversions
|
|
10
|
+
include Documenting
|
|
11
|
+
include Logging
|
|
12
|
+
|
|
13
|
+
# @return [YARD::CodeObjects::Base]
|
|
14
|
+
attr_reader :code_object
|
|
15
|
+
|
|
16
|
+
# @return [Solargraph::Location, nil]
|
|
17
|
+
attr_reader :location
|
|
18
|
+
|
|
19
|
+
# @return [Solargraph::Location, nil]
|
|
20
|
+
attr_reader :type_location
|
|
21
|
+
|
|
22
|
+
# @return [String]
|
|
23
|
+
attr_reader :name
|
|
24
|
+
|
|
25
|
+
# @return [String]
|
|
26
|
+
attr_reader :path
|
|
27
|
+
|
|
28
|
+
# @return [::Symbol]
|
|
29
|
+
attr_accessor :source
|
|
30
|
+
|
|
31
|
+
# @type [::Numeric, nil] A priority for determining if pins should be combined or not
|
|
32
|
+
# A nil priority is considered the be the lowest. All code, yard & rbs pins have nil priority
|
|
33
|
+
# Between 2 pins, the one with the higher priority gets chosen. If the priorities are equal, they are combined.
|
|
34
|
+
attr_reader :combine_priority
|
|
35
|
+
|
|
36
|
+
def presence_certain?
|
|
37
|
+
true
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @param location [Solargraph::Location, nil]
|
|
41
|
+
# @param type_location [Solargraph::Location, nil]
|
|
42
|
+
# @param closure [Solargraph::Pin::Closure, nil]
|
|
43
|
+
# @param name [String]
|
|
44
|
+
# @param comments [String, nil]
|
|
45
|
+
# @param source [Symbol, nil]
|
|
46
|
+
# @param docstring [YARD::Docstring, nil]
|
|
47
|
+
# @param directives [::Array<YARD::Tags::Directive>, nil]
|
|
48
|
+
# @param combine_priority [::Numeric, nil] See attr_reader for combine_priority
|
|
49
|
+
def initialize location: nil, type_location: nil, closure: nil, source: nil, name: '', comments: '', docstring: nil, directives: nil, combine_priority: nil
|
|
50
|
+
@location = location
|
|
51
|
+
@type_location = type_location
|
|
52
|
+
@closure = closure
|
|
53
|
+
@name = name
|
|
54
|
+
@comments = comments
|
|
55
|
+
@source = source
|
|
56
|
+
@identity = nil
|
|
57
|
+
@docstring = docstring
|
|
58
|
+
@directives = directives
|
|
59
|
+
@combine_priority = combine_priority
|
|
60
|
+
# @type [ComplexType, ComplexType::UniqueType, nil]
|
|
61
|
+
@binder = nil
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
assert_source_provided
|
|
65
|
+
assert_location_provided
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# @return [void]
|
|
69
|
+
def assert_location_provided
|
|
70
|
+
return unless best_location.nil? && %i[yardoc source rbs].include?(source)
|
|
71
|
+
|
|
72
|
+
Solargraph.assert_or_log(:best_location, "Neither location nor type_location provided - #{path} #{source} #{self.class}")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# @return [Pin::Closure, nil]
|
|
76
|
+
def closure
|
|
77
|
+
Solargraph.assert_or_log(:closure, "Closure not set on #{self.class} #{name.inspect} from #{source.inspect}") unless @closure
|
|
78
|
+
@closure
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# @param other [self]
|
|
82
|
+
# @param attrs [Hash{::Symbol => Object}]
|
|
83
|
+
#
|
|
84
|
+
# @return [self]
|
|
85
|
+
def combine_with(other, attrs={})
|
|
86
|
+
priority_choice = choose_priority(other)
|
|
87
|
+
return priority_choice unless priority_choice.nil?
|
|
88
|
+
|
|
89
|
+
type_location = choose(other, :type_location)
|
|
90
|
+
location = choose(other, :location)
|
|
91
|
+
combined_name = combine_name(other)
|
|
92
|
+
new_attrs = {
|
|
93
|
+
location: location,
|
|
94
|
+
type_location: type_location,
|
|
95
|
+
name: combined_name,
|
|
96
|
+
closure: combine_closure(other),
|
|
97
|
+
comments: choose_longer(other, :comments),
|
|
98
|
+
source: :combined,
|
|
99
|
+
docstring: choose(other, :docstring),
|
|
100
|
+
directives: combine_directives(other),
|
|
101
|
+
combine_priority: combine_priority
|
|
102
|
+
}.merge(attrs)
|
|
103
|
+
assert_same_macros(other)
|
|
104
|
+
logger.debug { "Base#combine_with(path=#{path}) - other.comments=#{other.comments.inspect}, self.comments = #{self.comments}" }
|
|
105
|
+
out = self.class.new(**new_attrs)
|
|
106
|
+
out.reset_generated!
|
|
107
|
+
out
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# @param other [self]
|
|
111
|
+
# @return [self, nil] Returns either the pin chosen based on priority or nil
|
|
112
|
+
# A nil return means that the combination process must proceed
|
|
113
|
+
def choose_priority(other)
|
|
114
|
+
if combine_priority.nil? && !other.combine_priority.nil?
|
|
115
|
+
return other
|
|
116
|
+
elsif other.combine_priority.nil? && !combine_priority.nil?
|
|
117
|
+
return self
|
|
118
|
+
elsif !combine_priority.nil? && !other.combine_priority.nil?
|
|
119
|
+
if combine_priority > other.combine_priority
|
|
120
|
+
return self
|
|
121
|
+
elsif combine_priority < other.combine_priority
|
|
122
|
+
return other
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
nil
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# @param other [self]
|
|
130
|
+
# @param attr [::Symbol]
|
|
131
|
+
# @sg-ignore
|
|
132
|
+
# @return [undefined]
|
|
133
|
+
def choose_longer(other, attr)
|
|
134
|
+
# @type [undefined]
|
|
135
|
+
val1 = send(attr)
|
|
136
|
+
# @type [undefined]
|
|
137
|
+
val2 = other.send(attr)
|
|
138
|
+
return val1 if val1 == val2
|
|
139
|
+
return val2 if val1.nil?
|
|
140
|
+
val1.length > val2.length ? val1 : val2
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# @param other [self]
|
|
144
|
+
#
|
|
145
|
+
# @return [::Array<YARD::Tags::Directive>, nil]
|
|
146
|
+
def combine_directives(other)
|
|
147
|
+
return self.directives if other.directives.empty?
|
|
148
|
+
return other.directives if directives.empty?
|
|
149
|
+
(directives + other.directives).uniq
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# @param other [self]
|
|
153
|
+
# @return [Pin::Closure, nil]
|
|
154
|
+
def combine_closure(other)
|
|
155
|
+
choose_pin_attr_with_same_name(other, :closure)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# @param other [self]
|
|
159
|
+
# @sg-ignore @type should override probed type
|
|
160
|
+
# @return [String]
|
|
161
|
+
def combine_name(other)
|
|
162
|
+
if needs_consistent_name? || other.needs_consistent_name?
|
|
163
|
+
assert_same(other, :name)
|
|
164
|
+
else
|
|
165
|
+
choose(other, :name)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# @return [void]
|
|
170
|
+
def reset_generated!
|
|
171
|
+
# @return_type doesn't go here as subclasses tend to assign it
|
|
172
|
+
# themselves in constructors, and they will deal with setting
|
|
173
|
+
# it in any methods that call this
|
|
174
|
+
#
|
|
175
|
+
# @docstring also doesn't go here, as there is code which
|
|
176
|
+
# directly manipulates docstring without editing comments
|
|
177
|
+
# (e.g., Api::Map::Store#index processes overrides that way
|
|
178
|
+
#
|
|
179
|
+
# Same with @directives, @macros, @maybe_directives, which
|
|
180
|
+
# regenerate docstring
|
|
181
|
+
@deprecated = nil
|
|
182
|
+
@context = nil
|
|
183
|
+
@binder = nil
|
|
184
|
+
@path = nil
|
|
185
|
+
reset_conversions
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def needs_consistent_name?
|
|
189
|
+
true
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
# @sg-ignore def should infer as symbol - "Not enough arguments to Module#protected"
|
|
193
|
+
protected def equality_fields
|
|
194
|
+
[name, location, type_location, closure, source]
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
# @param other [self]
|
|
198
|
+
# @return [ComplexType]
|
|
199
|
+
def combine_return_type(other)
|
|
200
|
+
if return_type.undefined?
|
|
201
|
+
other.return_type
|
|
202
|
+
elsif other.return_type.undefined?
|
|
203
|
+
return_type
|
|
204
|
+
elsif return_type.erased_version_of?(other.return_type)
|
|
205
|
+
other.return_type
|
|
206
|
+
elsif other.return_type.erased_version_of?(return_type)
|
|
207
|
+
return_type
|
|
208
|
+
elsif dodgy_return_type_source? && !other.dodgy_return_type_source?
|
|
209
|
+
other.return_type
|
|
210
|
+
elsif other.dodgy_return_type_source? && !dodgy_return_type_source?
|
|
211
|
+
return_type
|
|
212
|
+
else
|
|
213
|
+
all_items = return_type.items + other.return_type.items
|
|
214
|
+
if all_items.any? { |item| item.selfy? } && all_items.any? { |item| item.rooted_tag == context.reduce_class_type.rooted_tag }
|
|
215
|
+
# assume this was a declaration that should have said 'self'
|
|
216
|
+
all_items.delete_if { |item| item.rooted_tag == context.reduce_class_type.rooted_tag }
|
|
217
|
+
end
|
|
218
|
+
ComplexType.new(all_items)
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
# @sg-ignore need boolish support for ? methods
|
|
223
|
+
def dodgy_return_type_source?
|
|
224
|
+
# uses a lot of 'Object' instead of 'self'
|
|
225
|
+
location&.filename&.include?('core_ext/object/') ||
|
|
226
|
+
# ditto
|
|
227
|
+
location&.filename&.include?('stdlib/date/0/date.rbs')
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
# when choices are arbitrary, make sure the choice is consistent
|
|
231
|
+
#
|
|
232
|
+
# @param other [Pin::Base]
|
|
233
|
+
# @param attr [::Symbol]
|
|
234
|
+
#
|
|
235
|
+
# @sg-ignore
|
|
236
|
+
# @return [undefined, nil]
|
|
237
|
+
def choose(other, attr)
|
|
238
|
+
results = [self, other].map(&attr).compact
|
|
239
|
+
# true and false are different classes and can't be sorted
|
|
240
|
+
return true if results.any? { |r| r == true || r == false }
|
|
241
|
+
return results.first if results.any? { |r| r.is_a? AST::Node }
|
|
242
|
+
results.min
|
|
243
|
+
rescue
|
|
244
|
+
STDERR.puts("Problem handling #{attr} for \n#{self.inspect}\n and \n#{other.inspect}\n\n#{self.send(attr).inspect} vs #{other.send(attr).inspect}")
|
|
245
|
+
raise
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# @param other [self]
|
|
249
|
+
# @param attr [::Symbol]
|
|
250
|
+
# @sg-ignore
|
|
251
|
+
# @return [undefined]
|
|
252
|
+
def choose_node(other, attr)
|
|
253
|
+
if other.object_id < attr.object_id
|
|
254
|
+
other.send(attr)
|
|
255
|
+
else
|
|
256
|
+
send(attr)
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
# @param other [self]
|
|
261
|
+
# @param attr [::Symbol]
|
|
262
|
+
# @sg-ignore
|
|
263
|
+
# @return [undefined]
|
|
264
|
+
def prefer_rbs_location(other, attr)
|
|
265
|
+
if rbs_location? && !other.rbs_location?
|
|
266
|
+
self.send(attr)
|
|
267
|
+
elsif !rbs_location? && other.rbs_location?
|
|
268
|
+
other.send(attr)
|
|
269
|
+
else
|
|
270
|
+
choose(other, attr)
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
# @sg-ignore need boolish support for ? methods
|
|
275
|
+
def rbs_location?
|
|
276
|
+
type_location&.rbs?
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
# @param other [self]
|
|
280
|
+
# @return [void]
|
|
281
|
+
def assert_same_macros(other)
|
|
282
|
+
return unless self.source == :yardoc && other.source == :yardoc
|
|
283
|
+
assert_same_count(other, :macros)
|
|
284
|
+
# @param [YARD::Tags::MacroDirective]
|
|
285
|
+
assert_same_array_content(other, :macros) { |macro| macro.tag.name }
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
# @param other [self]
|
|
289
|
+
# @param attr [::Symbol]
|
|
290
|
+
# @return [void]
|
|
291
|
+
# @todo strong typechecking should complain when there are no block-related tags
|
|
292
|
+
def assert_same_array_content(other, attr, &block)
|
|
293
|
+
arr1 = send(attr)
|
|
294
|
+
raise "Expected #{attr} on #{self} to be an Enumerable, got #{arr1.class}" unless arr1.is_a?(::Enumerable)
|
|
295
|
+
# @type arr1 [::Enumerable]
|
|
296
|
+
arr2 = other.send(attr)
|
|
297
|
+
raise "Expected #{attr} on #{other} to be an Enumerable, got #{arr2.class}" unless arr2.is_a?(::Enumerable)
|
|
298
|
+
# @type arr2 [::Enumerable]
|
|
299
|
+
|
|
300
|
+
# @type [undefined]
|
|
301
|
+
values1 = arr1.map(&block)
|
|
302
|
+
# @type [undefined]
|
|
303
|
+
values2 = arr2.map(&block)
|
|
304
|
+
# @sg-ignore
|
|
305
|
+
return arr1 if values1 == values2
|
|
306
|
+
Solargraph.assert_or_log("combine_with_#{attr}".to_sym,
|
|
307
|
+
"Inconsistent #{attr.inspect} values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self values = #{values1}\nother values =#{attr} = #{values2}")
|
|
308
|
+
arr1
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
# @param other [self]
|
|
312
|
+
# @param attr [::Symbol]
|
|
313
|
+
#
|
|
314
|
+
# @return [::Enumerable]
|
|
315
|
+
def assert_same_count(other, attr)
|
|
316
|
+
# @type [::Enumerable]
|
|
317
|
+
arr1 = self.send(attr)
|
|
318
|
+
raise "Expected #{attr} on #{self} to be an Enumerable, got #{arr1.class}" unless arr1.is_a?(::Enumerable)
|
|
319
|
+
# @type [::Enumerable]
|
|
320
|
+
arr2 = other.send(attr)
|
|
321
|
+
raise "Expected #{attr} on #{other} to be an Enumerable, got #{arr2.class}" unless arr2.is_a?(::Enumerable)
|
|
322
|
+
return arr1 if arr1.count == arr2.count
|
|
323
|
+
Solargraph.assert_or_log("combine_with_#{attr}".to_sym,
|
|
324
|
+
"Inconsistent #{attr.inspect} count value between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{arr1.inspect}\nother.#{attr} = #{arr2.inspect}")
|
|
325
|
+
arr1
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
# @param other [self]
|
|
329
|
+
# @param attr [::Symbol]
|
|
330
|
+
#
|
|
331
|
+
# @sg-ignore
|
|
332
|
+
# @return [undefined]
|
|
333
|
+
def assert_same(other, attr)
|
|
334
|
+
if other.nil?
|
|
335
|
+
Solargraph.assert_or_log("combine_with_#{attr}_nil".to_sym,
|
|
336
|
+
"Other was passed in nil in assert_same on #{self}")
|
|
337
|
+
return send(attr)
|
|
338
|
+
end
|
|
339
|
+
val1 = send(attr)
|
|
340
|
+
val2 = other.send(attr)
|
|
341
|
+
return val1 if val1 == val2
|
|
342
|
+
Solargraph.assert_or_log("combine_with_#{attr}".to_sym,
|
|
343
|
+
"Inconsistent #{attr.inspect} values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
|
|
344
|
+
val1
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
# @param other [self]
|
|
348
|
+
# @param attr [::Symbol]
|
|
349
|
+
# @sg-ignore
|
|
350
|
+
# @return [undefined]
|
|
351
|
+
def choose_pin_attr_with_same_name(other, attr)
|
|
352
|
+
# @type [Pin::Base, nil]
|
|
353
|
+
val1 = send(attr)
|
|
354
|
+
# @type [Pin::Base, nil]
|
|
355
|
+
val2 = other.send(attr)
|
|
356
|
+
raise "Expected pin for #{attr} on\n#{self.inspect},\ngot #{val1.inspect}" unless val1.nil? || val1.is_a?(Pin::Base)
|
|
357
|
+
raise "Expected pin for #{attr} on\n#{other.inspect},\ngot #{val2.inspect}" unless val2.nil? || val2.is_a?(Pin::Base)
|
|
358
|
+
if val1&.name != val2&.name
|
|
359
|
+
Solargraph.assert_or_log("combine_with_#{attr}_name".to_sym,
|
|
360
|
+
"Inconsistent #{attr.inspect} name values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
|
|
361
|
+
end
|
|
362
|
+
choose_pin_attr(other, attr)
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
# @param other [self]
|
|
366
|
+
# @param attr [::Symbol]
|
|
367
|
+
#
|
|
368
|
+
# @sg-ignore Missing @return tag for Solargraph::Pin::Base#choose_pin_attr
|
|
369
|
+
# @return [undefined]
|
|
370
|
+
def choose_pin_attr(other, attr)
|
|
371
|
+
# @type [Pin::Base, nil]
|
|
372
|
+
val1 = send(attr)
|
|
373
|
+
# @type [Pin::Base, nil]
|
|
374
|
+
val2 = other.send(attr)
|
|
375
|
+
if val1.class != val2.class
|
|
376
|
+
# :nocov:
|
|
377
|
+
Solargraph.assert_or_log("combine_with_#{attr}_class".to_sym,
|
|
378
|
+
"Inconsistent #{attr.inspect} class values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
|
|
379
|
+
return val1
|
|
380
|
+
# :nocov:
|
|
381
|
+
end
|
|
382
|
+
# arbitrary way of choosing a pin
|
|
383
|
+
[val1, val2].compact.max_by do |closure|
|
|
384
|
+
[
|
|
385
|
+
# maximize number of gates, as types in other combined pins may
|
|
386
|
+
# depend on those gates
|
|
387
|
+
|
|
388
|
+
# @sg-ignore Need better handling of #compact
|
|
389
|
+
closure.gates.length,
|
|
390
|
+
# use basename so that results don't vary system to system
|
|
391
|
+
# @sg-ignore Need better handling of #compact
|
|
392
|
+
File.basename(closure.best_location.to_s)
|
|
393
|
+
]
|
|
394
|
+
end
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
# @return [void]
|
|
398
|
+
def assert_source_provided
|
|
399
|
+
Solargraph.assert_or_log(:source, "source not provided - #{@path} #{@source} #{self.class}") if source.nil?
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
# @return [String]
|
|
403
|
+
def comments
|
|
404
|
+
@comments ||= ''
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
# @param generics_to_resolve [Enumerable<String>]
|
|
408
|
+
# @param return_type_context [ComplexType, ComplexType::UniqueType, nil]
|
|
409
|
+
# @param context [ComplexType]
|
|
410
|
+
# @param resolved_generic_values [Hash{String => ComplexType}]
|
|
411
|
+
# @return [self]
|
|
412
|
+
def resolve_generics_from_context(generics_to_resolve, return_type_context = nil, resolved_generic_values: {})
|
|
413
|
+
proxy return_type.resolve_generics_from_context(generics_to_resolve,
|
|
414
|
+
return_type_context,
|
|
415
|
+
resolved_generic_values: resolved_generic_values)
|
|
416
|
+
end
|
|
417
|
+
|
|
418
|
+
# @yieldparam [ComplexType]
|
|
419
|
+
# @yieldreturn [ComplexType]
|
|
420
|
+
# @return [self]
|
|
421
|
+
def transform_types(&transform)
|
|
422
|
+
proxy return_type.transform(&transform)
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
# Determine the concrete type for each of the generic type
|
|
426
|
+
# parameters used in this method based on the parameters passed
|
|
427
|
+
# into the its class and return a new method pin.
|
|
428
|
+
#
|
|
429
|
+
# @param definitions [Pin::Namespace] The module/class which uses generic types
|
|
430
|
+
# @param context_type [ComplexType] The receiver type
|
|
431
|
+
# @return [self]
|
|
432
|
+
def resolve_generics definitions, context_type
|
|
433
|
+
transform_types { |t| t.resolve_generics(definitions, context_type) if t }
|
|
434
|
+
end
|
|
435
|
+
|
|
436
|
+
def all_rooted?
|
|
437
|
+
!return_type || return_type.all_rooted?
|
|
438
|
+
end
|
|
439
|
+
|
|
440
|
+
# @param generics_to_erase [::Array<String>]
|
|
441
|
+
# @return [self]
|
|
442
|
+
def erase_generics(generics_to_erase)
|
|
443
|
+
return self if generics_to_erase.empty?
|
|
444
|
+
transform_types { |t| t.erase_generics(generics_to_erase) }
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
# @return [String, nil]
|
|
448
|
+
def filename
|
|
449
|
+
return nil if location.nil?
|
|
450
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
451
|
+
location.filename
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
# @return [Integer]
|
|
455
|
+
def completion_item_kind
|
|
456
|
+
LanguageServer::CompletionItemKinds::KEYWORD
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
# @return [Integer, nil]
|
|
460
|
+
def symbol_kind
|
|
461
|
+
nil
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
def to_s
|
|
465
|
+
desc
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
# @return [Boolean]
|
|
469
|
+
def variable?
|
|
470
|
+
false
|
|
471
|
+
end
|
|
472
|
+
|
|
473
|
+
# @return [Location, nil]
|
|
474
|
+
def best_location
|
|
475
|
+
location || type_location
|
|
476
|
+
end
|
|
477
|
+
|
|
478
|
+
# True if the specified pin is a near match to this one. A near match
|
|
479
|
+
# indicates that the pins contain mostly the same data. Any differences
|
|
480
|
+
# between them should not have an impact on the API surface.
|
|
481
|
+
#
|
|
482
|
+
# @param other [Solargraph::Pin::Base, Object]
|
|
483
|
+
# @return [Boolean]
|
|
484
|
+
def nearly? other
|
|
485
|
+
self.class == other.class &&
|
|
486
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
487
|
+
name == other.name &&
|
|
488
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
489
|
+
(closure == other.closure || (closure && closure.nearly?(other.closure))) &&
|
|
490
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
491
|
+
(comments == other.comments ||
|
|
492
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
493
|
+
(((maybe_directives? == false && other.maybe_directives? == false) || compare_directives(directives, other.directives)) &&
|
|
494
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
495
|
+
compare_docstring_tags(docstring, other.docstring))
|
|
496
|
+
)
|
|
497
|
+
end
|
|
498
|
+
|
|
499
|
+
# Pin equality is determined using the #nearly? method and also
|
|
500
|
+
# requiring both pins to have the same location.
|
|
501
|
+
#
|
|
502
|
+
# @param other [Object]
|
|
503
|
+
def == other
|
|
504
|
+
return false unless nearly? other
|
|
505
|
+
# @sg-ignore Should add more explicit type check on other
|
|
506
|
+
comments == other.comments && location == other.location
|
|
507
|
+
end
|
|
508
|
+
|
|
509
|
+
# The pin's return type.
|
|
510
|
+
#
|
|
511
|
+
# @return [ComplexType]
|
|
512
|
+
def return_type
|
|
513
|
+
@return_type ||= ComplexType::UNDEFINED
|
|
514
|
+
end
|
|
515
|
+
|
|
516
|
+
# @return [YARD::Docstring]
|
|
517
|
+
def docstring
|
|
518
|
+
parse_comments unless @docstring
|
|
519
|
+
@docstring ||= Solargraph::Source.parse_docstring('').to_docstring
|
|
520
|
+
end
|
|
521
|
+
|
|
522
|
+
# @sg-ignore parse_comments will always set @directives
|
|
523
|
+
# @return [::Array<YARD::Tags::Directive>]
|
|
524
|
+
def directives
|
|
525
|
+
parse_comments unless @directives
|
|
526
|
+
@directives
|
|
527
|
+
end
|
|
528
|
+
|
|
529
|
+
# @return [::Array<YARD::Tags::MacroDirective>]
|
|
530
|
+
def macros
|
|
531
|
+
@macros ||= collect_macros
|
|
532
|
+
end
|
|
533
|
+
|
|
534
|
+
# Perform a quick check to see if this pin possibly includes YARD
|
|
535
|
+
# directives. This method does not require parsing the comments.
|
|
536
|
+
#
|
|
537
|
+
# After the comments have been parsed, this method will return false if
|
|
538
|
+
# no directives were found, regardless of whether it previously appeared
|
|
539
|
+
# possible.
|
|
540
|
+
#
|
|
541
|
+
# @return [Boolean]
|
|
542
|
+
def maybe_directives?
|
|
543
|
+
return !@directives.empty? if defined?(@directives) && @directives
|
|
544
|
+
@maybe_directives ||= comments.include?('@!')
|
|
545
|
+
end
|
|
546
|
+
|
|
547
|
+
# @return [Boolean]
|
|
548
|
+
def deprecated?
|
|
549
|
+
@deprecated ||= docstring.has_tag?('deprecated')
|
|
550
|
+
end
|
|
551
|
+
|
|
552
|
+
# Get a fully qualified type from the pin's return type.
|
|
553
|
+
#
|
|
554
|
+
# The relative type is determined from YARD documentation (@return,
|
|
555
|
+
# @param, @type, etc.) and its namespaces are fully qualified using the
|
|
556
|
+
# provided ApiMap.
|
|
557
|
+
#
|
|
558
|
+
# @param api_map [ApiMap]
|
|
559
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
560
|
+
def typify api_map
|
|
561
|
+
return_type.qualify(api_map, *(closure&.gates || ['']))
|
|
562
|
+
end
|
|
563
|
+
|
|
564
|
+
# Infer the pin's return type via static code analysis.
|
|
565
|
+
#
|
|
566
|
+
# @param api_map [ApiMap]
|
|
567
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
568
|
+
def probe api_map
|
|
569
|
+
typify api_map
|
|
570
|
+
end
|
|
571
|
+
|
|
572
|
+
# @deprecated Use #typify and/or #probe instead
|
|
573
|
+
# @param api_map [ApiMap]
|
|
574
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
575
|
+
def infer api_map
|
|
576
|
+
Solargraph.assert_or_log(:pin_infer, 'WARNING: Pin #infer methods are deprecated. Use #typify or #probe instead.')
|
|
577
|
+
type = typify(api_map)
|
|
578
|
+
return type unless type.undefined?
|
|
579
|
+
probe api_map
|
|
580
|
+
end
|
|
581
|
+
|
|
582
|
+
def proxied?
|
|
583
|
+
@proxied ||= false
|
|
584
|
+
end
|
|
585
|
+
|
|
586
|
+
def probed?
|
|
587
|
+
@probed ||= false
|
|
588
|
+
end
|
|
589
|
+
|
|
590
|
+
# @param api_map [ApiMap]
|
|
591
|
+
# @return [self]
|
|
592
|
+
def realize api_map
|
|
593
|
+
return self if return_type.defined?
|
|
594
|
+
type = typify(api_map)
|
|
595
|
+
return proxy(type) if type.defined?
|
|
596
|
+
type = probe(api_map)
|
|
597
|
+
return self if type.undefined?
|
|
598
|
+
result = proxy(type)
|
|
599
|
+
result.probed = true
|
|
600
|
+
result
|
|
601
|
+
end
|
|
602
|
+
|
|
603
|
+
# Return a proxy for this pin with the specified return type. Other than
|
|
604
|
+
# the return type and the #proxied? setting, the proxy should be a clone
|
|
605
|
+
# of the original.
|
|
606
|
+
#
|
|
607
|
+
# @param return_type [ComplexType, ComplexType::UniqueType, nil]
|
|
608
|
+
# @return [self]
|
|
609
|
+
def proxy return_type
|
|
610
|
+
result = dup
|
|
611
|
+
result.return_type = return_type
|
|
612
|
+
result.proxied = true
|
|
613
|
+
result
|
|
614
|
+
end
|
|
615
|
+
|
|
616
|
+
# @deprecated
|
|
617
|
+
# @return [String]
|
|
618
|
+
def identity
|
|
619
|
+
@identity ||= "#{closure&.path}|#{name}|#{location}"
|
|
620
|
+
end
|
|
621
|
+
|
|
622
|
+
# The namespaces available for resolving the current namespace. Each gate
|
|
623
|
+
# should be a fully qualified namespace or the root namespace (i.e., an
|
|
624
|
+
# empty string.)
|
|
625
|
+
#
|
|
626
|
+
# Example: Given the name 'Bar' and the gates ['Foo', ''],
|
|
627
|
+
# the fully qualified namespace should be 'Foo::Bar' or 'Bar'.
|
|
628
|
+
#
|
|
629
|
+
# @return [Array<String>]
|
|
630
|
+
def gates
|
|
631
|
+
@gates ||= closure&.gates || ['']
|
|
632
|
+
end
|
|
633
|
+
|
|
634
|
+
# @return [String, nil]
|
|
635
|
+
def to_rbs
|
|
636
|
+
return_type.to_rbs
|
|
637
|
+
end
|
|
638
|
+
|
|
639
|
+
# @return [String, nil]
|
|
640
|
+
def type_desc
|
|
641
|
+
rbs = to_rbs
|
|
642
|
+
# RBS doesn't have a way to represent a Class<x> type
|
|
643
|
+
rbs = return_type.rooted_tags if return_type.name == 'Class'
|
|
644
|
+
if path
|
|
645
|
+
if rbs
|
|
646
|
+
path + ' ' + rbs
|
|
647
|
+
else
|
|
648
|
+
path
|
|
649
|
+
end
|
|
650
|
+
else
|
|
651
|
+
rbs
|
|
652
|
+
end
|
|
653
|
+
end
|
|
654
|
+
|
|
655
|
+
# @return [String]
|
|
656
|
+
def inner_desc
|
|
657
|
+
closure_info = closure&.name.inspect
|
|
658
|
+
binder_info = binder&.desc
|
|
659
|
+
"name=#{name.inspect} return_type=#{type_desc}, context=#{context.rooted_tags}, closure=#{closure_info}, binder=#{binder_info}"
|
|
660
|
+
end
|
|
661
|
+
|
|
662
|
+
# @return [String]
|
|
663
|
+
def desc
|
|
664
|
+
"[#{inner_desc}]"
|
|
665
|
+
end
|
|
666
|
+
|
|
667
|
+
# @return [String]
|
|
668
|
+
def inspect
|
|
669
|
+
"#<#{self.class} `#{self.inner_desc}`#{all_location_text} via #{source.inspect}>"
|
|
670
|
+
end
|
|
671
|
+
|
|
672
|
+
# @return [String]
|
|
673
|
+
def all_location_text
|
|
674
|
+
if location.nil? && type_location.nil?
|
|
675
|
+
''
|
|
676
|
+
elsif !location.nil? && type_location.nil?
|
|
677
|
+
" at #{location.inspect})"
|
|
678
|
+
elsif !type_location.nil? && location.nil?
|
|
679
|
+
" at #{type_location.inspect})"
|
|
680
|
+
else
|
|
681
|
+
" at (#{location.inspect} and #{type_location.inspect})"
|
|
682
|
+
end
|
|
683
|
+
end
|
|
684
|
+
|
|
685
|
+
protected
|
|
686
|
+
|
|
687
|
+
# @return [Boolean]
|
|
688
|
+
attr_writer :probed
|
|
689
|
+
|
|
690
|
+
# @return [Boolean]
|
|
691
|
+
attr_writer :proxied
|
|
692
|
+
|
|
693
|
+
# @return [ComplexType, ComplexType::UniqueType, nil]
|
|
694
|
+
attr_writer :return_type
|
|
695
|
+
|
|
696
|
+
attr_writer :docstring
|
|
697
|
+
|
|
698
|
+
attr_writer :directives
|
|
699
|
+
|
|
700
|
+
private
|
|
701
|
+
|
|
702
|
+
# @return [void]
|
|
703
|
+
def parse_comments
|
|
704
|
+
# HACK: Avoid a NoMethodError on nil with empty overload tags
|
|
705
|
+
if comments.nil? || comments.empty? || comments.strip.end_with?('@overload')
|
|
706
|
+
@docstring = nil
|
|
707
|
+
@directives = []
|
|
708
|
+
else
|
|
709
|
+
# HACK: Pass a dummy code object to the parser for plugins that
|
|
710
|
+
# expect it not to be nil
|
|
711
|
+
parse = Solargraph::Source.parse_docstring(comments)
|
|
712
|
+
@docstring = parse.to_docstring
|
|
713
|
+
@directives = parse.directives
|
|
714
|
+
end
|
|
715
|
+
end
|
|
716
|
+
|
|
717
|
+
# True if two docstrings have the same tags, regardless of any other
|
|
718
|
+
# differences.
|
|
719
|
+
#
|
|
720
|
+
# @param d1 [YARD::Docstring]
|
|
721
|
+
# @param d2 [YARD::Docstring]
|
|
722
|
+
# @return [Boolean]
|
|
723
|
+
def compare_docstring_tags d1, d2
|
|
724
|
+
return false if d1.tags.length != d2.tags.length
|
|
725
|
+
d1.tags.each_index do |i|
|
|
726
|
+
return false unless compare_tags(d1.tags[i], d2.tags[i])
|
|
727
|
+
end
|
|
728
|
+
true
|
|
729
|
+
end
|
|
730
|
+
|
|
731
|
+
# @param dir1 [::Array<YARD::Tags::Directive>]
|
|
732
|
+
# @param dir2 [::Array<YARD::Tags::Directive>]
|
|
733
|
+
# @return [Boolean]
|
|
734
|
+
def compare_directives dir1, dir2
|
|
735
|
+
return false if dir1.length != dir2.length
|
|
736
|
+
dir1.each_index do |i|
|
|
737
|
+
return false unless compare_tags(dir1[i].tag, dir2[i].tag)
|
|
738
|
+
end
|
|
739
|
+
true
|
|
740
|
+
end
|
|
741
|
+
|
|
742
|
+
# @param tag1 [YARD::Tags::Tag]
|
|
743
|
+
# @param tag2 [YARD::Tags::Tag]
|
|
744
|
+
# @return [Boolean]
|
|
745
|
+
def compare_tags tag1, tag2
|
|
746
|
+
tag1.class == tag2.class &&
|
|
747
|
+
tag1.tag_name == tag2.tag_name &&
|
|
748
|
+
tag1.text == tag2.text &&
|
|
749
|
+
tag1.name == tag2.name &&
|
|
750
|
+
tag1.types == tag2.types
|
|
751
|
+
end
|
|
752
|
+
|
|
753
|
+
# @return [::Array<YARD::Tags::Handlers::Directive>]
|
|
754
|
+
def collect_macros
|
|
755
|
+
return [] unless maybe_directives?
|
|
756
|
+
parse = Solargraph::Source.parse_docstring(comments)
|
|
757
|
+
parse.directives.select{ |d| d.tag.tag_name == 'macro' }
|
|
758
|
+
end
|
|
759
|
+
end
|
|
760
|
+
end
|
|
761
|
+
end
|