solargraph 0.54.4 → 0.56.2
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/plugins.yml +2 -0
- data/.github/workflows/typecheck.yml +3 -1
- data/.gitignore +2 -0
- data/CHANGELOG.md +62 -0
- data/README.md +13 -3
- data/lib/solargraph/api_map/index.rb +24 -16
- data/lib/solargraph/api_map/store.rb +48 -23
- data/lib/solargraph/api_map.rb +175 -77
- data/lib/solargraph/bench.rb +17 -1
- data/lib/solargraph/complex_type/type_methods.rb +6 -1
- data/lib/solargraph/complex_type/unique_type.rb +98 -9
- data/lib/solargraph/complex_type.rb +35 -6
- data/lib/solargraph/convention/base.rb +3 -3
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +60 -0
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +89 -0
- data/lib/solargraph/convention/data_definition.rb +104 -0
- data/lib/solargraph/convention/gemspec.rb +2 -1
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +60 -0
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +100 -0
- data/lib/solargraph/convention/struct_definition.rb +141 -0
- data/lib/solargraph/convention.rb +5 -3
- data/lib/solargraph/doc_map.rb +277 -57
- data/lib/solargraph/gem_pins.rb +53 -37
- data/lib/solargraph/language_server/host/message_worker.rb +10 -7
- data/lib/solargraph/language_server/host.rb +12 -2
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +2 -0
- data/lib/solargraph/language_server/message/extended/document.rb +5 -2
- data/lib/solargraph/language_server/message/extended/document_gems.rb +3 -3
- data/lib/solargraph/library.rb +45 -17
- data/lib/solargraph/location.rb +21 -0
- data/lib/solargraph/logging.rb +1 -0
- data/lib/solargraph/parser/comment_ripper.rb +12 -6
- data/lib/solargraph/parser/flow_sensitive_typing.rb +227 -0
- data/lib/solargraph/parser/node_methods.rb +14 -0
- data/lib/solargraph/parser/node_processor/base.rb +9 -4
- data/lib/solargraph/parser/node_processor.rb +21 -8
- data/lib/solargraph/parser/parser_gem/class_methods.rb +16 -14
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +10 -10
- data/lib/solargraph/parser/parser_gem/node_methods.rb +4 -2
- data/lib/solargraph/parser/parser_gem/node_processors/alias_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +21 -0
- 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/if_node.rb +21 -0
- 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/masgn_node.rb +4 -1
- data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +8 -7
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +42 -0
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +3 -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 +3 -1
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +29 -0
- data/lib/solargraph/parser/parser_gem/node_processors.rb +14 -0
- data/lib/solargraph/parser/region.rb +1 -1
- data/lib/solargraph/parser.rb +1 -0
- data/lib/solargraph/pin/base.rb +316 -28
- data/lib/solargraph/pin/base_variable.rb +16 -9
- data/lib/solargraph/pin/block.rb +2 -0
- data/lib/solargraph/pin/breakable.rb +9 -0
- data/lib/solargraph/pin/callable.rb +74 -3
- data/lib/solargraph/pin/closure.rb +18 -1
- data/lib/solargraph/pin/common.rb +5 -0
- data/lib/solargraph/pin/delegated_method.rb +20 -1
- data/lib/solargraph/pin/documenting.rb +16 -0
- data/lib/solargraph/pin/keyword.rb +7 -2
- data/lib/solargraph/pin/local_variable.rb +15 -6
- data/lib/solargraph/pin/method.rb +169 -43
- data/lib/solargraph/pin/namespace.rb +17 -9
- data/lib/solargraph/pin/parameter.rb +60 -11
- data/lib/solargraph/pin/proxy_type.rb +12 -6
- data/lib/solargraph/pin/reference/override.rb +10 -6
- data/lib/solargraph/pin/reference/require.rb +2 -2
- data/lib/solargraph/pin/signature.rb +42 -0
- data/lib/solargraph/pin/singleton.rb +1 -1
- data/lib/solargraph/pin/symbol.rb +3 -2
- data/lib/solargraph/pin/until.rb +18 -0
- data/lib/solargraph/pin/while.rb +18 -0
- data/lib/solargraph/pin.rb +4 -1
- data/lib/solargraph/pin_cache.rb +185 -0
- data/lib/solargraph/position.rb +9 -0
- data/lib/solargraph/range.rb +9 -0
- data/lib/solargraph/rbs_map/conversions.rb +221 -67
- data/lib/solargraph/rbs_map/core_fills.rb +32 -16
- data/lib/solargraph/rbs_map/core_map.rb +34 -11
- data/lib/solargraph/rbs_map/stdlib_map.rb +15 -5
- data/lib/solargraph/rbs_map.rb +74 -17
- data/lib/solargraph/shell.rb +17 -18
- data/lib/solargraph/source/chain/array.rb +11 -7
- 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 +53 -23
- data/lib/solargraph/source/chain/constant.rb +1 -1
- data/lib/solargraph/source/chain/hash.rb +4 -3
- data/lib/solargraph/source/chain/head.rb +1 -1
- data/lib/solargraph/source/chain/if.rb +1 -1
- data/lib/solargraph/source/chain/link.rb +2 -0
- data/lib/solargraph/source/chain/literal.rb +22 -2
- data/lib/solargraph/source/chain/or.rb +1 -1
- data/lib/solargraph/source/chain/z_super.rb +1 -1
- data/lib/solargraph/source/chain.rb +78 -48
- data/lib/solargraph/source/source_chainer.rb +2 -2
- data/lib/solargraph/source_map/clip.rb +3 -1
- data/lib/solargraph/source_map/mapper.rb +9 -5
- data/lib/solargraph/source_map.rb +0 -17
- data/lib/solargraph/type_checker/checks.rb +4 -0
- data/lib/solargraph/type_checker.rb +35 -8
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/views/_method.erb +10 -10
- data/lib/solargraph/views/_namespace.erb +3 -3
- data/lib/solargraph/views/document.erb +10 -10
- data/lib/solargraph/workspace/config.rb +1 -1
- data/lib/solargraph/workspace.rb +23 -5
- data/lib/solargraph/yard_map/helpers.rb +29 -1
- data/lib/solargraph/yard_map/mapper/to_constant.rb +7 -5
- data/lib/solargraph/yard_map/mapper/to_method.rb +53 -18
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +9 -7
- data/lib/solargraph/yard_map/mapper.rb +4 -3
- data/lib/solargraph/yard_map/to_method.rb +4 -2
- data/lib/solargraph/yardoc.rb +7 -8
- data/lib/solargraph.rb +32 -1
- data/rbs/fills/tuple.rbs +150 -0
- data/rbs_collection.yaml +19 -0
- data/solargraph.gemspec +2 -1
- metadata +37 -9
- data/lib/solargraph/cache.rb +0 -77
@@ -6,7 +6,9 @@ module Solargraph
|
|
6
6
|
class RbsMap
|
7
7
|
# Functions for converting RBS declarations to Solargraph pins
|
8
8
|
#
|
9
|
-
|
9
|
+
class 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
|
@@ -20,11 +22,19 @@ module Solargraph
|
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
# @
|
24
|
-
def
|
25
|
-
@
|
25
|
+
# @param loader [RBS::EnvironmentLoader]
|
26
|
+
def initialize(loader:)
|
27
|
+
@loader = loader
|
28
|
+
@pins = []
|
29
|
+
load_environment_to_pins(loader)
|
26
30
|
end
|
27
31
|
|
32
|
+
# @return [RBS::EnvironmentLoader]
|
33
|
+
attr_reader :loader
|
34
|
+
|
35
|
+
# @return [Array<Pin::Base>]
|
36
|
+
attr_reader :pins
|
37
|
+
|
28
38
|
private
|
29
39
|
|
30
40
|
# @return [Hash{String => RBS::AST::Declarations::TypeAlias}]
|
@@ -37,9 +47,11 @@ module Solargraph
|
|
37
47
|
def load_environment_to_pins(loader)
|
38
48
|
environment = RBS::Environment.from_loader(loader).resolve_type_names
|
39
49
|
cursor = pins.length
|
50
|
+
if environment.declarations.empty?
|
51
|
+
Solargraph.logger.info "No RBS declarations found in environment for core_root #{loader.core_root.inspect}, libraries #{loader.libs} and directories #{loader.dirs}"
|
52
|
+
return
|
53
|
+
end
|
40
54
|
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
55
|
end
|
44
56
|
|
45
57
|
# @param decl [RBS::AST::Declarations::Base]
|
@@ -86,7 +98,8 @@ module Solargraph
|
|
86
98
|
name: decl.name.relative!.to_s,
|
87
99
|
type_location: location_decl_to_pin_location(decl.location),
|
88
100
|
generic_values: generic_values,
|
89
|
-
closure: closure
|
101
|
+
closure: closure,
|
102
|
+
source: :rbs
|
90
103
|
)
|
91
104
|
pins.push include_pin
|
92
105
|
end
|
@@ -95,24 +108,24 @@ module Solargraph
|
|
95
108
|
# @param closure [Pin::Namespace]
|
96
109
|
# @return [void]
|
97
110
|
def convert_members_to_pins decl, closure
|
98
|
-
context = Context.new
|
111
|
+
context = Conversions::Context.new
|
99
112
|
decl.members.each { |m| context = convert_member_to_pin(m, closure, context) }
|
100
113
|
end
|
101
114
|
|
102
115
|
# @param member [RBS::AST::Members::Base,RBS::AST::Declarations::Base]
|
103
116
|
# @param closure [Pin::Namespace]
|
104
117
|
# @param context [Context]
|
105
|
-
# @return [
|
118
|
+
# @return [Context]
|
106
119
|
def convert_member_to_pin member, closure, context
|
107
120
|
case member
|
108
121
|
when RBS::AST::Members::MethodDefinition
|
109
|
-
method_def_to_pin(member, closure)
|
122
|
+
method_def_to_pin(member, closure, context)
|
110
123
|
when RBS::AST::Members::AttrReader
|
111
|
-
attr_reader_to_pin(member, closure)
|
124
|
+
attr_reader_to_pin(member, closure, context)
|
112
125
|
when RBS::AST::Members::AttrWriter
|
113
|
-
attr_writer_to_pin(member, closure)
|
126
|
+
attr_writer_to_pin(member, closure, context)
|
114
127
|
when RBS::AST::Members::AttrAccessor
|
115
|
-
attr_accessor_to_pin(member, closure)
|
128
|
+
attr_accessor_to_pin(member, closure, context)
|
116
129
|
when RBS::AST::Members::Include
|
117
130
|
include_to_pin(member, closure)
|
118
131
|
when RBS::AST::Members::Prepend
|
@@ -128,9 +141,9 @@ module Solargraph
|
|
128
141
|
when RBS::AST::Members::InstanceVariable
|
129
142
|
ivar_to_pin(member, closure)
|
130
143
|
when RBS::AST::Members::Public
|
131
|
-
return Context.new(
|
144
|
+
return Context.new(:public)
|
132
145
|
when RBS::AST::Members::Private
|
133
|
-
return Context.new(
|
146
|
+
return Context.new(:private)
|
134
147
|
when RBS::AST::Declarations::Base
|
135
148
|
convert_decl_to_pin(member, closure)
|
136
149
|
else
|
@@ -142,6 +155,14 @@ module Solargraph
|
|
142
155
|
# @param decl [RBS::AST::Declarations::Class]
|
143
156
|
# @return [void]
|
144
157
|
def class_decl_to_pin decl
|
158
|
+
generics = decl.type_params.map(&:name).map(&:to_s)
|
159
|
+
generic_defaults = {}
|
160
|
+
decl.type_params.each do |param|
|
161
|
+
if param.default_type
|
162
|
+
tag = other_type_to_tag param.default_type
|
163
|
+
generic_defaults[param.name.to_s] = ComplexType.parse(tag).force_rooted
|
164
|
+
end
|
165
|
+
end
|
145
166
|
class_pin = Solargraph::Pin::Namespace.new(
|
146
167
|
type: :class,
|
147
168
|
name: decl.name.relative!.to_s,
|
@@ -151,14 +172,20 @@ module Solargraph
|
|
151
172
|
# @todo some type parameters in core/stdlib have default
|
152
173
|
# values; Solargraph doesn't support that yet as so these
|
153
174
|
# get treated as undefined if not specified
|
154
|
-
generics:
|
175
|
+
generics: generics,
|
176
|
+
generic_defaults: generic_defaults,
|
177
|
+
source: :rbs
|
155
178
|
)
|
156
179
|
pins.push class_pin
|
157
180
|
if decl.super_class
|
181
|
+
type = build_type(decl.super_class.name, decl.super_class.args)
|
182
|
+
generic_values = type.all_params.map(&:to_s)
|
158
183
|
pins.push Solargraph::Pin::Reference::Superclass.new(
|
159
184
|
type_location: location_decl_to_pin_location(decl.super_class.location),
|
160
185
|
closure: class_pin,
|
161
|
-
|
186
|
+
generic_values: generic_values,
|
187
|
+
name: decl.super_class.name.relative!.to_s,
|
188
|
+
source: :rbs
|
162
189
|
)
|
163
190
|
end
|
164
191
|
add_mixins decl, class_pin
|
@@ -178,7 +205,8 @@ module Solargraph
|
|
178
205
|
generics: decl.type_params.map(&:name).map(&:to_s),
|
179
206
|
# HACK: Using :hidden to keep interfaces from appearing in
|
180
207
|
# autocompletion
|
181
|
-
visibility: :hidden
|
208
|
+
visibility: :hidden,
|
209
|
+
source: :rbs
|
182
210
|
)
|
183
211
|
class_pin.docstring.add_tag(YARD::Tags::Tag.new(:abstract, '(RBS interface)'))
|
184
212
|
pins.push class_pin
|
@@ -195,6 +223,7 @@ module Solargraph
|
|
195
223
|
closure: Solargraph::Pin::ROOT_PIN,
|
196
224
|
comments: decl.comment&.string,
|
197
225
|
generics: decl.type_params.map(&:name).map(&:to_s),
|
226
|
+
source: :rbs
|
198
227
|
)
|
199
228
|
pins.push module_pin
|
200
229
|
convert_self_types_to_pins decl, module_pin
|
@@ -223,7 +252,8 @@ module Solargraph
|
|
223
252
|
name: name,
|
224
253
|
closure: closure,
|
225
254
|
type_location: location_decl_to_pin_location(decl.location),
|
226
|
-
comments: comments
|
255
|
+
comments: comments,
|
256
|
+
source: :rbs
|
227
257
|
)
|
228
258
|
tag = "#{base}<#{tag}>" if base
|
229
259
|
rooted_tag = ComplexType.parse(tag).force_rooted.rooted_tags
|
@@ -267,32 +297,101 @@ module Solargraph
|
|
267
297
|
name: name,
|
268
298
|
closure: closure,
|
269
299
|
comments: decl.comment&.string,
|
300
|
+
type_location: location_decl_to_pin_location(decl.location),
|
301
|
+
source: :rbs
|
270
302
|
)
|
271
303
|
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
272
304
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
273
305
|
pins.push pin
|
274
306
|
end
|
275
307
|
|
308
|
+
|
309
|
+
# Visibility overrides that will allow the Solargraph project
|
310
|
+
# and plugins to pass typechecking using SOLARGRAPH_ASSERTS=on,
|
311
|
+
# so that we can detect any regressions/issues elsewhere in the
|
312
|
+
# visibility logic.
|
313
|
+
#
|
314
|
+
# These should either reflect a bug upstream in the RBS
|
315
|
+
# definitions, or include a @todo indicating what needs to be
|
316
|
+
# fixed in Solargraph to properly understand it.
|
317
|
+
#
|
318
|
+
# @todo PR these fixes upstream and list open PRs here above
|
319
|
+
# related overrides
|
320
|
+
# @todo externalize remaining overrides into yaml file, then
|
321
|
+
# allow that to be extended via .solargraph.yml
|
322
|
+
# @type [Hash{Array(String, Symbol, String) => Symbol}
|
323
|
+
VISIBILITY_OVERRIDE = {
|
324
|
+
["Rails::Engine", :instance, "run_tasks_blocks"] => :protected,
|
325
|
+
# Should have been marked as both instance and class method in module -e.g., 'module_function'
|
326
|
+
["Kernel", :instance, "pretty_inspect"] => :private,
|
327
|
+
# marked incorrectly in RBS
|
328
|
+
["WEBrick::HTTPUtils::FormData", :instance, "next_data"] => :protected,
|
329
|
+
["Rails::Command", :class, "command_type"] => :private,
|
330
|
+
["Rails::Command", :class, "lookup_paths"] => :private,
|
331
|
+
["Rails::Command", :class, "file_lookup_paths"] => :private,
|
332
|
+
["Rails::Railtie", :instance, "run_console_blocks"] => :protected,
|
333
|
+
["Rails::Railtie", :instance, "run_generators_blocks"] => :protected,
|
334
|
+
["Rails::Railtie", :instance, "run_runner_blocks"] => :protected,
|
335
|
+
["Rails::Railtie", :instance, "run_tasks_blocks"] => :protected,
|
336
|
+
["ActionController::Base", :instance, "_protected_ivars"] => :private,
|
337
|
+
["ActionView::Template", :instance, "method_name"] => :public,
|
338
|
+
["Module", :instance, "ruby2_keywords"] => :private,
|
339
|
+
["Nokogiri::XML::Node", :instance, "coerce"] => :protected,
|
340
|
+
["Nokogiri::XML::Document", :class, "empty_doc?"] => :private,
|
341
|
+
["Nokogiri::Decorators::Slop", :instance, "respond_to_missing?"] => :public,
|
342
|
+
["RuboCop::Cop::RangeHelp", :instance, "source_range"] => :private,
|
343
|
+
["AST::Node", :instance, "original_dup"] => :private,
|
344
|
+
["Rainbow::Presenter", :instance, "wrap_with_sgr"] => :private,
|
345
|
+
}
|
346
|
+
|
347
|
+
# @param decl [RBS::AST::Members::MethodDefinition, RBS::AST::Members::AttrReader, RBS::AST::Members::AttrAccessor]
|
348
|
+
# @param closure [Pin::Namespace]
|
349
|
+
# @param context [Context]
|
350
|
+
# @param scope [Symbol] :instance or :class
|
351
|
+
# @param name [String] The name of the method
|
352
|
+
# @sg-ignore
|
353
|
+
# @return [Symbol]
|
354
|
+
def calculate_method_visibility(decl, context, closure, scope, name)
|
355
|
+
override_key = [closure.path, scope, name]
|
356
|
+
visibility = VISIBILITY_OVERRIDE[override_key]
|
357
|
+
simple_override_key = [closure.path, scope]
|
358
|
+
visibility ||= VISIBILITY_OVERRIDE[simple_override_key]
|
359
|
+
visibility ||= :private if closure.path == 'Kernel' && Kernel.private_instance_methods(false).include?(decl.name)
|
360
|
+
if decl.kind == :singleton_instance
|
361
|
+
# this is a 'module function'
|
362
|
+
visibility ||= :private
|
363
|
+
end
|
364
|
+
visibility ||= decl.visibility
|
365
|
+
visibility ||= context.visibility
|
366
|
+
visibility ||= :public
|
367
|
+
visibility
|
368
|
+
end
|
369
|
+
|
276
370
|
# @param decl [RBS::AST::Members::MethodDefinition]
|
277
371
|
# @param closure [Pin::Closure]
|
372
|
+
# @param context [Context]
|
278
373
|
# @return [void]
|
279
|
-
def method_def_to_pin decl, closure
|
374
|
+
def method_def_to_pin decl, closure, context
|
280
375
|
# there may be edge cases here around different signatures
|
281
376
|
# having different type params / orders - we may need to match
|
282
377
|
# this data model and have generics live in signatures to
|
283
378
|
# handle those correctly
|
284
379
|
generics = decl.overloads.map(&:method_type).flat_map(&:type_params).map(&:name).map(&:to_s).uniq
|
380
|
+
|
285
381
|
if decl.instance?
|
382
|
+
name = decl.name.to_s
|
383
|
+
final_scope = :instance
|
384
|
+
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
286
385
|
pin = Solargraph::Pin::Method.new(
|
287
|
-
name:
|
386
|
+
name: name,
|
288
387
|
closure: closure,
|
289
388
|
type_location: location_decl_to_pin_location(decl.location),
|
290
389
|
comments: decl.comment&.string,
|
291
|
-
scope:
|
390
|
+
scope: final_scope,
|
292
391
|
signatures: [],
|
293
392
|
generics: generics,
|
294
|
-
|
295
|
-
|
393
|
+
visibility: visibility,
|
394
|
+
source: :rbs
|
296
395
|
)
|
297
396
|
pin.signatures.concat method_def_to_sigs(decl, pin)
|
298
397
|
pins.push pin
|
@@ -302,14 +401,19 @@ module Solargraph
|
|
302
401
|
end
|
303
402
|
end
|
304
403
|
if decl.singleton?
|
404
|
+
final_scope = :class
|
405
|
+
name = decl.name.to_s
|
406
|
+
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
305
407
|
pin = Solargraph::Pin::Method.new(
|
306
|
-
name:
|
408
|
+
name: name,
|
307
409
|
closure: closure,
|
308
410
|
comments: decl.comment&.string,
|
309
411
|
type_location: location_decl_to_pin_location(decl.location),
|
310
|
-
|
412
|
+
visibility: visibility,
|
413
|
+
scope: final_scope,
|
311
414
|
signatures: [],
|
312
|
-
generics: generics
|
415
|
+
generics: generics,
|
416
|
+
source: :rbs
|
313
417
|
)
|
314
418
|
pin.signatures.concat method_def_to_sigs(decl, pin)
|
315
419
|
pins.push pin
|
@@ -321,13 +425,16 @@ module Solargraph
|
|
321
425
|
# @return [void]
|
322
426
|
def method_def_to_sigs decl, pin
|
323
427
|
decl.overloads.map do |overload|
|
428
|
+
type_location = location_decl_to_pin_location(overload.method_type.location)
|
324
429
|
generics = overload.method_type.type_params.map(&:name).map(&:to_s)
|
325
430
|
signature_parameters, signature_return_type = parts_of_function(overload.method_type, pin)
|
326
431
|
block = if overload.method_type.block
|
327
432
|
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
|
433
|
+
Pin::Signature.new(generics: generics, parameters: block_parameters, return_type: block_return_type, source: :rbs,
|
434
|
+
type_location: type_location, closure: pin)
|
329
435
|
end
|
330
|
-
Pin::Signature.new(generics: generics, parameters: signature_parameters, return_type: signature_return_type, block: block
|
436
|
+
Pin::Signature.new(generics: generics, parameters: signature_parameters, return_type: signature_return_type, block: block, source: :rbs,
|
437
|
+
type_location: type_location, closure: pin)
|
331
438
|
end
|
332
439
|
end
|
333
440
|
|
@@ -346,40 +453,52 @@ module Solargraph
|
|
346
453
|
# @param pin [Pin::Method]
|
347
454
|
# @return [Array(Array<Pin::Parameter>, ComplexType)]
|
348
455
|
def parts_of_function type, pin
|
349
|
-
|
456
|
+
type_location = pin.type_location
|
457
|
+
if defined?(RBS::Types::UntypedFunction) && type.type.is_a?(RBS::Types::UntypedFunction)
|
458
|
+
return [
|
459
|
+
[Solargraph::Pin::Parameter.new(decl: :restarg, name: 'arg', closure: pin, source: :rbs, type_location: type_location)],
|
460
|
+
ComplexType.try_parse(method_type_to_tag(type)).force_rooted
|
461
|
+
]
|
462
|
+
end
|
350
463
|
|
351
464
|
parameters = []
|
352
465
|
arg_num = -1
|
353
466
|
type.type.required_positionals.each do |param|
|
354
|
-
name = param.name ? param.name.to_s : "
|
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)
|
467
|
+
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
468
|
+
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, type_location: type_location)
|
356
469
|
end
|
357
470
|
type.type.optional_positionals.each do |param|
|
358
|
-
name = param.name ? param.name.to_s : "
|
471
|
+
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
359
472
|
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
|
473
|
+
return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted,
|
474
|
+
type_location: type_location,
|
475
|
+
source: :rbs)
|
361
476
|
end
|
362
477
|
if type.type.rest_positionals
|
363
|
-
name = type.type.rest_positionals.name ? type.type.rest_positionals.name.to_s : "
|
364
|
-
parameters.push Solargraph::Pin::Parameter.new(decl: :restarg, name: name, closure: pin)
|
478
|
+
name = type.type.rest_positionals.name ? type.type.rest_positionals.name.to_s : "arg_#{arg_num += 1}"
|
479
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :restarg, name: name, closure: pin, source: :rbs, type_location: type_location)
|
365
480
|
end
|
366
481
|
type.type.trailing_positionals.each do |param|
|
367
|
-
name = param.name ? param.name.to_s : "
|
368
|
-
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin)
|
482
|
+
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
483
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin, source: :rbs, type_location: type_location)
|
369
484
|
end
|
370
485
|
type.type.required_keywords.each do |orig, param|
|
371
|
-
name = orig ? orig.to_s : "
|
486
|
+
name = orig ? orig.to_s : "arg_#{arg_num += 1}"
|
372
487
|
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
|
488
|
+
return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted,
|
489
|
+
source: :rbs, type_location: type_location)
|
374
490
|
end
|
375
491
|
type.type.optional_keywords.each do |orig, param|
|
376
|
-
name = orig ? orig.to_s : "
|
492
|
+
name = orig ? orig.to_s : "arg_#{arg_num += 1}"
|
377
493
|
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
|
494
|
+
return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted,
|
495
|
+
type_location: type_location,
|
496
|
+
source: :rbs)
|
379
497
|
end
|
380
498
|
if type.type.rest_keywords
|
381
|
-
name = type.type.rest_keywords.name ? type.type.rest_keywords.name.to_s : "
|
382
|
-
parameters.push Solargraph::Pin::Parameter.new(decl: :kwrestarg, name: type.type.rest_keywords.name.to_s, closure: pin
|
499
|
+
name = type.type.rest_keywords.name ? type.type.rest_keywords.name.to_s : "arg_#{arg_num += 1}"
|
500
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :kwrestarg, name: type.type.rest_keywords.name.to_s, closure: pin,
|
501
|
+
source: :rbs, type_location: type_location)
|
383
502
|
end
|
384
503
|
|
385
504
|
rooted_tag = method_type_to_tag(type)
|
@@ -389,33 +508,56 @@ module Solargraph
|
|
389
508
|
|
390
509
|
# @param decl [RBS::AST::Members::AttrReader,RBS::AST::Members::AttrAccessor]
|
391
510
|
# @param closure [Pin::Namespace]
|
511
|
+
# @param context [Context]
|
392
512
|
# @return [void]
|
393
|
-
def attr_reader_to_pin(decl, closure)
|
513
|
+
def attr_reader_to_pin(decl, closure, context)
|
514
|
+
name = decl.name.to_s
|
515
|
+
final_scope = decl.kind == :instance ? :instance : :class
|
516
|
+
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
394
517
|
pin = Solargraph::Pin::Method.new(
|
395
|
-
name:
|
518
|
+
name: name,
|
396
519
|
type_location: location_decl_to_pin_location(decl.location),
|
397
520
|
closure: closure,
|
398
521
|
comments: decl.comment&.string,
|
399
|
-
scope:
|
400
|
-
attribute: true
|
522
|
+
scope: final_scope,
|
523
|
+
attribute: true,
|
524
|
+
visibility: visibility,
|
525
|
+
source: :rbs
|
401
526
|
)
|
402
527
|
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
403
528
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
|
529
|
+
logger.debug { "Conversions#attr_reader_to_pin(name=#{name.inspect}, visibility=#{visibility.inspect}) => #{pin.inspect}" }
|
404
530
|
pins.push pin
|
405
531
|
end
|
406
532
|
|
407
533
|
# @param decl [RBS::AST::Members::AttrWriter, RBS::AST::Members::AttrAccessor]
|
408
534
|
# @param closure [Pin::Namespace]
|
535
|
+
# @param context [Context]
|
409
536
|
# @return [void]
|
410
|
-
def attr_writer_to_pin(decl, closure)
|
537
|
+
def attr_writer_to_pin(decl, closure, context)
|
538
|
+
final_scope = decl.kind == :instance ? :instance : :class
|
539
|
+
name = "#{decl.name.to_s}="
|
540
|
+
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
541
|
+
type_location = location_decl_to_pin_location(decl.location)
|
411
542
|
pin = Solargraph::Pin::Method.new(
|
412
|
-
name:
|
413
|
-
type_location:
|
543
|
+
name: name,
|
544
|
+
type_location: type_location,
|
414
545
|
closure: closure,
|
546
|
+
parameters: [],
|
415
547
|
comments: decl.comment&.string,
|
416
|
-
scope:
|
417
|
-
attribute: true
|
548
|
+
scope: final_scope,
|
549
|
+
attribute: true,
|
550
|
+
visibility: visibility,
|
551
|
+
source: :rbs
|
418
552
|
)
|
553
|
+
pin.parameters <<
|
554
|
+
Solargraph::Pin::Parameter.new(
|
555
|
+
name: 'value',
|
556
|
+
return_type: ComplexType.try_parse(other_type_to_tag(decl.type)).force_rooted,
|
557
|
+
source: :rbs,
|
558
|
+
closure: pin,
|
559
|
+
type_location: type_location
|
560
|
+
)
|
419
561
|
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
420
562
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
|
421
563
|
pins.push pin
|
@@ -423,10 +565,11 @@ module Solargraph
|
|
423
565
|
|
424
566
|
# @param decl [RBS::AST::Members::AttrAccessor]
|
425
567
|
# @param closure [Pin::Namespace]
|
568
|
+
# @param context [Context]
|
426
569
|
# @return [void]
|
427
|
-
def attr_accessor_to_pin(decl, closure)
|
428
|
-
attr_reader_to_pin(decl, closure)
|
429
|
-
attr_writer_to_pin(decl, closure)
|
570
|
+
def attr_accessor_to_pin(decl, closure, context)
|
571
|
+
attr_reader_to_pin(decl, closure, context)
|
572
|
+
attr_writer_to_pin(decl, closure, context)
|
430
573
|
end
|
431
574
|
|
432
575
|
# @param decl [RBS::AST::Members::InstanceVariable]
|
@@ -437,7 +580,8 @@ module Solargraph
|
|
437
580
|
name: decl.name.to_s,
|
438
581
|
closure: closure,
|
439
582
|
type_location: location_decl_to_pin_location(decl.location),
|
440
|
-
comments: decl.comment&.string
|
583
|
+
comments: decl.comment&.string,
|
584
|
+
source: :rbs
|
441
585
|
)
|
442
586
|
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
443
587
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
@@ -452,7 +596,9 @@ module Solargraph
|
|
452
596
|
pin = Solargraph::Pin::ClassVariable.new(
|
453
597
|
name: name,
|
454
598
|
closure: closure,
|
455
|
-
comments: decl.comment&.string
|
599
|
+
comments: decl.comment&.string,
|
600
|
+
type_location: location_decl_to_pin_location(decl.location),
|
601
|
+
source: :rbs
|
456
602
|
)
|
457
603
|
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
458
604
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
@@ -467,7 +613,9 @@ module Solargraph
|
|
467
613
|
pin = Solargraph::Pin::InstanceVariable.new(
|
468
614
|
name: name,
|
469
615
|
closure: closure,
|
470
|
-
comments: decl.comment&.string
|
616
|
+
comments: decl.comment&.string,
|
617
|
+
type_location: location_decl_to_pin_location(decl.location),
|
618
|
+
source: :rbs
|
471
619
|
)
|
472
620
|
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
473
621
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
@@ -484,7 +632,8 @@ module Solargraph
|
|
484
632
|
name: decl.name.relative!.to_s,
|
485
633
|
type_location: location_decl_to_pin_location(decl.location),
|
486
634
|
generic_values: generic_values,
|
487
|
-
closure: closure
|
635
|
+
closure: closure,
|
636
|
+
source: :rbs
|
488
637
|
)
|
489
638
|
end
|
490
639
|
|
@@ -495,7 +644,8 @@ module Solargraph
|
|
495
644
|
pins.push Solargraph::Pin::Reference::Prepend.new(
|
496
645
|
name: decl.name.relative!.to_s,
|
497
646
|
type_location: location_decl_to_pin_location(decl.location),
|
498
|
-
closure: closure
|
647
|
+
closure: closure,
|
648
|
+
source: :rbs
|
499
649
|
)
|
500
650
|
end
|
501
651
|
|
@@ -506,7 +656,8 @@ module Solargraph
|
|
506
656
|
pins.push Solargraph::Pin::Reference::Extend.new(
|
507
657
|
name: decl.name.relative!.to_s,
|
508
658
|
type_location: location_decl_to_pin_location(decl.location),
|
509
|
-
closure: closure
|
659
|
+
closure: closure,
|
660
|
+
source: :rbs
|
510
661
|
)
|
511
662
|
end
|
512
663
|
|
@@ -514,11 +665,14 @@ module Solargraph
|
|
514
665
|
# @param closure [Pin::Namespace]
|
515
666
|
# @return [void]
|
516
667
|
def alias_to_pin decl, closure
|
668
|
+
final_scope = decl.singleton? ? :class : :instance
|
517
669
|
pins.push Solargraph::Pin::MethodAlias.new(
|
518
670
|
name: decl.new_name.to_s,
|
519
671
|
type_location: location_decl_to_pin_location(decl.location),
|
520
672
|
original: decl.old_name.to_s,
|
521
|
-
closure: closure
|
673
|
+
closure: closure,
|
674
|
+
scope: final_scope,
|
675
|
+
source: :rbs,
|
522
676
|
)
|
523
677
|
end
|
524
678
|
|
@@ -568,14 +722,13 @@ module Solargraph
|
|
568
722
|
if type.is_a?(RBS::Types::Optional)
|
569
723
|
"#{other_type_to_tag(type.type)}, nil"
|
570
724
|
elsif type.is_a?(RBS::Types::Bases::Any)
|
571
|
-
|
572
|
-
'BasicObject'
|
725
|
+
'undefined'
|
573
726
|
elsif type.is_a?(RBS::Types::Bases::Bool)
|
574
727
|
'Boolean'
|
575
728
|
elsif type.is_a?(RBS::Types::Tuple)
|
576
729
|
"Array(#{type.types.map { |t| other_type_to_tag(t) }.join(', ')})"
|
577
730
|
elsif type.is_a?(RBS::Types::Literal)
|
578
|
-
type.literal.
|
731
|
+
type.literal.inspect
|
579
732
|
elsif type.is_a?(RBS::Types::Union)
|
580
733
|
type.types.map { |t| other_type_to_tag(t) }.join(', ')
|
581
734
|
elsif type.is_a?(RBS::Types::Record)
|
@@ -637,7 +790,8 @@ module Solargraph
|
|
637
790
|
name: mixin.name.relative!.to_s,
|
638
791
|
type_location: location_decl_to_pin_location(mixin.location),
|
639
792
|
generic_values: generic_values,
|
640
|
-
closure: namespace
|
793
|
+
closure: namespace,
|
794
|
+
source: :rbs
|
641
795
|
)
|
642
796
|
end
|
643
797
|
end
|
@@ -13,38 +13,54 @@ 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
|
-
Solargraph::Pin::Method.new(name: 'tap', scope: :instance,
|
20
|
-
closure: Solargraph::Pin::Namespace.new(name: 'Object')),
|
21
19
|
Solargraph::Pin::Method.new(name: 'class', scope: :instance,
|
22
|
-
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)
|
23
22
|
]
|
24
23
|
|
25
24
|
OVERRIDES = [
|
26
|
-
Override.from_comment('BasicObject#instance_eval', '@yieldreceiver [self]'
|
27
|
-
|
28
|
-
Override.from_comment('
|
29
|
-
|
30
|
-
Override.from_comment('Module#
|
31
|
-
|
32
|
-
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),
|
33
39
|
# RBS does not define Class with a generic, so all calls to
|
34
40
|
# generic() return an 'untyped'. We can do better:
|
35
|
-
Override.method_return('Class#allocate', 'self')
|
41
|
+
Override.method_return('Class#allocate', 'self', source: :core_fill),
|
42
|
+
]
|
43
|
+
|
44
|
+
# @todo I don't see any direct link in RBS to build this from -
|
45
|
+
# presumably RBS is using duck typing to match interfaces
|
46
|
+
# against concrete classes
|
47
|
+
INCLUDES = [
|
48
|
+
Solargraph::Pin::Reference::Include.new(name: '_ToAry',
|
49
|
+
closure: Solargraph::Pin::Namespace.new(name: 'Array', source: :core_fill),
|
50
|
+
generic_values: ['generic<Elem>'],
|
51
|
+
source: :core_fill)
|
36
52
|
]
|
37
53
|
|
38
54
|
# HACK: Add Errno exception classes
|
39
|
-
errno = Solargraph::Pin::Namespace.new(name: 'Errno')
|
55
|
+
errno = Solargraph::Pin::Namespace.new(name: 'Errno', source: :core_fill)
|
40
56
|
errnos = []
|
41
57
|
Errno.constants.each do |const|
|
42
|
-
errnos.push Solargraph::Pin::Namespace.new(type: :class, name: const.to_s, closure: errno)
|
43
|
-
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)
|
44
60
|
end
|
45
61
|
ERRNOS = errnos
|
46
62
|
|
47
|
-
ALL = KEYWORDS + MISSING + OVERRIDES + ERRNOS
|
63
|
+
ALL = KEYWORDS + MISSING + OVERRIDES + ERRNOS + INCLUDES
|
48
64
|
end
|
49
65
|
end
|
50
66
|
end
|