solargraph 0.55.3 → 0.55.4
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/.github/workflows/typecheck.yml +1 -1
- data/CHANGELOG.md +4 -1
- data/lib/solargraph/api_map/store.rb +6 -3
- data/lib/solargraph/api_map.rb +97 -30
- data/lib/solargraph/complex_type/type_methods.rb +1 -0
- data/lib/solargraph/complex_type/unique_type.rb +3 -2
- data/lib/solargraph/doc_map.rb +3 -3
- data/lib/solargraph/gem_pins.rb +2 -1
- data/lib/solargraph/language_server/host.rb +2 -1
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +1 -0
- data/lib/solargraph/logging.rb +1 -0
- data/lib/solargraph/parser/comment_ripper.rb +1 -0
- data/lib/solargraph/parser/flow_sensitive_typing.rb +2 -1
- data/lib/solargraph/parser/node_processor.rb +3 -1
- data/lib/solargraph/parser/parser_gem/node_methods.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/alias_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +4 -2
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +4 -2
- data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +6 -3
- data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +4 -2
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +4 -2
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +4 -3
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +28 -16
- data/lib/solargraph/parser/parser_gem/node_processors/sym_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +1 -0
- data/lib/solargraph/parser/region.rb +1 -1
- data/lib/solargraph/pin/base.rb +27 -4
- data/lib/solargraph/pin/callable.rb +5 -3
- data/lib/solargraph/pin/closure.rb +6 -1
- data/lib/solargraph/pin/common.rb +5 -0
- data/lib/solargraph/pin/delegated_method.rb +2 -0
- data/lib/solargraph/pin/documenting.rb +16 -0
- data/lib/solargraph/pin/keyword.rb +7 -2
- data/lib/solargraph/pin/method.rb +14 -9
- data/lib/solargraph/pin/namespace.rb +7 -2
- data/lib/solargraph/pin/parameter.rb +4 -0
- data/lib/solargraph/pin/proxy_type.rb +3 -3
- data/lib/solargraph/pin/reference/override.rb +10 -6
- data/lib/solargraph/pin/reference/require.rb +2 -2
- data/lib/solargraph/pin/signature.rb +4 -0
- data/lib/solargraph/pin/singleton.rb +1 -1
- data/lib/solargraph/pin/symbol.rb +3 -2
- data/lib/solargraph/pin.rb +1 -1
- data/lib/solargraph/rbs_map/conversions.rb +164 -48
- data/lib/solargraph/rbs_map/core_fills.rb +24 -15
- data/lib/solargraph/rbs_map/core_map.rb +3 -2
- data/lib/solargraph/shell.rb +1 -0
- data/lib/solargraph/source/chain/array.rb +7 -4
- data/lib/solargraph/source/chain/block_symbol.rb +1 -1
- data/lib/solargraph/source/chain/block_variable.rb +1 -1
- data/lib/solargraph/source/chain/call.rb +8 -7
- data/lib/solargraph/source/chain/hash.rb +1 -1
- data/lib/solargraph/source/chain/head.rb +1 -1
- data/lib/solargraph/source/chain/if.rb +1 -1
- data/lib/solargraph/source/chain/literal.rb +2 -2
- data/lib/solargraph/source/chain/or.rb +1 -1
- data/lib/solargraph/source/chain.rb +2 -2
- data/lib/solargraph/source_map/mapper.rb +9 -5
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/yard_map/mapper/to_constant.rb +4 -2
- data/lib/solargraph/yard_map/mapper/to_method.rb +14 -1
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +4 -2
- data/lib/solargraph/yard_map/mapper.rb +4 -3
- data/lib/solargraph/yard_map/to_method.rb +4 -2
- data/lib/solargraph.rb +19 -0
- data/rbs/fills/tuple.rbs +150 -0
- metadata +3 -2
@@ -7,6 +7,8 @@ module Solargraph
|
|
7
7
|
# Functions for converting RBS declarations to Solargraph pins
|
8
8
|
#
|
9
9
|
module Conversions
|
10
|
+
include Logging
|
11
|
+
|
10
12
|
# A container for tracking the current context of the RBS conversion
|
11
13
|
# process, e.g., what visibility is declared for methods in the current
|
12
14
|
# scope
|
@@ -38,8 +40,6 @@ module Solargraph
|
|
38
40
|
environment = RBS::Environment.from_loader(loader).resolve_type_names
|
39
41
|
cursor = pins.length
|
40
42
|
environment.declarations.each { |decl| convert_decl_to_pin(decl, Solargraph::Pin::ROOT_PIN) }
|
41
|
-
added_pins = pins[cursor..-1]
|
42
|
-
added_pins.each { |pin| pin.source = :rbs }
|
43
43
|
end
|
44
44
|
|
45
45
|
# @param decl [RBS::AST::Declarations::Base]
|
@@ -86,7 +86,8 @@ module Solargraph
|
|
86
86
|
name: decl.name.relative!.to_s,
|
87
87
|
type_location: location_decl_to_pin_location(decl.location),
|
88
88
|
generic_values: generic_values,
|
89
|
-
closure: closure
|
89
|
+
closure: closure,
|
90
|
+
source: :rbs
|
90
91
|
)
|
91
92
|
pins.push include_pin
|
92
93
|
end
|
@@ -106,13 +107,13 @@ module Solargraph
|
|
106
107
|
def convert_member_to_pin member, closure, context
|
107
108
|
case member
|
108
109
|
when RBS::AST::Members::MethodDefinition
|
109
|
-
method_def_to_pin(member, closure)
|
110
|
+
method_def_to_pin(member, closure, context)
|
110
111
|
when RBS::AST::Members::AttrReader
|
111
|
-
attr_reader_to_pin(member, closure)
|
112
|
+
attr_reader_to_pin(member, closure, context)
|
112
113
|
when RBS::AST::Members::AttrWriter
|
113
|
-
attr_writer_to_pin(member, closure)
|
114
|
+
attr_writer_to_pin(member, closure, context)
|
114
115
|
when RBS::AST::Members::AttrAccessor
|
115
|
-
attr_accessor_to_pin(member, closure)
|
116
|
+
attr_accessor_to_pin(member, closure, context)
|
116
117
|
when RBS::AST::Members::Include
|
117
118
|
include_to_pin(member, closure)
|
118
119
|
when RBS::AST::Members::Prepend
|
@@ -128,9 +129,9 @@ module Solargraph
|
|
128
129
|
when RBS::AST::Members::InstanceVariable
|
129
130
|
ivar_to_pin(member, closure)
|
130
131
|
when RBS::AST::Members::Public
|
131
|
-
return Context.new(
|
132
|
+
return Context.new(:public)
|
132
133
|
when RBS::AST::Members::Private
|
133
|
-
return Context.new(
|
134
|
+
return Context.new(:private)
|
134
135
|
when RBS::AST::Declarations::Base
|
135
136
|
convert_decl_to_pin(member, closure)
|
136
137
|
else
|
@@ -142,6 +143,14 @@ module Solargraph
|
|
142
143
|
# @param decl [RBS::AST::Declarations::Class]
|
143
144
|
# @return [void]
|
144
145
|
def class_decl_to_pin decl
|
146
|
+
generics = decl.type_params.map(&:name).map(&:to_s)
|
147
|
+
generic_defaults = {}
|
148
|
+
decl.type_params.each do |param|
|
149
|
+
if param.default_type
|
150
|
+
tag = other_type_to_tag param.default_type
|
151
|
+
generic_defaults[param.name.to_s] = ComplexType.parse(tag).force_rooted
|
152
|
+
end
|
153
|
+
end
|
145
154
|
class_pin = Solargraph::Pin::Namespace.new(
|
146
155
|
type: :class,
|
147
156
|
name: decl.name.relative!.to_s,
|
@@ -151,14 +160,20 @@ module Solargraph
|
|
151
160
|
# @todo some type parameters in core/stdlib have default
|
152
161
|
# values; Solargraph doesn't support that yet as so these
|
153
162
|
# get treated as undefined if not specified
|
154
|
-
generics:
|
163
|
+
generics: generics,
|
164
|
+
generic_defaults: generic_defaults,
|
165
|
+
source: :rbs
|
155
166
|
)
|
156
167
|
pins.push class_pin
|
157
168
|
if decl.super_class
|
169
|
+
type = build_type(decl.super_class.name, decl.super_class.args)
|
170
|
+
generic_values = type.all_params.map(&:to_s)
|
158
171
|
pins.push Solargraph::Pin::Reference::Superclass.new(
|
159
172
|
type_location: location_decl_to_pin_location(decl.super_class.location),
|
160
173
|
closure: class_pin,
|
161
|
-
|
174
|
+
generic_values: generic_values,
|
175
|
+
name: decl.super_class.name.relative!.to_s,
|
176
|
+
source: :rbs
|
162
177
|
)
|
163
178
|
end
|
164
179
|
add_mixins decl, class_pin
|
@@ -178,7 +193,8 @@ module Solargraph
|
|
178
193
|
generics: decl.type_params.map(&:name).map(&:to_s),
|
179
194
|
# HACK: Using :hidden to keep interfaces from appearing in
|
180
195
|
# autocompletion
|
181
|
-
visibility: :hidden
|
196
|
+
visibility: :hidden,
|
197
|
+
source: :rbs
|
182
198
|
)
|
183
199
|
class_pin.docstring.add_tag(YARD::Tags::Tag.new(:abstract, '(RBS interface)'))
|
184
200
|
pins.push class_pin
|
@@ -195,6 +211,7 @@ module Solargraph
|
|
195
211
|
closure: Solargraph::Pin::ROOT_PIN,
|
196
212
|
comments: decl.comment&.string,
|
197
213
|
generics: decl.type_params.map(&:name).map(&:to_s),
|
214
|
+
source: :rbs
|
198
215
|
)
|
199
216
|
pins.push module_pin
|
200
217
|
convert_self_types_to_pins decl, module_pin
|
@@ -223,7 +240,8 @@ module Solargraph
|
|
223
240
|
name: name,
|
224
241
|
closure: closure,
|
225
242
|
type_location: location_decl_to_pin_location(decl.location),
|
226
|
-
comments: comments
|
243
|
+
comments: comments,
|
244
|
+
source: :rbs
|
227
245
|
)
|
228
246
|
tag = "#{base}<#{tag}>" if base
|
229
247
|
rooted_tag = ComplexType.parse(tag).force_rooted.rooted_tags
|
@@ -267,32 +285,92 @@ module Solargraph
|
|
267
285
|
name: name,
|
268
286
|
closure: closure,
|
269
287
|
comments: decl.comment&.string,
|
288
|
+
source: :rbs
|
270
289
|
)
|
271
290
|
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
272
291
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
273
292
|
pins.push pin
|
274
293
|
end
|
275
294
|
|
295
|
+
|
296
|
+
# Visibility overrides that will allow the Solargraph project
|
297
|
+
# and plugins to pass typechecking using SOLARGRAPH_ASSERTS=on,
|
298
|
+
# so that we can detect any regressions/issues elsewhere in the
|
299
|
+
# visibility logic.
|
300
|
+
#
|
301
|
+
# These should either reflect a bug upstream in the RBS
|
302
|
+
# definitions, or include a @todo indicating what needs to be
|
303
|
+
# fixed in Solargraph to properly understand it.
|
304
|
+
#
|
305
|
+
# @todo PR these fixes upstream and list open PRs here above
|
306
|
+
# related overrides
|
307
|
+
# @todo externalize remaining overrides into yaml file, then
|
308
|
+
# allow that to be extended via .solargraph.yml
|
309
|
+
VISIBILITY_OVERRIDE = {
|
310
|
+
["Rails::Engine", :instance, "run_tasks_blocks"] => :protected,
|
311
|
+
# Should have been marked as both instance and class method in module -e.g., 'module_function'
|
312
|
+
["Kernel", :instance, "pretty_inspect"] => :private,
|
313
|
+
# marked incorrectly in RBS
|
314
|
+
["WEBrick::HTTPUtils::FormData", :instance, "next_data"] => :protected,
|
315
|
+
["Rails::Command", :class, "command_type"] => :private,
|
316
|
+
["Rails::Command", :class, "lookup_paths"] => :private,
|
317
|
+
["Rails::Command", :class, "file_lookup_paths"] => :private,
|
318
|
+
["Rails::Railtie", :instance, "run_console_blocks"] => :protected,
|
319
|
+
["Rails::Railtie", :instance, "run_generators_blocks"] => :protected,
|
320
|
+
["Rails::Railtie", :instance, "run_runner_blocks"] => :protected,
|
321
|
+
["Rails::Railtie", :instance, "run_tasks_blocks"] => :protected,
|
322
|
+
["ActionController::Base", :instance, "_protected_ivars"] => :private,
|
323
|
+
["ActionView::Template", :instance, "method_name"] => :public,
|
324
|
+
["Module", :instance, "ruby2_keywords"] => :private,
|
325
|
+
["Nokogiri::XML::Node", :instance, "coerce"] => :protected,
|
326
|
+
["Nokogiri::XML::Document", :class, "empty_doc?"] => :private,
|
327
|
+
["Nokogiri::Decorators::Slop", :instance, "respond_to_missing?"] => :public,
|
328
|
+
["RuboCop::Cop::RangeHelp", :instance, "source_range"] => :private,
|
329
|
+
["AST::Node", :instance, "original_dup"] => :private,
|
330
|
+
["Rainbow::Presenter", :instance, "wrap_with_sgr"] => :private,
|
331
|
+
}
|
332
|
+
|
333
|
+
def calculate_method_visibility(decl, context, closure, scope, name)
|
334
|
+
override_key = [closure.path, scope, name]
|
335
|
+
visibility = VISIBILITY_OVERRIDE[override_key]
|
336
|
+
simple_override_key = [closure.path, scope]
|
337
|
+
visibility ||= VISIBILITY_OVERRIDE[simple_override_key]
|
338
|
+
visibility ||= :private if closure.path == 'Kernel' && Kernel.private_instance_methods(false).include?(decl.name)
|
339
|
+
if decl.kind == :singleton_instance
|
340
|
+
# this is a 'module function'
|
341
|
+
visibility ||= :private
|
342
|
+
end
|
343
|
+
visibility ||= decl.visibility
|
344
|
+
visibility ||= context.visibility
|
345
|
+
visibility ||= :public
|
346
|
+
visibility
|
347
|
+
end
|
348
|
+
|
276
349
|
# @param decl [RBS::AST::Members::MethodDefinition]
|
277
350
|
# @param closure [Pin::Closure]
|
351
|
+
# @param context [Context]
|
278
352
|
# @return [void]
|
279
|
-
def method_def_to_pin decl, closure
|
353
|
+
def method_def_to_pin decl, closure, context
|
280
354
|
# there may be edge cases here around different signatures
|
281
355
|
# having different type params / orders - we may need to match
|
282
356
|
# this data model and have generics live in signatures to
|
283
357
|
# handle those correctly
|
284
358
|
generics = decl.overloads.map(&:method_type).flat_map(&:type_params).map(&:name).map(&:to_s).uniq
|
359
|
+
|
285
360
|
if decl.instance?
|
361
|
+
name = decl.name.to_s
|
362
|
+
final_scope = :instance
|
363
|
+
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
286
364
|
pin = Solargraph::Pin::Method.new(
|
287
|
-
name:
|
365
|
+
name: name,
|
288
366
|
closure: closure,
|
289
367
|
type_location: location_decl_to_pin_location(decl.location),
|
290
368
|
comments: decl.comment&.string,
|
291
|
-
scope:
|
369
|
+
scope: final_scope,
|
292
370
|
signatures: [],
|
293
371
|
generics: generics,
|
294
|
-
|
295
|
-
|
372
|
+
visibility: visibility,
|
373
|
+
source: :rbs
|
296
374
|
)
|
297
375
|
pin.signatures.concat method_def_to_sigs(decl, pin)
|
298
376
|
pins.push pin
|
@@ -302,14 +380,19 @@ module Solargraph
|
|
302
380
|
end
|
303
381
|
end
|
304
382
|
if decl.singleton?
|
383
|
+
final_scope = :class
|
384
|
+
name = decl.name.to_s
|
385
|
+
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
305
386
|
pin = Solargraph::Pin::Method.new(
|
306
|
-
name:
|
387
|
+
name: name,
|
307
388
|
closure: closure,
|
308
389
|
comments: decl.comment&.string,
|
309
390
|
type_location: location_decl_to_pin_location(decl.location),
|
310
|
-
|
391
|
+
visibility: visibility,
|
392
|
+
scope: final_scope,
|
311
393
|
signatures: [],
|
312
|
-
generics: generics
|
394
|
+
generics: generics,
|
395
|
+
source: :rbs
|
313
396
|
)
|
314
397
|
pin.signatures.concat method_def_to_sigs(decl, pin)
|
315
398
|
pins.push pin
|
@@ -325,9 +408,11 @@ module Solargraph
|
|
325
408
|
signature_parameters, signature_return_type = parts_of_function(overload.method_type, pin)
|
326
409
|
block = if overload.method_type.block
|
327
410
|
block_parameters, block_return_type = parts_of_function(overload.method_type.block, pin)
|
328
|
-
Pin::Signature.new(generics: generics, parameters: block_parameters, return_type: block_return_type
|
411
|
+
Pin::Signature.new(generics: generics, parameters: block_parameters, return_type: block_return_type,
|
412
|
+
closure: pin, source: :rbs)
|
329
413
|
end
|
330
|
-
Pin::Signature.new(generics: generics, parameters: signature_parameters, return_type: signature_return_type, block: block
|
414
|
+
Pin::Signature.new(generics: generics, parameters: signature_parameters, return_type: signature_return_type, block: block,
|
415
|
+
closure: pin, source: :rbs)
|
331
416
|
end
|
332
417
|
end
|
333
418
|
|
@@ -346,40 +431,44 @@ module Solargraph
|
|
346
431
|
# @param pin [Pin::Method]
|
347
432
|
# @return [Array(Array<Pin::Parameter>, ComplexType)]
|
348
433
|
def parts_of_function type, pin
|
349
|
-
return [[Solargraph::Pin::Parameter.new(decl: :restarg, name: 'arg', closure: pin)], ComplexType.try_parse(method_type_to_tag(type)).force_rooted] if defined?(RBS::Types::UntypedFunction) && type.type.is_a?(RBS::Types::UntypedFunction)
|
434
|
+
return [[Solargraph::Pin::Parameter.new(decl: :restarg, name: 'arg', closure: pin, source: :rbs)], ComplexType.try_parse(method_type_to_tag(type)).force_rooted] if defined?(RBS::Types::UntypedFunction) && type.type.is_a?(RBS::Types::UntypedFunction)
|
350
435
|
|
351
436
|
parameters = []
|
352
437
|
arg_num = -1
|
353
438
|
type.type.required_positionals.each do |param|
|
354
439
|
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
355
|
-
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin, return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted)
|
440
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin, return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted, source: :rbs)
|
356
441
|
end
|
357
442
|
type.type.optional_positionals.each do |param|
|
358
443
|
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
359
444
|
parameters.push Solargraph::Pin::Parameter.new(decl: :optarg, name: name, closure: pin,
|
360
|
-
return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted
|
445
|
+
return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted,
|
446
|
+
source: :rbs)
|
361
447
|
end
|
362
448
|
if type.type.rest_positionals
|
363
449
|
name = type.type.rest_positionals.name ? type.type.rest_positionals.name.to_s : "arg_#{arg_num += 1}"
|
364
|
-
parameters.push Solargraph::Pin::Parameter.new(decl: :restarg, name: name, closure: pin)
|
450
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :restarg, name: name, closure: pin, source: :rbs)
|
365
451
|
end
|
366
452
|
type.type.trailing_positionals.each do |param|
|
367
453
|
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
368
|
-
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin)
|
454
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin, source: :rbs)
|
369
455
|
end
|
370
456
|
type.type.required_keywords.each do |orig, param|
|
371
457
|
name = orig ? orig.to_s : "arg_#{arg_num += 1}"
|
372
458
|
parameters.push Solargraph::Pin::Parameter.new(decl: :kwarg, name: name, closure: pin,
|
373
|
-
return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted
|
459
|
+
return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted,
|
460
|
+
source: :rbs)
|
374
461
|
end
|
375
462
|
type.type.optional_keywords.each do |orig, param|
|
376
463
|
name = orig ? orig.to_s : "arg_#{arg_num += 1}"
|
377
464
|
parameters.push Solargraph::Pin::Parameter.new(decl: :kwoptarg, name: name, closure: pin,
|
378
|
-
return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted
|
465
|
+
return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted,
|
466
|
+
source: :rbs)
|
379
467
|
end
|
380
468
|
if type.type.rest_keywords
|
381
469
|
name = type.type.rest_keywords.name ? type.type.rest_keywords.name.to_s : "arg_#{arg_num += 1}"
|
382
|
-
parameters.push Solargraph::Pin::Parameter.new(decl: :kwrestarg, name: type.type.rest_keywords.name.to_s, closure: pin
|
470
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :kwrestarg, name: type.type.rest_keywords.name.to_s, closure: pin,
|
471
|
+
source: :rbs)
|
383
472
|
end
|
384
473
|
|
385
474
|
rooted_tag = method_type_to_tag(type)
|
@@ -390,32 +479,51 @@ module Solargraph
|
|
390
479
|
# @param decl [RBS::AST::Members::AttrReader,RBS::AST::Members::AttrAccessor]
|
391
480
|
# @param closure [Pin::Namespace]
|
392
481
|
# @return [void]
|
393
|
-
def attr_reader_to_pin(decl, closure)
|
482
|
+
def attr_reader_to_pin(decl, closure, context)
|
483
|
+
name = decl.name.to_s
|
484
|
+
final_scope = decl.kind == :instance ? :instance : :class
|
485
|
+
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
394
486
|
pin = Solargraph::Pin::Method.new(
|
395
|
-
name:
|
487
|
+
name: name,
|
396
488
|
type_location: location_decl_to_pin_location(decl.location),
|
397
489
|
closure: closure,
|
398
490
|
comments: decl.comment&.string,
|
399
491
|
scope: :instance,
|
400
|
-
attribute: true
|
492
|
+
attribute: true,
|
493
|
+
visibility: visibility,
|
494
|
+
source: :rbs
|
401
495
|
)
|
402
496
|
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
403
497
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
|
498
|
+
logger.debug { "Conversions#attr_reader_to_pin(name=#{name.inspect}, visibility=#{visibility.inspect}) => #{pin.inspect}" }
|
404
499
|
pins.push pin
|
405
500
|
end
|
406
501
|
|
407
502
|
# @param decl [RBS::AST::Members::AttrWriter, RBS::AST::Members::AttrAccessor]
|
408
503
|
# @param closure [Pin::Namespace]
|
409
504
|
# @return [void]
|
410
|
-
def attr_writer_to_pin(decl, closure)
|
505
|
+
def attr_writer_to_pin(decl, closure, context)
|
506
|
+
final_scope = decl.kind == :instance ? :instance : :class
|
507
|
+
name = "#{decl.name.to_s}="
|
508
|
+
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
411
509
|
pin = Solargraph::Pin::Method.new(
|
412
|
-
name:
|
510
|
+
name: name,
|
413
511
|
type_location: location_decl_to_pin_location(decl.location),
|
414
512
|
closure: closure,
|
513
|
+
parameters: [],
|
415
514
|
comments: decl.comment&.string,
|
416
515
|
scope: :instance,
|
417
|
-
attribute: true
|
516
|
+
attribute: true,
|
517
|
+
visibility: visibility,
|
518
|
+
source: :rbs
|
418
519
|
)
|
520
|
+
pin.parameters <<
|
521
|
+
Solargraph::Pin::Parameter.new(
|
522
|
+
name: 'value',
|
523
|
+
return_type: ComplexType.try_parse(other_type_to_tag(decl.type)).force_rooted,
|
524
|
+
source: :rbs,
|
525
|
+
closure: pin
|
526
|
+
)
|
419
527
|
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
420
528
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
|
421
529
|
pins.push pin
|
@@ -424,9 +532,9 @@ module Solargraph
|
|
424
532
|
# @param decl [RBS::AST::Members::AttrAccessor]
|
425
533
|
# @param closure [Pin::Namespace]
|
426
534
|
# @return [void]
|
427
|
-
def attr_accessor_to_pin(decl, closure)
|
428
|
-
attr_reader_to_pin(decl, closure)
|
429
|
-
attr_writer_to_pin(decl, closure)
|
535
|
+
def attr_accessor_to_pin(decl, closure, context)
|
536
|
+
attr_reader_to_pin(decl, closure, context)
|
537
|
+
attr_writer_to_pin(decl, closure, context)
|
430
538
|
end
|
431
539
|
|
432
540
|
# @param decl [RBS::AST::Members::InstanceVariable]
|
@@ -437,7 +545,8 @@ module Solargraph
|
|
437
545
|
name: decl.name.to_s,
|
438
546
|
closure: closure,
|
439
547
|
type_location: location_decl_to_pin_location(decl.location),
|
440
|
-
comments: decl.comment&.string
|
548
|
+
comments: decl.comment&.string,
|
549
|
+
source: :rbs
|
441
550
|
)
|
442
551
|
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
443
552
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
@@ -452,7 +561,8 @@ module Solargraph
|
|
452
561
|
pin = Solargraph::Pin::ClassVariable.new(
|
453
562
|
name: name,
|
454
563
|
closure: closure,
|
455
|
-
comments: decl.comment&.string
|
564
|
+
comments: decl.comment&.string,
|
565
|
+
source: :rbs
|
456
566
|
)
|
457
567
|
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
458
568
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
@@ -467,7 +577,8 @@ module Solargraph
|
|
467
577
|
pin = Solargraph::Pin::InstanceVariable.new(
|
468
578
|
name: name,
|
469
579
|
closure: closure,
|
470
|
-
comments: decl.comment&.string
|
580
|
+
comments: decl.comment&.string,
|
581
|
+
source: :rbs
|
471
582
|
)
|
472
583
|
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
473
584
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
@@ -484,7 +595,8 @@ module Solargraph
|
|
484
595
|
name: decl.name.relative!.to_s,
|
485
596
|
type_location: location_decl_to_pin_location(decl.location),
|
486
597
|
generic_values: generic_values,
|
487
|
-
closure: closure
|
598
|
+
closure: closure,
|
599
|
+
source: :rbs
|
488
600
|
)
|
489
601
|
end
|
490
602
|
|
@@ -495,7 +607,8 @@ module Solargraph
|
|
495
607
|
pins.push Solargraph::Pin::Reference::Prepend.new(
|
496
608
|
name: decl.name.relative!.to_s,
|
497
609
|
type_location: location_decl_to_pin_location(decl.location),
|
498
|
-
closure: closure
|
610
|
+
closure: closure,
|
611
|
+
source: :rbs
|
499
612
|
)
|
500
613
|
end
|
501
614
|
|
@@ -506,7 +619,8 @@ module Solargraph
|
|
506
619
|
pins.push Solargraph::Pin::Reference::Extend.new(
|
507
620
|
name: decl.name.relative!.to_s,
|
508
621
|
type_location: location_decl_to_pin_location(decl.location),
|
509
|
-
closure: closure
|
622
|
+
closure: closure,
|
623
|
+
source: :rbs
|
510
624
|
)
|
511
625
|
end
|
512
626
|
|
@@ -518,7 +632,8 @@ module Solargraph
|
|
518
632
|
name: decl.new_name.to_s,
|
519
633
|
type_location: location_decl_to_pin_location(decl.location),
|
520
634
|
original: decl.old_name.to_s,
|
521
|
-
closure: closure
|
635
|
+
closure: closure,
|
636
|
+
source: :rbs,
|
522
637
|
)
|
523
638
|
end
|
524
639
|
|
@@ -637,7 +752,8 @@ module Solargraph
|
|
637
752
|
name: mixin.name.relative!.to_s,
|
638
753
|
type_location: location_decl_to_pin_location(mixin.location),
|
639
754
|
generic_values: generic_values,
|
640
|
-
closure: namespace
|
755
|
+
closure: namespace,
|
756
|
+
source: :rbs
|
641
757
|
)
|
642
758
|
end
|
643
759
|
end
|
@@ -13,24 +13,32 @@ module Solargraph
|
|
13
13
|
'elsif', 'end', 'ensure', 'false', 'for', 'if', 'in', 'module', 'next',
|
14
14
|
'nil', 'not', 'or', 'redo', 'rescue', 'retry', 'return', 'self', 'super',
|
15
15
|
'then', 'true', 'undef', 'unless', 'until', 'when', 'while', 'yield'
|
16
|
-
].map { |k| Pin::Keyword.new(k) }
|
16
|
+
].map { |k| Pin::Keyword.new(k, source: :core_fill) }
|
17
17
|
|
18
18
|
MISSING = [
|
19
19
|
Solargraph::Pin::Method.new(name: 'class', scope: :instance,
|
20
|
-
closure: Solargraph::Pin::Namespace.new(name: 'Object'), comments: '@return [::Class<self>]'
|
20
|
+
closure: Solargraph::Pin::Namespace.new(name: 'Object', source: :core_fill), comments: '@return [::Class<self>]',
|
21
|
+
source: :core_fill)
|
21
22
|
]
|
22
23
|
|
23
24
|
OVERRIDES = [
|
24
|
-
Override.from_comment('BasicObject#instance_eval', '@yieldreceiver [self]'
|
25
|
-
|
26
|
-
Override.from_comment('
|
27
|
-
|
28
|
-
Override.from_comment('Module#
|
29
|
-
|
30
|
-
Override.from_comment('Module#
|
25
|
+
Override.from_comment('BasicObject#instance_eval', '@yieldreceiver [self]',
|
26
|
+
source: :core_fill),
|
27
|
+
Override.from_comment('BasicObject#instance_exec', '@yieldreceiver [self]',
|
28
|
+
source: :core_fill),
|
29
|
+
Override.from_comment('Module#define_method', '@yieldreceiver [::Object<self>]',
|
30
|
+
source: :core_fill),
|
31
|
+
Override.from_comment('Module#class_eval', '@yieldreceiver [::Class<self>]',
|
32
|
+
source: :core_fill),
|
33
|
+
Override.from_comment('Module#class_exec', '@yieldreceiver [::Class<self>]',
|
34
|
+
source: :core_fill),
|
35
|
+
Override.from_comment('Module#module_eval', '@yieldreceiver [::Module<self>]',
|
36
|
+
source: :core_fill),
|
37
|
+
Override.from_comment('Module#module_exec', '@yieldreceiver [::Module<self>]',
|
38
|
+
source: :core_fill),
|
31
39
|
# RBS does not define Class with a generic, so all calls to
|
32
40
|
# generic() return an 'untyped'. We can do better:
|
33
|
-
Override.method_return('Class#allocate', 'self')
|
41
|
+
Override.method_return('Class#allocate', 'self', source: :core_fill),
|
34
42
|
]
|
35
43
|
|
36
44
|
# @todo I don't see any direct link in RBS to build this from -
|
@@ -38,16 +46,17 @@ module Solargraph
|
|
38
46
|
# against concrete classes
|
39
47
|
INCLUDES = [
|
40
48
|
Solargraph::Pin::Reference::Include.new(name: '_ToAry',
|
41
|
-
closure: Solargraph::Pin::Namespace.new(name: 'Array'),
|
42
|
-
generic_values: ['generic<Elem>']
|
49
|
+
closure: Solargraph::Pin::Namespace.new(name: 'Array', source: :core_fill),
|
50
|
+
generic_values: ['generic<Elem>'],
|
51
|
+
source: :core_fill)
|
43
52
|
]
|
44
53
|
|
45
54
|
# HACK: Add Errno exception classes
|
46
|
-
errno = Solargraph::Pin::Namespace.new(name: 'Errno')
|
55
|
+
errno = Solargraph::Pin::Namespace.new(name: 'Errno', source: :core_fill)
|
47
56
|
errnos = []
|
48
57
|
Errno.constants.each do |const|
|
49
|
-
errnos.push Solargraph::Pin::Namespace.new(type: :class, name: const.to_s, closure: errno)
|
50
|
-
errnos.push Solargraph::Pin::Reference::Superclass.new(closure: errnos.last, name: 'SystemCallError')
|
58
|
+
errnos.push Solargraph::Pin::Namespace.new(type: :class, name: const.to_s, closure: errno, source: :core_fill)
|
59
|
+
errnos.push Solargraph::Pin::Reference::Superclass.new(closure: errnos.last, name: 'SystemCallError', source: :core_fill)
|
51
60
|
end
|
52
61
|
ERRNOS = errnos
|
53
62
|
|
@@ -7,17 +7,18 @@ module Solargraph
|
|
7
7
|
class CoreMap
|
8
8
|
include Conversions
|
9
9
|
|
10
|
+
FILLS_DIRECTORY = File.join(File.dirname(__FILE__), '..', '..', '..', 'rbs', 'fills')
|
11
|
+
|
10
12
|
def initialize
|
11
13
|
cache = Cache.load('core.ser')
|
12
14
|
if cache
|
13
15
|
pins.replace cache
|
14
16
|
else
|
15
17
|
loader = RBS::EnvironmentLoader.new(repository: RBS::Repository.new(no_stdlib: false))
|
16
|
-
|
18
|
+
loader.add(path: Pathname(FILLS_DIRECTORY))
|
17
19
|
load_environment_to_pins(loader)
|
18
20
|
pins.concat RbsMap::CoreFills::ALL
|
19
21
|
processed = ApiMap::Store.new(pins).pins.reject { |p| p.is_a?(Solargraph::Pin::Reference::Override) }
|
20
|
-
processed.each { |pin| pin.source = :rbs }
|
21
22
|
pins.replace processed
|
22
23
|
|
23
24
|
Cache.save('core.ser', pins)
|
data/lib/solargraph/shell.rb
CHANGED
@@ -206,6 +206,7 @@ module Solargraph
|
|
206
206
|
# @return [void]
|
207
207
|
def scan
|
208
208
|
directory = File.realpath(options[:directory])
|
209
|
+
# @type [Solargraph::ApiMap, nil]
|
209
210
|
api_map = nil
|
210
211
|
time = Benchmark.measure {
|
211
212
|
api_map = Solargraph::ApiMap.load_with_cache(directory, $stdout)
|
@@ -20,13 +20,16 @@ module Solargraph
|
|
20
20
|
child_types = @children.map do |child|
|
21
21
|
child.infer(api_map, name_pin, locals).simplify_literals
|
22
22
|
end
|
23
|
-
|
24
|
-
|
23
|
+
type = if child_types.length == 0 || child_types.any?(&:undefined?)
|
24
|
+
ComplexType::UniqueType.new('Array', rooted: true)
|
25
|
+
elsif child_types.uniq.length == 1 && child_types.first.defined?
|
25
26
|
ComplexType::UniqueType.new('Array', [], child_types.uniq, rooted: true, parameters_type: :list)
|
27
|
+
elsif child_types.length == 0
|
28
|
+
ComplexType::UniqueType.new('Array', rooted: true, parameters_type: :list)
|
26
29
|
else
|
27
|
-
ComplexType::UniqueType.new('Array', rooted: true)
|
30
|
+
ComplexType::UniqueType.new('Array', [], child_types, rooted: true, parameters_type: :fixed)
|
28
31
|
end
|
29
|
-
[Pin::ProxyType.anonymous(type)]
|
32
|
+
[Pin::ProxyType.anonymous(type, source: :chain)]
|
30
33
|
end
|
31
34
|
end
|
32
35
|
end
|
@@ -85,6 +85,7 @@ module Solargraph
|
|
85
85
|
|
86
86
|
with_block, without_block = overloads.partition(&:block?)
|
87
87
|
sorted_overloads = with_block + without_block
|
88
|
+
# @type [Pin::Signature, nil]
|
88
89
|
new_signature_pin = nil
|
89
90
|
sorted_overloads.each do |ol|
|
90
91
|
next unless ol.arity_matches?(arguments, with_block?)
|
@@ -97,8 +98,7 @@ module Solargraph
|
|
97
98
|
match = ol.parameters.any?(&:restarg?)
|
98
99
|
break
|
99
100
|
end
|
100
|
-
|
101
|
-
atype = atypes[idx] ||= arg.infer(api_map, Pin::ProxyType.anonymous(name_pin.context), locals)
|
101
|
+
atype = atypes[idx] ||= arg.infer(api_map, Pin::ProxyType.anonymous(name_pin.context, source: :chain), locals)
|
102
102
|
unless param.compatible_arg?(atype, api_map) || param.restarg?
|
103
103
|
match = false
|
104
104
|
break
|
@@ -114,6 +114,7 @@ module Solargraph
|
|
114
114
|
blocktype = block_call_type(api_map, name_pin, locals)
|
115
115
|
end
|
116
116
|
end
|
117
|
+
# @type new_signature_pin [Pin::Signature]
|
117
118
|
new_signature_pin = ol.resolve_generics_from_context_until_complete(ol.generics, atypes, nil, nil, blocktype)
|
118
119
|
new_return_type = new_signature_pin.return_type
|
119
120
|
if head?
|
@@ -181,7 +182,7 @@ module Solargraph
|
|
181
182
|
result = inner_process_macro(pin, macro, api_map, context, locals)
|
182
183
|
return result unless result.return_type.undefined?
|
183
184
|
end
|
184
|
-
Pin::ProxyType.anonymous(ComplexType::UNDEFINED)
|
185
|
+
Pin::ProxyType.anonymous(ComplexType::UNDEFINED, source: :chain)
|
185
186
|
end
|
186
187
|
|
187
188
|
# @param pin [Pin::Method]
|
@@ -196,7 +197,7 @@ module Solargraph
|
|
196
197
|
result = inner_process_macro(pin, macro, api_map, context, locals)
|
197
198
|
return result unless result.return_type.undefined?
|
198
199
|
end
|
199
|
-
Pin::ProxyType.anonymous ComplexType::UNDEFINED
|
200
|
+
Pin::ProxyType.anonymous ComplexType::UNDEFINED, source: :chain
|
200
201
|
end
|
201
202
|
|
202
203
|
# @param pin [Pin::Base]
|
@@ -206,7 +207,7 @@ module Solargraph
|
|
206
207
|
# @param locals [::Array<Pin::LocalVariable, Pin::Parameter>]
|
207
208
|
# @return [Pin::ProxyType]
|
208
209
|
def inner_process_macro pin, macro, api_map, context, locals
|
209
|
-
vals = arguments.map{ |c| Pin::ProxyType.anonymous(c.infer(api_map, pin, locals)) }
|
210
|
+
vals = arguments.map{ |c| Pin::ProxyType.anonymous(c.infer(api_map, pin, locals), source: :chain) }
|
210
211
|
txt = macro.tag.text.clone
|
211
212
|
if txt.empty? && macro.tag.name
|
212
213
|
named = api_map.named_macro(macro.tag.name)
|
@@ -220,9 +221,9 @@ module Solargraph
|
|
220
221
|
docstring = Solargraph::Source.parse_docstring(txt).to_docstring
|
221
222
|
tag = docstring.tag(:return)
|
222
223
|
unless tag.nil? || tag.types.nil?
|
223
|
-
return Pin::ProxyType.anonymous(ComplexType.try_parse(*tag.types))
|
224
|
+
return Pin::ProxyType.anonymous(ComplexType.try_parse(*tag.types), source: :chain)
|
224
225
|
end
|
225
|
-
Pin::ProxyType.anonymous(ComplexType::UNDEFINED)
|
226
|
+
Pin::ProxyType.anonymous(ComplexType::UNDEFINED, source: :chain)
|
226
227
|
end
|
227
228
|
|
228
229
|
# @param docstring [YARD::Docstring]
|