solargraph 0.59.0.dev.1 → 0.59.0
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/linting.yml +3 -1
- data/.github/workflows/plugins.yml +12 -3
- data/.github/workflows/rspec.yml +9 -54
- data/.github/workflows/typecheck.yml +2 -1
- data/.gitignore +1 -0
- data/.rubocop.yml +38 -6
- data/.rubocop_todo.yml +40 -931
- data/CHANGELOG.md +22 -1
- data/Gemfile +3 -1
- data/Rakefile +25 -23
- data/bin/solargraph +2 -1
- data/lib/solargraph/api_map/constants.rb +0 -1
- data/lib/solargraph/api_map/index.rb +11 -11
- data/lib/solargraph/api_map/source_to_yard.rb +9 -8
- data/lib/solargraph/api_map/store.rb +28 -20
- data/lib/solargraph/api_map.rb +70 -41
- data/lib/solargraph/bench.rb +44 -45
- data/lib/solargraph/complex_type/type_methods.rb +14 -16
- data/lib/solargraph/complex_type/unique_type.rb +56 -47
- data/lib/solargraph/complex_type.rb +70 -62
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -61
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +4 -4
- data/lib/solargraph/convention/data_definition.rb +1 -1
- data/lib/solargraph/convention/gemfile.rb +15 -15
- data/lib/solargraph/convention/gemspec.rb +23 -23
- data/lib/solargraph/convention/rakefile.rb +17 -17
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +1 -1
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +3 -3
- data/lib/solargraph/convention/struct_definition.rb +3 -3
- data/lib/solargraph/convention.rb +78 -78
- data/lib/solargraph/converters/dd.rb +19 -17
- data/lib/solargraph/converters/dl.rb +17 -15
- data/lib/solargraph/converters/dt.rb +17 -15
- data/lib/solargraph/converters/misc.rb +3 -1
- data/lib/solargraph/diagnostics/rubocop.rb +10 -10
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +3 -3
- data/lib/solargraph/diagnostics/type_check.rb +10 -10
- data/lib/solargraph/diagnostics/update_errors.rb +37 -41
- data/lib/solargraph/doc_map.rb +370 -132
- data/lib/solargraph/equality.rb +3 -3
- data/lib/solargraph/gem_pins.rb +19 -18
- data/lib/solargraph/language_server/error_codes.rb +20 -20
- data/lib/solargraph/language_server/host/diagnoser.rb +89 -89
- data/lib/solargraph/language_server/host/dispatch.rb +2 -3
- data/lib/solargraph/language_server/host/message_worker.rb +2 -2
- data/lib/solargraph/language_server/host/sources.rb +1 -1
- data/lib/solargraph/language_server/host.rb +24 -21
- data/lib/solargraph/language_server/message/base.rb +97 -97
- data/lib/solargraph/language_server/message/client/register_capability.rb +13 -15
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +58 -60
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +10 -11
- data/lib/solargraph/language_server/message/extended/document_gems.rb +32 -32
- data/lib/solargraph/language_server/message/extended/download_core.rb +20 -19
- data/lib/solargraph/language_server/message/extended/search.rb +20 -20
- data/lib/solargraph/language_server/message/initialize.rb +197 -191
- data/lib/solargraph/language_server/message/text_document/completion.rb +8 -8
- data/lib/solargraph/language_server/message/text_document/definition.rb +41 -34
- data/lib/solargraph/language_server/message/text_document/document_highlight.rb +23 -16
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +29 -21
- data/lib/solargraph/language_server/message/text_document/formatting.rb +6 -6
- data/lib/solargraph/language_server/message/text_document/hover.rb +3 -5
- data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +18 -11
- data/lib/solargraph/language_server/message/text_document/references.rb +23 -16
- data/lib/solargraph/language_server/message/text_document/rename.rb +26 -19
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +2 -2
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -19
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +41 -35
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +48 -40
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +32 -26
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +27 -19
- data/lib/solargraph/language_server/message.rb +94 -94
- data/lib/solargraph/language_server/request.rb +29 -27
- data/lib/solargraph/language_server/transport/data_reader.rb +72 -74
- data/lib/solargraph/language_server/uri_helpers.rb +49 -49
- data/lib/solargraph/library.rb +68 -95
- data/lib/solargraph/location.rb +10 -12
- data/lib/solargraph/logging.rb +4 -6
- data/lib/solargraph/page.rb +92 -92
- data/lib/solargraph/parser/comment_ripper.rb +12 -4
- data/lib/solargraph/parser/flow_sensitive_typing.rb +32 -44
- data/lib/solargraph/parser/node_processor/base.rb +4 -4
- data/lib/solargraph/parser/node_processor.rb +1 -1
- data/lib/solargraph/parser/parser_gem/class_methods.rb +4 -6
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +19 -19
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +20 -20
- data/lib/solargraph/parser/parser_gem/node_methods.rb +66 -65
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +12 -12
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +1 -2
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +3 -3
- data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +38 -37
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +3 -3
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +3 -5
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +118 -112
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem.rb +14 -12
- data/lib/solargraph/parser/snippet.rb +2 -0
- data/lib/solargraph/parser.rb +25 -23
- data/lib/solargraph/pin/base.rb +76 -64
- data/lib/solargraph/pin/base_variable.rb +28 -71
- data/lib/solargraph/pin/block.rb +3 -2
- data/lib/solargraph/pin/breakable.rb +2 -0
- data/lib/solargraph/pin/callable.rb +23 -26
- data/lib/solargraph/pin/closure.rb +5 -4
- data/lib/solargraph/pin/common.rb +5 -2
- data/lib/solargraph/pin/compound_statement.rb +3 -3
- data/lib/solargraph/pin/constant.rb +43 -45
- data/lib/solargraph/pin/conversions.rb +9 -4
- data/lib/solargraph/pin/delegated_method.rb +4 -4
- data/lib/solargraph/pin/documenting.rb +3 -2
- data/lib/solargraph/pin/local_variable.rb +4 -4
- data/lib/solargraph/pin/method.rb +74 -70
- data/lib/solargraph/pin/namespace.rb +13 -12
- data/lib/solargraph/pin/parameter.rb +28 -27
- data/lib/solargraph/pin/proxy_type.rb +2 -0
- data/lib/solargraph/pin/reference/type_alias.rb +16 -0
- data/lib/solargraph/pin/reference.rb +18 -0
- data/lib/solargraph/pin/search.rb +2 -2
- data/lib/solargraph/pin/signature.rb +9 -14
- data/lib/solargraph/pin/symbol.rb +1 -0
- data/lib/solargraph/pin/until.rb +1 -3
- data/lib/solargraph/pin/while.rb +1 -3
- data/lib/solargraph/pin_cache.rb +71 -488
- data/lib/solargraph/position.rb +38 -17
- data/lib/solargraph/range.rb +10 -9
- data/lib/solargraph/rbs_map/conversions.rb +327 -221
- data/lib/solargraph/rbs_map/core_fills.rb +91 -84
- data/lib/solargraph/rbs_map/stdlib_map.rb +0 -1
- data/lib/solargraph/rbs_map.rb +5 -15
- data/lib/solargraph/server_methods.rb +16 -16
- data/lib/solargraph/shell.rb +224 -66
- data/lib/solargraph/source/chain/array.rb +39 -37
- data/lib/solargraph/source/chain/call.rb +49 -44
- data/lib/solargraph/source/chain/class_variable.rb +13 -13
- data/lib/solargraph/source/chain/constant.rb +3 -1
- data/lib/solargraph/source/chain/global_variable.rb +13 -13
- data/lib/solargraph/source/chain/hash.rb +8 -6
- data/lib/solargraph/source/chain/if.rb +11 -10
- data/lib/solargraph/source/chain/instance_variable.rb +3 -1
- data/lib/solargraph/source/chain/link.rb +99 -109
- data/lib/solargraph/source/chain/literal.rb +4 -6
- data/lib/solargraph/source/chain/or.rb +2 -4
- data/lib/solargraph/source/chain/q_call.rb +13 -11
- data/lib/solargraph/source/chain/variable.rb +15 -13
- data/lib/solargraph/source/chain/z_super.rb +28 -30
- data/lib/solargraph/source/chain.rb +26 -16
- data/lib/solargraph/source/change.rb +3 -3
- data/lib/solargraph/source/cursor.rb +18 -18
- data/lib/solargraph/source/encoding_fixes.rb +6 -7
- data/lib/solargraph/source/source_chainer.rb +46 -32
- data/lib/solargraph/source/updater.rb +1 -1
- data/lib/solargraph/source.rb +27 -29
- data/lib/solargraph/source_map/clip.rb +38 -30
- data/lib/solargraph/source_map/mapper.rb +51 -47
- data/lib/solargraph/source_map.rb +8 -4
- data/lib/solargraph/type_checker/rules.rb +8 -8
- data/lib/solargraph/type_checker.rb +95 -102
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +11 -10
- data/lib/solargraph/workspace/gemspecs.rb +3 -3
- data/lib/solargraph/workspace.rb +45 -165
- data/lib/solargraph/yard_map/helpers.rb +6 -2
- data/lib/solargraph/yard_map/mapper/to_method.rb +8 -6
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +1 -1
- data/lib/solargraph/yard_map/mapper.rb +12 -12
- data/lib/solargraph/yard_map.rb +17 -18
- data/lib/solargraph/yard_tags.rb +20 -20
- data/lib/solargraph/yardoc.rb +26 -33
- data/lib/solargraph.rb +7 -5
- data/solargraph.gemspec +36 -35
- metadata +33 -38
|
@@ -23,7 +23,7 @@ module Solargraph
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
# @param loader [RBS::EnvironmentLoader]
|
|
26
|
-
def initialize
|
|
26
|
+
def initialize loader:
|
|
27
27
|
@loader = loader
|
|
28
28
|
@pins = []
|
|
29
29
|
load_environment_to_pins(loader)
|
|
@@ -37,18 +37,15 @@ module Solargraph
|
|
|
37
37
|
|
|
38
38
|
private
|
|
39
39
|
|
|
40
|
-
# @return [Hash{String => RBS::AST::Declarations::TypeAlias}]
|
|
41
|
-
def type_aliases
|
|
42
|
-
@type_aliases ||= {}
|
|
43
|
-
end
|
|
44
|
-
|
|
45
40
|
# @param loader [RBS::EnvironmentLoader]
|
|
41
|
+
#
|
|
46
42
|
# @return [void]
|
|
47
|
-
def load_environment_to_pins
|
|
43
|
+
def load_environment_to_pins loader
|
|
48
44
|
environment = RBS::Environment.from_loader(loader).resolve_type_names
|
|
49
|
-
cursor = pins.length
|
|
50
45
|
if environment.declarations.empty?
|
|
51
|
-
Solargraph.logger.info
|
|
46
|
+
Solargraph.logger.info 'No RBS declarations found in environment for core_root ' \
|
|
47
|
+
"#{loader.core_root.inspect}, libraries #{loader.libs} and " \
|
|
48
|
+
"directories #{loader.dirs}"
|
|
52
49
|
return
|
|
53
50
|
end
|
|
54
51
|
environment.declarations.each { |decl| convert_decl_to_pin(decl, Solargraph::Pin::ROOT_PIN) }
|
|
@@ -60,22 +57,62 @@ module Solargraph
|
|
|
60
57
|
def convert_decl_to_pin decl, closure
|
|
61
58
|
case decl
|
|
62
59
|
when RBS::AST::Declarations::Class
|
|
60
|
+
# @sg-ignore flow sensitive typing should support case/when
|
|
61
|
+
unless closure.name == '' || decl.name.absolute?
|
|
62
|
+
Solargraph.assert_or_log(:rbs_closure, "Ignoring closure #{closure.inspect} on class #{decl.inspect}")
|
|
63
|
+
end
|
|
63
64
|
class_decl_to_pin decl
|
|
64
65
|
when RBS::AST::Declarations::Interface
|
|
66
|
+
# @sg-ignore flow sensitive typing should support case/when
|
|
67
|
+
unless closure.name == '' || decl.name.absolute?
|
|
68
|
+
Solargraph.assert_or_log(:rbs_closure, "Ignoring closure #{closure.inspect} on interface #{decl.inspect}")
|
|
69
|
+
end
|
|
65
70
|
# STDERR.puts "Skipping interface #{decl.name.relative!}"
|
|
66
|
-
interface_decl_to_pin decl
|
|
71
|
+
interface_decl_to_pin decl
|
|
67
72
|
when RBS::AST::Declarations::TypeAlias
|
|
68
73
|
# @sg-ignore flow sensitive typing should support case/when
|
|
69
|
-
|
|
74
|
+
unless closure.name == '' || decl.name.absolute?
|
|
75
|
+
Solargraph.assert_or_log(:rbs_closure,
|
|
76
|
+
# @sg-ignore flow sensitive typing should support case/when
|
|
77
|
+
"Ignoring closure #{closure.inspect} on alias type name #{decl.name}")
|
|
78
|
+
end
|
|
79
|
+
pins.push(
|
|
80
|
+
# @sg-ignore Wrong argument type for Solargraph::Pin::Reference::TypeAlias.new: return_type expected Solargraph::ComplexType, received Solargraph::ComplexType::UniqueType, Solargraph::ComplexType
|
|
81
|
+
Solargraph::Pin::Reference::TypeAlias.new(
|
|
82
|
+
# @sg-ignore Unresolved calls to name, type, type_location; return_type type mismatch
|
|
83
|
+
name: ComplexType.try_parse(decl.name.to_s).to_s, return_type: other_type_to_type(decl.type).force_rooted, closure: closure, source: :rbs, type_location: location_decl_to_pin_location(decl.location)
|
|
84
|
+
)
|
|
85
|
+
)
|
|
70
86
|
when RBS::AST::Declarations::Module
|
|
87
|
+
# @sg-ignore flow sensitive typing should support case/when
|
|
88
|
+
unless closure.name == '' || decl.name.absolute?
|
|
89
|
+
Solargraph.assert_or_log(:rbs_closure,
|
|
90
|
+
# @sg-ignore flow sensitive typing should support case/when
|
|
91
|
+
"Ignoring closure #{closure.inspect} on alias type name #{decl.name}")
|
|
92
|
+
end
|
|
71
93
|
module_decl_to_pin decl
|
|
72
94
|
when RBS::AST::Declarations::Constant
|
|
95
|
+
# @sg-ignore flow sensitive typing should support case/when
|
|
96
|
+
unless closure.name == '' || decl.name.absolute?
|
|
97
|
+
Solargraph.assert_or_log(:rbs_closure, "Ignoring closure #{closure.inspect} on constant #{decl.inspect}")
|
|
98
|
+
end
|
|
73
99
|
constant_decl_to_pin decl
|
|
74
100
|
when RBS::AST::Declarations::ClassAlias
|
|
101
|
+
# @sg-ignore flow sensitive typing should support case/when
|
|
102
|
+
unless closure.name == '' || decl.new_name.absolute?
|
|
103
|
+
Solargraph.assert_or_log(:rbs_closure, "Ignoring closure #{closure.inspect} on class alias #{decl.inspect}")
|
|
104
|
+
end
|
|
75
105
|
class_alias_decl_to_pin decl
|
|
76
106
|
when RBS::AST::Declarations::ModuleAlias
|
|
107
|
+
unless closure.name == ''
|
|
108
|
+
Solargraph.assert_or_log(:rbs_closure,
|
|
109
|
+
"Ignoring closure #{closure.inspect} on module alias #{decl.inspect}")
|
|
110
|
+
end
|
|
77
111
|
module_alias_decl_to_pin decl
|
|
78
112
|
when RBS::AST::Declarations::Global
|
|
113
|
+
unless closure.name == ''
|
|
114
|
+
Solargraph.assert_or_log(:rbs_closure, "Ignoring closure #{closure.inspect} on global decl #{decl.inspect}")
|
|
115
|
+
end
|
|
79
116
|
global_decl_to_pin decl
|
|
80
117
|
else
|
|
81
118
|
Solargraph.logger.warn "Skipping declaration #{decl.class}"
|
|
@@ -86,7 +123,61 @@ module Solargraph
|
|
|
86
123
|
# @param module_pin [Pin::Namespace]
|
|
87
124
|
# @return [void]
|
|
88
125
|
def convert_self_types_to_pins decl, module_pin
|
|
89
|
-
decl.self_types.each { |self_type|
|
|
126
|
+
decl.self_types.each { |self_type| convert_self_type_to_pins(self_type, module_pin) }
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# @type [Hash{String => String}]
|
|
130
|
+
RBS_TO_CLASS = {
|
|
131
|
+
'bool' => 'Boolean',
|
|
132
|
+
'string' => 'String',
|
|
133
|
+
'int' => 'Integer'
|
|
134
|
+
}.freeze
|
|
135
|
+
private_constant :RBS_TO_CLASS
|
|
136
|
+
|
|
137
|
+
# rooted names (namespaces) use the prefix of :: when they are
|
|
138
|
+
# relative to the root namespace, or not if they are relative to
|
|
139
|
+
# the current namespace.
|
|
140
|
+
#
|
|
141
|
+
# @param type_name [RBS::TypeName]
|
|
142
|
+
#
|
|
143
|
+
# @return [String]
|
|
144
|
+
def rooted_name type_name
|
|
145
|
+
name = type_name.to_s
|
|
146
|
+
RBS_TO_CLASS.fetch(name, name)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# fqns names are implicitly fully qualified - they are relative
|
|
150
|
+
# to the root namespace and are not prefixed with ::
|
|
151
|
+
#
|
|
152
|
+
# @param type_name [RBS::TypeName]
|
|
153
|
+
#
|
|
154
|
+
# @return [String]
|
|
155
|
+
def fqns type_name
|
|
156
|
+
unless type_name.absolute?
|
|
157
|
+
Solargraph.assert_or_log(:rbs_fqns, "Received unexpected unqualified type name: #{type_name}")
|
|
158
|
+
end
|
|
159
|
+
ns = type_name.relative!.to_s
|
|
160
|
+
RBS_TO_CLASS.fetch(ns, ns)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# @param type_name [RBS::TypeName]
|
|
164
|
+
# @param type_args [Enumerable<RBS::Types::Bases::Base>]
|
|
165
|
+
# @return [ComplexType::UniqueType]
|
|
166
|
+
def build_type type_name, type_args = []
|
|
167
|
+
# we use .absolute? below to tell the type object what to
|
|
168
|
+
# expect
|
|
169
|
+
rbs_name = type_name.relative!.to_s
|
|
170
|
+
base = RBS_TO_CLASS.fetch(rbs_name, rbs_name)
|
|
171
|
+
|
|
172
|
+
params = type_args.map { |a| other_type_to_type(a) }
|
|
173
|
+
# tuples have their own class and are handled in other_type_to_type
|
|
174
|
+
if base == 'Hash' && params.length == 2
|
|
175
|
+
ComplexType::UniqueType.new(base, [params.first], [params.last], rooted: type_name.absolute?,
|
|
176
|
+
parameters_type: :hash)
|
|
177
|
+
else
|
|
178
|
+
ComplexType::UniqueType.new(base, [], params.reject(&:undefined?), rooted: type_name.absolute?,
|
|
179
|
+
parameters_type: :list)
|
|
180
|
+
end
|
|
90
181
|
end
|
|
91
182
|
|
|
92
183
|
# @param decl [RBS::AST::Declarations::Module::Self]
|
|
@@ -94,9 +185,9 @@ module Solargraph
|
|
|
94
185
|
# @return [void]
|
|
95
186
|
def convert_self_type_to_pins decl, closure
|
|
96
187
|
type = build_type(decl.name, decl.args)
|
|
97
|
-
generic_values = type.all_params.map(&:
|
|
188
|
+
generic_values = type.all_params.map(&:rooted_tags)
|
|
98
189
|
include_pin = Solargraph::Pin::Reference::Include.new(
|
|
99
|
-
name: type.
|
|
190
|
+
name: type.name,
|
|
100
191
|
type_location: location_decl_to_pin_location(decl.location),
|
|
101
192
|
generic_values: generic_values,
|
|
102
193
|
closure: closure,
|
|
@@ -165,18 +256,31 @@ module Solargraph
|
|
|
165
256
|
context
|
|
166
257
|
end
|
|
167
258
|
|
|
259
|
+
# Pull the name of type variables for a generic - not the
|
|
260
|
+
# values, the names (e.g., T, U, V). As such, "rooting" isn't a
|
|
261
|
+
# thing, these are all in the global namespace.
|
|
262
|
+
#
|
|
263
|
+
# @param decl [RBS::AST::Declarations::Class, RBS::AST::Declarations::Interface,
|
|
264
|
+
# RBS::AST::Declarations::Module, RBS::MethodType]
|
|
265
|
+
#
|
|
266
|
+
# @return [Array<String>]
|
|
267
|
+
def type_parameter_names decl
|
|
268
|
+
decl.type_params.map(&:name).map(&:to_s)
|
|
269
|
+
end
|
|
270
|
+
|
|
168
271
|
# @param decl [RBS::AST::Declarations::Class]
|
|
169
272
|
# @return [void]
|
|
170
273
|
def class_decl_to_pin decl
|
|
171
|
-
|
|
274
|
+
# @type [Hash{String => ComplexType, ComplexType::UniqueType}]
|
|
172
275
|
generic_defaults = {}
|
|
173
276
|
decl.type_params.each do |param|
|
|
174
|
-
if param.default_type
|
|
175
|
-
tag = other_type_to_tag param.default_type
|
|
176
|
-
generic_defaults[param.name.to_s] = ComplexType.parse(tag).force_rooted
|
|
177
|
-
end
|
|
277
|
+
generic_defaults[param.name.to_s] = other_type_to_type param.default_type if param.default_type
|
|
178
278
|
end
|
|
179
|
-
|
|
279
|
+
|
|
280
|
+
class_name = fqns(decl.name)
|
|
281
|
+
|
|
282
|
+
generics = type_parameter_names(decl)
|
|
283
|
+
|
|
180
284
|
class_pin = Solargraph::Pin::Namespace.new(
|
|
181
285
|
type: :class,
|
|
182
286
|
name: class_name,
|
|
@@ -193,13 +297,12 @@ module Solargraph
|
|
|
193
297
|
pins.push class_pin
|
|
194
298
|
if decl.super_class
|
|
195
299
|
type = build_type(decl.super_class.name, decl.super_class.args)
|
|
196
|
-
generic_values = type.all_params.map(&:
|
|
197
|
-
superclass_name = decl.super_class.name.to_s
|
|
300
|
+
generic_values = type.all_params.map(&:rooted_tags)
|
|
198
301
|
pins.push Solargraph::Pin::Reference::Superclass.new(
|
|
199
302
|
type_location: location_decl_to_pin_location(decl.super_class.location),
|
|
200
303
|
closure: class_pin,
|
|
201
304
|
generic_values: generic_values,
|
|
202
|
-
name:
|
|
305
|
+
name: type.rooted_name, # reference pins use rooted names
|
|
203
306
|
source: :rbs
|
|
204
307
|
)
|
|
205
308
|
end
|
|
@@ -208,16 +311,15 @@ module Solargraph
|
|
|
208
311
|
end
|
|
209
312
|
|
|
210
313
|
# @param decl [RBS::AST::Declarations::Interface]
|
|
211
|
-
# @param closure [Pin::Closure]
|
|
212
314
|
# @return [void]
|
|
213
|
-
def interface_decl_to_pin decl
|
|
315
|
+
def interface_decl_to_pin decl
|
|
214
316
|
class_pin = Solargraph::Pin::Namespace.new(
|
|
215
317
|
type: :module,
|
|
216
318
|
type_location: location_decl_to_pin_location(decl.location),
|
|
217
|
-
name: decl.name
|
|
319
|
+
name: fqns(decl.name),
|
|
218
320
|
closure: Solargraph::Pin::ROOT_PIN,
|
|
219
321
|
comments: decl.comment&.string,
|
|
220
|
-
generics: decl
|
|
322
|
+
generics: type_parameter_names(decl),
|
|
221
323
|
# HACK: Using :hidden to keep interfaces from appearing in
|
|
222
324
|
# autocompletion
|
|
223
325
|
visibility: :hidden,
|
|
@@ -233,11 +335,11 @@ module Solargraph
|
|
|
233
335
|
def module_decl_to_pin decl
|
|
234
336
|
module_pin = Solargraph::Pin::Namespace.new(
|
|
235
337
|
type: :module,
|
|
236
|
-
name: decl.name
|
|
338
|
+
name: fqns(decl.name),
|
|
237
339
|
type_location: location_decl_to_pin_location(decl.location),
|
|
238
340
|
closure: Solargraph::Pin::ROOT_PIN,
|
|
239
341
|
comments: decl.comment&.string,
|
|
240
|
-
generics: decl
|
|
342
|
+
generics: type_parameter_names(decl),
|
|
241
343
|
source: :rbs
|
|
242
344
|
)
|
|
243
345
|
pins.push module_pin
|
|
@@ -249,32 +351,35 @@ module Solargraph
|
|
|
249
351
|
add_mixins decl, module_pin.closure
|
|
250
352
|
end
|
|
251
353
|
|
|
252
|
-
# @param
|
|
253
|
-
# @param
|
|
354
|
+
# @param fqns [String]
|
|
355
|
+
# @param type [ComplexType, ComplexType::UniqueType]
|
|
254
356
|
# @param comments [String, nil]
|
|
255
|
-
# @param decl [RBS::AST::Declarations::ClassAlias,
|
|
256
|
-
#
|
|
357
|
+
# @param decl [RBS::AST::Declarations::ClassAlias,
|
|
358
|
+
# RBS::AST::Declarations::Constant,
|
|
359
|
+
# RBS::AST::Declarations::ModuleAlias]
|
|
360
|
+
# @param base [String, nil] Optional conversion of tag to
|
|
361
|
+
# base<tag> - valid values are Class and Module
|
|
257
362
|
#
|
|
258
363
|
# @return [Solargraph::Pin::Constant]
|
|
259
|
-
def create_constant
|
|
260
|
-
parts =
|
|
364
|
+
def create_constant fqns, type, comments, decl, base = nil
|
|
365
|
+
parts = fqns.split('::')
|
|
261
366
|
if parts.length > 1
|
|
262
|
-
|
|
367
|
+
fqns = parts.last
|
|
263
368
|
# @sg-ignore Need to add nil check here
|
|
264
369
|
closure = pins.select { |pin| pin && pin.path == parts[0..-2].join('::') }.first
|
|
265
370
|
else
|
|
266
|
-
|
|
371
|
+
fqns = parts.first
|
|
267
372
|
closure = Solargraph::Pin::ROOT_PIN
|
|
268
373
|
end
|
|
269
374
|
constant_pin = Solargraph::Pin::Constant.new(
|
|
270
|
-
name:
|
|
375
|
+
name: fqns,
|
|
271
376
|
closure: closure,
|
|
272
377
|
type_location: location_decl_to_pin_location(decl.location),
|
|
273
378
|
comments: comments,
|
|
274
379
|
source: :rbs
|
|
275
380
|
)
|
|
276
|
-
|
|
277
|
-
rooted_tag =
|
|
381
|
+
rooted_tag = type.rooted_tags
|
|
382
|
+
rooted_tag = "#{base}<#{rooted_tag}>" if base
|
|
278
383
|
constant_pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
|
|
279
384
|
constant_pin
|
|
280
385
|
end
|
|
@@ -283,27 +388,27 @@ module Solargraph
|
|
|
283
388
|
# @return [void]
|
|
284
389
|
def class_alias_decl_to_pin decl
|
|
285
390
|
# See https://www.rubydoc.info/gems/rbs/3.4.3/RBS/AST/Declarations/ClassAlias
|
|
286
|
-
new_name = decl.new_name
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
pins.push create_constant(new_name, old_name, decl.comment&.string, decl, 'Class')
|
|
391
|
+
new_name = fqns(decl.new_name)
|
|
392
|
+
old_type = build_type(decl.old_name)
|
|
393
|
+
pins.push create_constant(new_name, old_type, decl.comment&.string, decl, '::Class')
|
|
290
394
|
end
|
|
291
395
|
|
|
292
396
|
# @param decl [RBS::AST::Declarations::ModuleAlias]
|
|
293
397
|
# @return [void]
|
|
294
398
|
def module_alias_decl_to_pin decl
|
|
295
399
|
# See https://www.rubydoc.info/gems/rbs/3.4.3/RBS/AST/Declarations/ModuleAlias
|
|
296
|
-
new_name = decl.new_name
|
|
297
|
-
|
|
400
|
+
new_name = fqns(decl.new_name)
|
|
401
|
+
old_type = build_type(decl.old_name)
|
|
298
402
|
|
|
299
|
-
pins.push create_constant(new_name,
|
|
403
|
+
pins.push create_constant(new_name, old_type, decl.comment&.string, decl, '::Module')
|
|
300
404
|
end
|
|
301
405
|
|
|
302
406
|
# @param decl [RBS::AST::Declarations::Constant]
|
|
303
407
|
# @return [void]
|
|
304
408
|
def constant_decl_to_pin decl
|
|
305
|
-
|
|
306
|
-
|
|
409
|
+
target_type = other_type_to_type(decl.type)
|
|
410
|
+
constant_name = fqns(decl.name)
|
|
411
|
+
pins.push create_constant(constant_name, target_type, decl.comment&.string, decl)
|
|
307
412
|
end
|
|
308
413
|
|
|
309
414
|
# @param decl [RBS::AST::Declarations::Global]
|
|
@@ -318,12 +423,11 @@ module Solargraph
|
|
|
318
423
|
type_location: location_decl_to_pin_location(decl.location),
|
|
319
424
|
source: :rbs
|
|
320
425
|
)
|
|
321
|
-
rooted_tag =
|
|
426
|
+
rooted_tag = other_type_to_type(decl.type).rooted_tags
|
|
322
427
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
|
323
428
|
pins.push pin
|
|
324
429
|
end
|
|
325
430
|
|
|
326
|
-
|
|
327
431
|
# Visibility overrides that will allow the Solargraph project
|
|
328
432
|
# and plugins to pass typechecking using SOLARGRAPH_ASSERTS=on,
|
|
329
433
|
# so that we can detect any regressions/issues elsewhere in the
|
|
@@ -339,41 +443,47 @@ module Solargraph
|
|
|
339
443
|
# allow that to be extended via .solargraph.yml
|
|
340
444
|
# @type [Hash{Array(String, Symbol, String) => Symbol}
|
|
341
445
|
VISIBILITY_OVERRIDE = {
|
|
342
|
-
[
|
|
446
|
+
['Rails::Engine', :instance, 'run_tasks_blocks'] => :protected,
|
|
343
447
|
# Should have been marked as both instance and class method in module -e.g., 'module_function'
|
|
344
|
-
[
|
|
448
|
+
['Kernel', :instance, 'pretty_inspect'] => :private,
|
|
345
449
|
# marked incorrectly in RBS
|
|
346
|
-
[
|
|
347
|
-
[
|
|
348
|
-
[
|
|
349
|
-
[
|
|
350
|
-
[
|
|
351
|
-
[
|
|
352
|
-
[
|
|
353
|
-
[
|
|
354
|
-
[
|
|
355
|
-
[
|
|
356
|
-
[
|
|
357
|
-
[
|
|
358
|
-
[
|
|
359
|
-
[
|
|
360
|
-
[
|
|
361
|
-
[
|
|
362
|
-
[
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
|
|
450
|
+
['WEBrick::HTTPUtils::FormData', :instance, 'next_data'] => :protected,
|
|
451
|
+
['Rails::Command', :class, 'command_type'] => :private,
|
|
452
|
+
['Rails::Command', :class, 'lookup_paths'] => :private,
|
|
453
|
+
['Rails::Command', :class, 'file_lookup_paths'] => :private,
|
|
454
|
+
['Rails::Railtie', :instance, 'run_console_blocks'] => :protected,
|
|
455
|
+
['Rails::Railtie', :instance, 'run_generators_blocks'] => :protected,
|
|
456
|
+
['Rails::Railtie', :instance, 'run_runner_blocks'] => :protected,
|
|
457
|
+
['Rails::Railtie', :instance, 'run_tasks_blocks'] => :protected,
|
|
458
|
+
['ActionController::Base', :instance, '_protected_ivars'] => :private,
|
|
459
|
+
['ActionView::Template', :instance, 'method_name'] => :public,
|
|
460
|
+
['Module', :instance, 'ruby2_keywords'] => :private,
|
|
461
|
+
['Nokogiri::XML::Node', :instance, 'coerce'] => :protected,
|
|
462
|
+
['Nokogiri::XML::Document', :class, 'empty_doc?'] => :private,
|
|
463
|
+
['Nokogiri::Decorators::Slop', :instance, 'respond_to_missing?'] => :public,
|
|
464
|
+
['RuboCop::Cop::RangeHelp', :instance, 'source_range'] => :private,
|
|
465
|
+
['AST::Node', :instance, 'original_dup'] => :private,
|
|
466
|
+
['Rainbow::Presenter', :instance, 'wrap_with_sgr'] => :private
|
|
467
|
+
}.freeze
|
|
468
|
+
private_constant :VISIBILITY_OVERRIDE
|
|
469
|
+
|
|
470
|
+
# @param decl [RBS::AST::Members::MethodDefinition, RBS::AST::Members::AttrReader,
|
|
471
|
+
# RBS::AST::Members::AttrWriter, RBS::AST::Members::AttrAccessor]
|
|
366
472
|
# @param closure [Pin::Closure]
|
|
367
473
|
# @param context [Context]
|
|
368
474
|
# @param scope [Symbol] :instance or :class
|
|
369
475
|
# @param name [String] The name of the method
|
|
370
476
|
# @return [Symbol]
|
|
371
|
-
|
|
477
|
+
# @sg-ignore Declared return type ::Symbol does not match inferred type
|
|
478
|
+
# ::Symbol, :public, :private, nil for Solargraph::RbsMap::Conversions#calculate_method_visibility
|
|
479
|
+
def calculate_method_visibility decl, context, closure, scope, name
|
|
372
480
|
override_key = [closure.path, scope, name]
|
|
373
481
|
visibility = VISIBILITY_OVERRIDE[override_key]
|
|
374
482
|
simple_override_key = [closure.path, scope]
|
|
375
483
|
visibility ||= VISIBILITY_OVERRIDE[simple_override_key]
|
|
376
|
-
|
|
484
|
+
if closure.path == 'Kernel' && Kernel.private_instance_methods(false).include?(decl.name)
|
|
485
|
+
visibility ||= :private
|
|
486
|
+
end
|
|
377
487
|
if decl.kind == :singleton_instance
|
|
378
488
|
# this is a 'module function'
|
|
379
489
|
visibility ||= :private
|
|
@@ -393,7 +503,9 @@ module Solargraph
|
|
|
393
503
|
# having different type params / orders - we may need to match
|
|
394
504
|
# this data model and have generics live in signatures to
|
|
395
505
|
# handle those correctly
|
|
396
|
-
generics = decl.overloads.map(&:method_type).
|
|
506
|
+
generics = decl.overloads.map(&:method_type).map do |method_type|
|
|
507
|
+
type_parameter_names method_type
|
|
508
|
+
end
|
|
397
509
|
|
|
398
510
|
if decl.instance?
|
|
399
511
|
name = decl.name.to_s
|
|
@@ -417,24 +529,23 @@ module Solargraph
|
|
|
417
529
|
pin.instance_variable_set(:@return_type, ComplexType::VOID)
|
|
418
530
|
end
|
|
419
531
|
end
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
end
|
|
532
|
+
return unless decl.singleton?
|
|
533
|
+
final_scope = :class
|
|
534
|
+
name = decl.name.to_s
|
|
535
|
+
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
|
536
|
+
pin = Solargraph::Pin::Method.new(
|
|
537
|
+
name: name,
|
|
538
|
+
closure: closure,
|
|
539
|
+
comments: decl.comment&.string,
|
|
540
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
541
|
+
visibility: visibility,
|
|
542
|
+
scope: final_scope,
|
|
543
|
+
signatures: [],
|
|
544
|
+
generics: generics,
|
|
545
|
+
source: :rbs
|
|
546
|
+
)
|
|
547
|
+
pin.signatures.concat method_def_to_sigs(decl, pin)
|
|
548
|
+
pins.push pin
|
|
438
549
|
end
|
|
439
550
|
|
|
440
551
|
# @param decl [RBS::AST::Members::MethodDefinition]
|
|
@@ -443,23 +554,27 @@ module Solargraph
|
|
|
443
554
|
def method_def_to_sigs decl, pin
|
|
444
555
|
# @param overload [RBS::AST::Members::MethodDefinition::Overload]
|
|
445
556
|
decl.overloads.map do |overload|
|
|
557
|
+
# @sg-ignore Wrong argument type for Solargraph::RbsMap::Conversions#location_decl_to_pin_location:
|
|
558
|
+
# location expected RBS::Location, nil, received RBS::Location<:type, :type_params>, RBS::AST::Members::Attribute::loc, nil
|
|
446
559
|
type_location = location_decl_to_pin_location(overload.method_type.location)
|
|
447
|
-
generics = overload.method_type
|
|
560
|
+
generics = type_parameter_names(overload.method_type)
|
|
448
561
|
signature_parameters, signature_return_type = parts_of_function(overload.method_type, pin)
|
|
449
562
|
rbs_block = overload.method_type.block
|
|
450
563
|
block = if rbs_block
|
|
451
564
|
block_parameters, block_return_type = parts_of_function(rbs_block, pin)
|
|
452
|
-
Pin::Signature.new(generics: generics, parameters: block_parameters,
|
|
565
|
+
Pin::Signature.new(generics: generics, parameters: block_parameters,
|
|
566
|
+
return_type: block_return_type, source: :rbs,
|
|
453
567
|
type_location: type_location, closure: pin)
|
|
454
568
|
end
|
|
455
|
-
Pin::Signature.new(generics: generics, parameters: signature_parameters,
|
|
569
|
+
Pin::Signature.new(generics: generics, parameters: signature_parameters,
|
|
570
|
+
return_type: signature_return_type, block: block, source: :rbs,
|
|
456
571
|
type_location: type_location, closure: pin)
|
|
457
572
|
end
|
|
458
573
|
end
|
|
459
574
|
|
|
460
575
|
# @param location [RBS::Location, nil]
|
|
461
576
|
# @return [Solargraph::Location, nil]
|
|
462
|
-
def location_decl_to_pin_location
|
|
577
|
+
def location_decl_to_pin_location location
|
|
463
578
|
return nil if location&.name.nil?
|
|
464
579
|
|
|
465
580
|
# @sg-ignore flow sensitive typing should handle return nil if location&.name.nil?
|
|
@@ -471,77 +586,80 @@ module Solargraph
|
|
|
471
586
|
Location.new(location.name.to_s, range)
|
|
472
587
|
end
|
|
473
588
|
|
|
474
|
-
# @param type [RBS::MethodType,RBS::Types::Block]
|
|
589
|
+
# @param type [RBS::MethodType, RBS::Types::Block]
|
|
475
590
|
# @param pin [Pin::Method]
|
|
476
591
|
# @return [Array(Array<Pin::Parameter>, ComplexType)]
|
|
477
592
|
def parts_of_function type, pin
|
|
478
593
|
type_location = pin.type_location
|
|
479
594
|
if defined?(RBS::Types::UntypedFunction) && type.type.is_a?(RBS::Types::UntypedFunction)
|
|
480
595
|
return [
|
|
481
|
-
[Solargraph::Pin::Parameter.new(decl: :restarg, name: 'arg', closure: pin, source: :rbs,
|
|
482
|
-
|
|
596
|
+
[Solargraph::Pin::Parameter.new(decl: :restarg, name: 'arg', closure: pin, source: :rbs,
|
|
597
|
+
type_location: type_location)],
|
|
598
|
+
method_type_to_type(type)
|
|
483
599
|
]
|
|
484
600
|
end
|
|
485
601
|
|
|
486
602
|
parameters = []
|
|
487
603
|
arg_num = -1
|
|
488
604
|
type.type.required_positionals.each do |param|
|
|
489
|
-
# @sg-ignore
|
|
605
|
+
# @sg-ignore Unresolved call to name
|
|
490
606
|
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
|
491
|
-
|
|
492
|
-
|
|
607
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin,
|
|
608
|
+
# @sg-ignore RBS generic type understanding issue
|
|
609
|
+
return_type: other_type_to_type(param.type),
|
|
610
|
+
source: :rbs, type_location: type_location)
|
|
493
611
|
end
|
|
494
612
|
type.type.optional_positionals.each do |param|
|
|
495
|
-
# @sg-ignore
|
|
613
|
+
# @sg-ignore Unresolved call to name
|
|
496
614
|
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
|
497
615
|
parameters.push Solargraph::Pin::Parameter.new(decl: :optarg, name: name, closure: pin,
|
|
498
616
|
# @sg-ignore RBS generic type understanding issue
|
|
499
|
-
return_type:
|
|
617
|
+
return_type: other_type_to_type(param.type),
|
|
500
618
|
type_location: type_location,
|
|
501
619
|
source: :rbs)
|
|
502
620
|
end
|
|
503
621
|
if type.type.rest_positionals
|
|
504
622
|
name = type.type.rest_positionals.name ? type.type.rest_positionals.name.to_s : "arg_#{arg_num += 1}"
|
|
505
|
-
inner_rest_positional_type =
|
|
506
|
-
ComplexType.try_parse(other_type_to_tag(type.type.rest_positionals.type))
|
|
623
|
+
inner_rest_positional_type = other_type_to_type(type.type.rest_positionals.type)
|
|
507
624
|
rest_positional_type = ComplexType::UniqueType.new('Array',
|
|
508
625
|
[],
|
|
509
626
|
[inner_rest_positional_type],
|
|
510
627
|
rooted: true, parameters_type: :list)
|
|
511
628
|
parameters.push Solargraph::Pin::Parameter.new(decl: :restarg, name: name, closure: pin,
|
|
512
629
|
source: :rbs, type_location: type_location,
|
|
513
|
-
return_type: rest_positional_type
|
|
630
|
+
return_type: rest_positional_type)
|
|
514
631
|
end
|
|
515
632
|
type.type.trailing_positionals.each do |param|
|
|
516
|
-
# @sg-ignore
|
|
633
|
+
# @sg-ignore Unresolved call to name
|
|
517
634
|
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
|
518
|
-
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin, source: :rbs,
|
|
635
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin, source: :rbs,
|
|
636
|
+
type_location: type_location)
|
|
519
637
|
end
|
|
520
638
|
type.type.required_keywords.each do |orig, param|
|
|
521
|
-
# @sg-ignore
|
|
639
|
+
# @sg-ignore Unresolved call to to_s
|
|
522
640
|
name = orig ? orig.to_s : "arg_#{arg_num += 1}"
|
|
523
641
|
parameters.push Solargraph::Pin::Parameter.new(decl: :kwarg, name: name, closure: pin,
|
|
524
642
|
# @sg-ignore RBS generic type understanding issue
|
|
525
|
-
return_type:
|
|
643
|
+
return_type: other_type_to_type(param.type),
|
|
526
644
|
source: :rbs, type_location: type_location)
|
|
527
645
|
end
|
|
528
646
|
type.type.optional_keywords.each do |orig, param|
|
|
529
|
-
# @sg-ignore
|
|
647
|
+
# @sg-ignore Unresolved call to to_s
|
|
530
648
|
name = orig ? orig.to_s : "arg_#{arg_num += 1}"
|
|
531
649
|
parameters.push Solargraph::Pin::Parameter.new(decl: :kwoptarg, name: name, closure: pin,
|
|
532
650
|
# @sg-ignore RBS generic type understanding issue
|
|
533
|
-
return_type:
|
|
651
|
+
return_type: other_type_to_type(param.type),
|
|
534
652
|
type_location: type_location,
|
|
535
653
|
source: :rbs)
|
|
536
654
|
end
|
|
537
655
|
if type.type.rest_keywords
|
|
538
656
|
name = type.type.rest_keywords.name ? type.type.rest_keywords.name.to_s : "arg_#{arg_num += 1}"
|
|
539
|
-
parameters.push Solargraph::Pin::Parameter.new(decl: :kwrestarg,
|
|
657
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :kwrestarg,
|
|
658
|
+
name: type.type.rest_keywords.name.to_s, closure: pin,
|
|
540
659
|
source: :rbs, type_location: type_location)
|
|
541
660
|
end
|
|
542
661
|
|
|
543
|
-
|
|
544
|
-
return_type = ComplexType.try_parse(rooted_tag).force_rooted
|
|
662
|
+
return_type = method_type_to_type(type)
|
|
545
663
|
[parameters, return_type]
|
|
546
664
|
end
|
|
547
665
|
|
|
@@ -549,7 +667,7 @@ module Solargraph
|
|
|
549
667
|
# @param closure [Pin::Namespace]
|
|
550
668
|
# @param context [Context]
|
|
551
669
|
# @return [void]
|
|
552
|
-
def attr_reader_to_pin
|
|
670
|
+
def attr_reader_to_pin decl, closure, context
|
|
553
671
|
name = decl.name.to_s
|
|
554
672
|
final_scope = decl.kind == :instance ? :instance : :class
|
|
555
673
|
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
|
@@ -563,9 +681,11 @@ module Solargraph
|
|
|
563
681
|
visibility: visibility,
|
|
564
682
|
source: :rbs
|
|
565
683
|
)
|
|
566
|
-
rooted_tag =
|
|
684
|
+
rooted_tag = other_type_to_type(decl.type).rooted_tags
|
|
567
685
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
|
|
568
|
-
logger.debug
|
|
686
|
+
logger.debug do
|
|
687
|
+
"Conversions#attr_reader_to_pin(name=#{name.inspect}, visibility=#{visibility.inspect}) => #{pin.inspect}"
|
|
688
|
+
end
|
|
569
689
|
pins.push pin
|
|
570
690
|
end
|
|
571
691
|
|
|
@@ -573,9 +693,9 @@ module Solargraph
|
|
|
573
693
|
# @param closure [Pin::Namespace]
|
|
574
694
|
# @param context [Context]
|
|
575
695
|
# @return [void]
|
|
576
|
-
def attr_writer_to_pin
|
|
696
|
+
def attr_writer_to_pin decl, closure, context
|
|
577
697
|
final_scope = decl.kind == :instance ? :instance : :class
|
|
578
|
-
name = "#{decl.name
|
|
698
|
+
name = "#{decl.name}="
|
|
579
699
|
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
|
580
700
|
type_location = location_decl_to_pin_location(decl.location)
|
|
581
701
|
pin = Solargraph::Pin::Method.new(
|
|
@@ -592,13 +712,13 @@ module Solargraph
|
|
|
592
712
|
pin.parameters <<
|
|
593
713
|
Solargraph::Pin::Parameter.new(
|
|
594
714
|
name: 'value',
|
|
595
|
-
return_type:
|
|
715
|
+
return_type: other_type_to_type(decl.type),
|
|
596
716
|
source: :rbs,
|
|
597
717
|
closure: pin,
|
|
598
718
|
type_location: type_location
|
|
599
719
|
)
|
|
600
|
-
|
|
601
|
-
pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '',
|
|
720
|
+
rooted_tags = other_type_to_type(decl.type).rooted_tags
|
|
721
|
+
pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tags))
|
|
602
722
|
pins.push pin
|
|
603
723
|
end
|
|
604
724
|
|
|
@@ -606,7 +726,7 @@ module Solargraph
|
|
|
606
726
|
# @param closure [Pin::Namespace]
|
|
607
727
|
# @param context [Context]
|
|
608
728
|
# @return [void]
|
|
609
|
-
def attr_accessor_to_pin
|
|
729
|
+
def attr_accessor_to_pin decl, closure, context
|
|
610
730
|
attr_reader_to_pin(decl, closure, context)
|
|
611
731
|
attr_writer_to_pin(decl, closure, context)
|
|
612
732
|
end
|
|
@@ -614,7 +734,7 @@ module Solargraph
|
|
|
614
734
|
# @param decl [RBS::AST::Members::InstanceVariable]
|
|
615
735
|
# @param closure [Pin::Namespace]
|
|
616
736
|
# @return [void]
|
|
617
|
-
def ivar_to_pin
|
|
737
|
+
def ivar_to_pin decl, closure
|
|
618
738
|
pin = Solargraph::Pin::InstanceVariable.new(
|
|
619
739
|
name: decl.name.to_s,
|
|
620
740
|
closure: closure,
|
|
@@ -622,7 +742,7 @@ module Solargraph
|
|
|
622
742
|
comments: decl.comment&.string,
|
|
623
743
|
source: :rbs
|
|
624
744
|
)
|
|
625
|
-
rooted_tag =
|
|
745
|
+
rooted_tag = other_type_to_type(decl.type).rooted_tags
|
|
626
746
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
|
627
747
|
pins.push pin
|
|
628
748
|
end
|
|
@@ -630,7 +750,7 @@ module Solargraph
|
|
|
630
750
|
# @param decl [RBS::AST::Members::ClassVariable]
|
|
631
751
|
# @param closure [Pin::Namespace]
|
|
632
752
|
# @return [void]
|
|
633
|
-
def cvar_to_pin
|
|
753
|
+
def cvar_to_pin decl, closure
|
|
634
754
|
name = decl.name.to_s
|
|
635
755
|
pin = Solargraph::Pin::ClassVariable.new(
|
|
636
756
|
name: name,
|
|
@@ -639,7 +759,7 @@ module Solargraph
|
|
|
639
759
|
type_location: location_decl_to_pin_location(decl.location),
|
|
640
760
|
source: :rbs
|
|
641
761
|
)
|
|
642
|
-
rooted_tag =
|
|
762
|
+
rooted_tag = other_type_to_type(decl.type).rooted_tags
|
|
643
763
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
|
644
764
|
pins.push pin
|
|
645
765
|
end
|
|
@@ -647,7 +767,7 @@ module Solargraph
|
|
|
647
767
|
# @param decl [RBS::AST::Members::ClassInstanceVariable]
|
|
648
768
|
# @param closure [Pin::Namespace]
|
|
649
769
|
# @return [void]
|
|
650
|
-
def civar_to_pin
|
|
770
|
+
def civar_to_pin decl, closure
|
|
651
771
|
name = decl.name.to_s
|
|
652
772
|
pin = Solargraph::Pin::InstanceVariable.new(
|
|
653
773
|
name: name,
|
|
@@ -656,7 +776,7 @@ module Solargraph
|
|
|
656
776
|
type_location: location_decl_to_pin_location(decl.location),
|
|
657
777
|
source: :rbs
|
|
658
778
|
)
|
|
659
|
-
rooted_tag =
|
|
779
|
+
rooted_tag = other_type_to_type(decl.type).rooted_tags
|
|
660
780
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
|
661
781
|
pins.push pin
|
|
662
782
|
end
|
|
@@ -666,9 +786,9 @@ module Solargraph
|
|
|
666
786
|
# @return [void]
|
|
667
787
|
def include_to_pin decl, closure
|
|
668
788
|
type = build_type(decl.name, decl.args)
|
|
669
|
-
generic_values = type.all_params.map(&:
|
|
789
|
+
generic_values = type.all_params.map(&:rooted_tags)
|
|
670
790
|
pins.push Solargraph::Pin::Reference::Include.new(
|
|
671
|
-
name:
|
|
791
|
+
name: type.rooted_name, # reference pins use rooted names
|
|
672
792
|
type_location: location_decl_to_pin_location(decl.location),
|
|
673
793
|
generic_values: generic_values,
|
|
674
794
|
closure: closure,
|
|
@@ -680,9 +800,12 @@ module Solargraph
|
|
|
680
800
|
# @param closure [Pin::Namespace]
|
|
681
801
|
# @return [void]
|
|
682
802
|
def prepend_to_pin decl, closure
|
|
803
|
+
type = build_type(decl.name, decl.args)
|
|
804
|
+
generic_values = type.all_params.map(&:rooted_tags)
|
|
683
805
|
pins.push Solargraph::Pin::Reference::Prepend.new(
|
|
684
|
-
name:
|
|
806
|
+
name: type.rooted_name, # reference pins use rooted names
|
|
685
807
|
type_location: location_decl_to_pin_location(decl.location),
|
|
808
|
+
generic_values: generic_values,
|
|
686
809
|
closure: closure,
|
|
687
810
|
source: :rbs
|
|
688
811
|
)
|
|
@@ -692,9 +815,12 @@ module Solargraph
|
|
|
692
815
|
# @param closure [Pin::Namespace]
|
|
693
816
|
# @return [void]
|
|
694
817
|
def extend_to_pin decl, closure
|
|
818
|
+
type = build_type(decl.name, decl.args)
|
|
819
|
+
generic_values = type.all_params.map(&:rooted_tags)
|
|
695
820
|
pins.push Solargraph::Pin::Reference::Extend.new(
|
|
696
|
-
name:
|
|
821
|
+
name: type.rooted_name, # reference pins use rooted names
|
|
697
822
|
type_location: location_decl_to_pin_location(decl.location),
|
|
823
|
+
generic_values: generic_values,
|
|
698
824
|
closure: closure,
|
|
699
825
|
source: :rbs
|
|
700
826
|
)
|
|
@@ -711,114 +837,94 @@ module Solargraph
|
|
|
711
837
|
original: decl.old_name.to_s,
|
|
712
838
|
closure: closure,
|
|
713
839
|
scope: final_scope,
|
|
714
|
-
source: :rbs
|
|
840
|
+
source: :rbs
|
|
715
841
|
)
|
|
716
842
|
end
|
|
717
843
|
|
|
718
|
-
RBS_TO_YARD_TYPE = {
|
|
719
|
-
'bool' => 'Boolean',
|
|
720
|
-
'string' => 'String',
|
|
721
|
-
'int' => 'Integer',
|
|
722
|
-
'untyped' => '',
|
|
723
|
-
'NilClass' => 'nil'
|
|
724
|
-
}
|
|
725
|
-
|
|
726
844
|
# @param type [RBS::MethodType, RBS::Types::Block]
|
|
727
|
-
# @return [
|
|
728
|
-
def
|
|
729
|
-
|
|
730
|
-
other_type_to_tag(type_aliases[type.type.return_type.to_s].type)
|
|
731
|
-
else
|
|
732
|
-
other_type_to_tag type.type.return_type
|
|
733
|
-
end
|
|
734
|
-
end
|
|
735
|
-
|
|
736
|
-
# @param type_name [RBS::TypeName]
|
|
737
|
-
# @param type_args [Enumerable<RBS::Types::Bases::Base>]
|
|
738
|
-
# @return [ComplexType::UniqueType]
|
|
739
|
-
def build_type(type_name, type_args = [])
|
|
740
|
-
base = RBS_TO_YARD_TYPE[type_name.relative!.to_s] || type_name.relative!.to_s
|
|
741
|
-
params = type_args.map { |a| other_type_to_tag(a) }.map do |t|
|
|
742
|
-
ComplexType.try_parse(t).force_rooted
|
|
743
|
-
end
|
|
744
|
-
if base == 'Hash' && params.length == 2
|
|
745
|
-
ComplexType::UniqueType.new(base, [params.first], [params.last], rooted: true, parameters_type: :hash)
|
|
746
|
-
else
|
|
747
|
-
ComplexType::UniqueType.new(base, [], params.reject(&:undefined?), rooted: true, parameters_type: :list)
|
|
748
|
-
end
|
|
749
|
-
end
|
|
750
|
-
|
|
751
|
-
# @param type_name [RBS::TypeName]
|
|
752
|
-
# @param type_args [Enumerable<RBS::Types::Bases::Base>]
|
|
753
|
-
# @return [String]
|
|
754
|
-
def type_tag(type_name, type_args = [])
|
|
755
|
-
build_type(type_name, type_args).tags
|
|
845
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
846
|
+
def method_type_to_type type
|
|
847
|
+
other_type_to_type type.type.return_type
|
|
756
848
|
end
|
|
757
849
|
|
|
758
850
|
# @param type [RBS::Types::Bases::Base,Object] RBS type object.
|
|
759
851
|
# Note: Generally these extend from RBS::Types::Bases::Base,
|
|
760
852
|
# but not all.
|
|
761
|
-
#
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
853
|
+
#
|
|
854
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
855
|
+
def other_type_to_type type
|
|
856
|
+
case type
|
|
857
|
+
when RBS::Types::Optional
|
|
858
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
859
|
+
ComplexType.new([other_type_to_type(type.type),
|
|
860
|
+
ComplexType::UniqueType::NIL])
|
|
861
|
+
when RBS::Types::Bases::Any
|
|
862
|
+
ComplexType::UNDEFINED
|
|
863
|
+
when RBS::Types::Bases::Bool
|
|
864
|
+
ComplexType::BOOLEAN
|
|
865
|
+
when RBS::Types::Tuple
|
|
866
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
867
|
+
tuple_types = type.types.map { |t| other_type_to_type(t) }
|
|
868
|
+
ComplexType::UniqueType.new('Array', [], tuple_types, rooted: true, parameters_type: :fixed)
|
|
869
|
+
when RBS::Types::Literal
|
|
870
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
871
|
+
ComplexType.try_parse(type.literal.inspect).force_rooted
|
|
872
|
+
when RBS::Types::Union
|
|
873
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
874
|
+
ComplexType.new(type.types.map { |t| other_type_to_type(t) })
|
|
875
|
+
when RBS::Types::Record
|
|
776
876
|
# @todo Better record support
|
|
777
|
-
'Hash'
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
877
|
+
ComplexType::UniqueType.new('Hash', rooted: true)
|
|
878
|
+
when RBS::Types::Bases::Nil
|
|
879
|
+
ComplexType::NIL
|
|
880
|
+
when RBS::Types::Bases::Self
|
|
881
|
+
ComplexType::SELF
|
|
882
|
+
when RBS::Types::Bases::Void
|
|
883
|
+
ComplexType::VOID
|
|
884
|
+
when RBS::Types::Variable
|
|
885
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
886
|
+
ComplexType.parse("generic<#{type.name}>").force_rooted
|
|
887
|
+
when RBS::Types::ClassInstance # && !type.args.empty?
|
|
888
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
889
|
+
build_type(type.name, type.args)
|
|
890
|
+
when RBS::Types::Bases::Instance
|
|
891
|
+
ComplexType::SELF
|
|
892
|
+
when RBS::Types::Bases::Top
|
|
791
893
|
# top is the most super superclass
|
|
792
|
-
'BasicObject'
|
|
793
|
-
|
|
894
|
+
ComplexType::UniqueType.new('BasicObject', rooted: true)
|
|
895
|
+
when RBS::Types::Bases::Bottom
|
|
794
896
|
# bottom is used in contexts where nothing will ever return
|
|
795
897
|
# - e.g., it could be the return type of 'exit()' or 'raise'
|
|
796
898
|
#
|
|
797
899
|
# @todo define a specific bottom type and use it to
|
|
798
900
|
# determine dead code
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
901
|
+
ComplexType::UNDEFINED
|
|
902
|
+
when RBS::Types::Intersection
|
|
903
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
904
|
+
ComplexType.new(type.types.map { |member| other_type_to_type(member) })
|
|
905
|
+
when RBS::Types::Proc
|
|
906
|
+
ComplexType::UniqueType.new('Proc', rooted: true)
|
|
907
|
+
when RBS::Types::Alias
|
|
805
908
|
# type-level alias use - e.g., 'bool' in "type bool = true | false"
|
|
806
909
|
# @todo ensure these get resolved after processing all aliases
|
|
807
910
|
# @todo handle recursive aliases
|
|
808
|
-
|
|
809
|
-
|
|
911
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
912
|
+
build_type(type.name, type.args)
|
|
913
|
+
when RBS::Types::Interface
|
|
810
914
|
# represents a mix-in module which can be considered a
|
|
811
915
|
# subtype of a consumer of it
|
|
812
|
-
|
|
813
|
-
|
|
916
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
917
|
+
build_type(type.name, type.args)
|
|
918
|
+
when RBS::Types::ClassSingleton
|
|
814
919
|
# e.g., singleton(String)
|
|
815
|
-
|
|
920
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
921
|
+
build_type(type.name)
|
|
816
922
|
else
|
|
817
923
|
# RBS doesn't provide a common base class for its type AST nodes
|
|
818
924
|
#
|
|
819
925
|
# @sg-ignore all types should include location
|
|
820
926
|
Solargraph.logger.warn "Unrecognized RBS type: #{type.class} at #{type.location}"
|
|
821
|
-
|
|
927
|
+
ComplexType::UNDEFINED
|
|
822
928
|
end
|
|
823
929
|
end
|
|
824
930
|
|
|
@@ -826,14 +932,14 @@ module Solargraph
|
|
|
826
932
|
# @param namespace [Pin::Namespace, nil]
|
|
827
933
|
# @return [void]
|
|
828
934
|
def add_mixins decl, namespace
|
|
829
|
-
# @param mixin [RBS::AST::Members::Include, RBS::AST::Members::
|
|
935
|
+
# @param mixin [RBS::AST::Members::Include, RBS::AST::Members::Extend, RBS::AST::Members::Prepend]
|
|
830
936
|
decl.each_mixin do |mixin|
|
|
831
937
|
# @todo are we handling prepend correctly?
|
|
832
938
|
klass = mixin.is_a?(RBS::AST::Members::Include) ? Pin::Reference::Include : Pin::Reference::Extend
|
|
833
939
|
type = build_type(mixin.name, mixin.args)
|
|
834
|
-
generic_values = type.all_params.map(&:
|
|
940
|
+
generic_values = type.all_params.map(&:rooted_tags)
|
|
835
941
|
pins.push klass.new(
|
|
836
|
-
name:
|
|
942
|
+
name: type.rooted_name, # reference pins use rooted names
|
|
837
943
|
type_location: location_decl_to_pin_location(mixin.location),
|
|
838
944
|
generic_values: generic_values,
|
|
839
945
|
closure: namespace,
|