solargraph 0.58.0 → 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/.envrc +3 -0
- data/.gitattributes +2 -0
- data/.github/workflows/linting.yml +6 -5
- data/.github/workflows/plugins.yml +48 -35
- data/.github/workflows/rspec.yml +15 -28
- data/.github/workflows/typecheck.yml +3 -2
- data/.gitignore +1 -0
- data/.rubocop.yml +38 -6
- data/.rubocop_todo.yml +53 -966
- data/CHANGELOG.md +24 -0
- data/Gemfile +3 -1
- data/README.md +3 -3
- data/Rakefile +26 -23
- data/bin/solargraph +9 -8
- data/lib/solargraph/api_map/cache.rb +110 -110
- data/lib/solargraph/api_map/constants.rb +288 -279
- data/lib/solargraph/api_map/index.rb +204 -193
- data/lib/solargraph/api_map/source_to_yard.rb +110 -97
- data/lib/solargraph/api_map/store.rb +395 -384
- data/lib/solargraph/api_map.rb +1029 -945
- data/lib/solargraph/bench.rb +44 -45
- data/lib/solargraph/complex_type/conformance.rb +176 -0
- data/lib/solargraph/complex_type/type_methods.rb +240 -228
- data/lib/solargraph/complex_type/unique_type.rb +641 -482
- data/lib/solargraph/complex_type.rb +557 -444
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -61
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +93 -91
- data/lib/solargraph/convention/data_definition.rb +108 -105
- data/lib/solargraph/convention/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 +62 -61
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +103 -102
- data/lib/solargraph/convention/struct_definition.rb +168 -164
- data/lib/solargraph/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/require_not_found.rb +54 -53
- data/lib/solargraph/diagnostics/rubocop.rb +119 -118
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +70 -68
- data/lib/solargraph/diagnostics/type_check.rb +56 -55
- data/lib/solargraph/diagnostics/update_errors.rb +37 -41
- data/lib/solargraph/doc_map.rb +438 -439
- data/lib/solargraph/equality.rb +34 -34
- data/lib/solargraph/gem_pins.rb +98 -98
- 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 +130 -130
- data/lib/solargraph/language_server/host/message_worker.rb +113 -112
- data/lib/solargraph/language_server/host/sources.rb +100 -99
- data/lib/solargraph/language_server/host.rb +886 -878
- 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 +108 -114
- data/lib/solargraph/language_server/message/extended/document.rb +24 -23
- 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 +58 -56
- data/lib/solargraph/language_server/message/text_document/definition.rb +49 -40
- data/lib/solargraph/language_server/message/text_document/document_highlight.rb +23 -16
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +36 -26
- data/lib/solargraph/language_server/message/text_document/formatting.rb +150 -148
- data/lib/solargraph/language_server/message/text_document/hover.rb +58 -58
- 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 +25 -24
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +33 -25
- 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 +33 -23
- 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 +702 -683
- data/lib/solargraph/location.rb +85 -82
- data/lib/solargraph/logging.rb +55 -37
- data/lib/solargraph/page.rb +92 -92
- data/lib/solargraph/parser/comment_ripper.rb +84 -69
- data/lib/solargraph/parser/flow_sensitive_typing.rb +471 -255
- data/lib/solargraph/parser/node_processor/base.rb +122 -92
- data/lib/solargraph/parser/node_processor.rb +63 -62
- data/lib/solargraph/parser/parser_gem/class_methods.rb +165 -149
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +19 -19
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +191 -166
- data/lib/solargraph/parser/parser_gem/node_methods.rb +507 -486
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +22 -22
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +61 -59
- data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +24 -15
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +45 -46
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +60 -53
- data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +38 -37
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +53 -23
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +42 -40
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +30 -29
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +61 -59
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +98 -98
- data/lib/solargraph/parser/parser_gem/node_processors/or_node.rb +22 -0
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +17 -17
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +39 -38
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +51 -52
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +302 -291
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +23 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +33 -29
- data/lib/solargraph/parser/parser_gem/node_processors.rb +74 -70
- data/lib/solargraph/parser/parser_gem.rb +14 -12
- data/lib/solargraph/parser/region.rb +75 -69
- data/lib/solargraph/parser/snippet.rb +19 -17
- data/lib/solargraph/parser.rb +25 -23
- data/lib/solargraph/pin/base.rb +773 -729
- data/lib/solargraph/pin/base_variable.rb +375 -126
- data/lib/solargraph/pin/block.rb +127 -104
- data/lib/solargraph/pin/breakable.rb +15 -9
- data/lib/solargraph/pin/callable.rb +275 -231
- data/lib/solargraph/pin/closure.rb +69 -72
- data/lib/solargraph/pin/common.rb +97 -79
- data/lib/solargraph/pin/compound_statement.rb +55 -0
- data/lib/solargraph/pin/constant.rb +43 -45
- data/lib/solargraph/pin/conversions.rb +129 -123
- data/lib/solargraph/pin/delegated_method.rb +131 -120
- data/lib/solargraph/pin/documenting.rb +116 -114
- data/lib/solargraph/pin/instance_variable.rb +38 -34
- data/lib/solargraph/pin/keyword.rb +16 -20
- data/lib/solargraph/pin/local_variable.rb +31 -75
- data/lib/solargraph/pin/method.rb +724 -672
- data/lib/solargraph/pin/method_alias.rb +42 -34
- data/lib/solargraph/pin/namespace.rb +122 -115
- data/lib/solargraph/pin/parameter.rb +339 -275
- data/lib/solargraph/pin/proxy_type.rb +42 -39
- data/lib/solargraph/pin/reference/override.rb +47 -47
- data/lib/solargraph/pin/reference/superclass.rb +17 -15
- data/lib/solargraph/pin/reference/type_alias.rb +16 -0
- data/lib/solargraph/pin/reference.rb +59 -39
- data/lib/solargraph/pin/search.rb +62 -61
- data/lib/solargraph/pin/signature.rb +64 -61
- data/lib/solargraph/pin/symbol.rb +54 -53
- data/lib/solargraph/pin/until.rb +16 -18
- data/lib/solargraph/pin/while.rb +16 -18
- data/lib/solargraph/pin.rb +46 -44
- data/lib/solargraph/pin_cache.rb +248 -245
- data/lib/solargraph/position.rb +139 -119
- data/lib/solargraph/range.rb +113 -112
- data/lib/solargraph/rbs_map/conversions.rb +952 -823
- data/lib/solargraph/rbs_map/core_fills.rb +91 -84
- data/lib/solargraph/rbs_map/core_map.rb +65 -58
- data/lib/solargraph/rbs_map/stdlib_map.rb +71 -43
- data/lib/solargraph/rbs_map.rb +207 -163
- data/lib/solargraph/server_methods.rb +16 -16
- data/lib/solargraph/shell.rb +555 -352
- data/lib/solargraph/source/chain/array.rb +39 -37
- data/lib/solargraph/source/chain/call.rb +377 -337
- data/lib/solargraph/source/chain/class_variable.rb +13 -13
- data/lib/solargraph/source/chain/constant.rb +30 -26
- data/lib/solargraph/source/chain/global_variable.rb +13 -13
- data/lib/solargraph/source/chain/hash.rb +37 -34
- data/lib/solargraph/source/chain/if.rb +30 -28
- data/lib/solargraph/source/chain/instance_variable.rb +36 -13
- data/lib/solargraph/source/chain/link.rb +99 -109
- data/lib/solargraph/source/chain/literal.rb +51 -48
- data/lib/solargraph/source/chain/or.rb +29 -23
- 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 +304 -291
- data/lib/solargraph/source/change.rb +89 -82
- data/lib/solargraph/source/cursor.rb +172 -166
- data/lib/solargraph/source/encoding_fixes.rb +22 -23
- data/lib/solargraph/source/source_chainer.rb +218 -194
- data/lib/solargraph/source/updater.rb +59 -55
- data/lib/solargraph/source.rb +522 -498
- data/lib/solargraph/source_map/clip.rb +245 -226
- data/lib/solargraph/source_map/data.rb +37 -34
- data/lib/solargraph/source_map/mapper.rb +286 -259
- data/lib/solargraph/source_map.rb +224 -212
- data/lib/solargraph/type_checker/problem.rb +34 -32
- data/lib/solargraph/type_checker/rules.rb +157 -84
- data/lib/solargraph/type_checker.rb +888 -814
- data/lib/solargraph/version.rb +5 -5
- data/lib/solargraph/workspace/config.rb +258 -255
- data/lib/solargraph/workspace/gemspecs.rb +367 -0
- data/lib/solargraph/workspace/require_paths.rb +98 -97
- data/lib/solargraph/workspace.rb +242 -220
- data/lib/solargraph/yard_map/helpers.rb +49 -44
- data/lib/solargraph/yard_map/mapper/to_method.rb +136 -130
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +32 -31
- data/lib/solargraph/yard_map/mapper.rb +84 -79
- data/lib/solargraph/yard_map.rb +17 -18
- data/lib/solargraph/yard_tags.rb +20 -20
- data/lib/solargraph/yardoc.rb +90 -87
- data/lib/solargraph.rb +128 -105
- data/rbs/fills/rubygems/0/dependency.rbs +193 -0
- data/rbs/fills/tuple/tuple.rbs +28 -0
- data/rbs/shims/ast/0/node.rbs +5 -0
- data/rbs/shims/diff-lcs/1.5/diff-lcs.rbs +11 -0
- data/rbs_collection.yaml +1 -1
- data/solargraph.gemspec +37 -35
- metadata +52 -51
- data/lib/solargraph/type_checker/checks.rb +0 -124
- data/lib/solargraph/type_checker/param_def.rb +0 -37
- data/lib/solargraph/yard_map/to_method.rb +0 -89
- data/sig/shims/ast/0/node.rbs +0 -5
- /data/{sig → rbs}/shims/ast/2.4/.rbs_meta.yaml +0 -0
- /data/{sig → rbs}/shims/ast/2.4/ast.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/builders/default.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/manifest.yaml +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/parser.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/polyfill.rbs +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/.rbs_meta.yaml +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/manifest.yaml +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/thor.rbs +0 -0
|
@@ -1,823 +1,952 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'rbs'
|
|
4
|
-
|
|
5
|
-
module Solargraph
|
|
6
|
-
class RbsMap
|
|
7
|
-
# Functions for converting RBS declarations to Solargraph pins
|
|
8
|
-
#
|
|
9
|
-
class Conversions
|
|
10
|
-
include Logging
|
|
11
|
-
|
|
12
|
-
# A container for tracking the current context of the RBS conversion
|
|
13
|
-
# process, e.g., what visibility is declared for methods in the current
|
|
14
|
-
# scope
|
|
15
|
-
#
|
|
16
|
-
class Context
|
|
17
|
-
attr_reader :visibility
|
|
18
|
-
|
|
19
|
-
# @param visibility [Symbol]
|
|
20
|
-
def initialize visibility = :public
|
|
21
|
-
@visibility = visibility
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# @param loader [RBS::EnvironmentLoader]
|
|
26
|
-
def initialize
|
|
27
|
-
@loader = loader
|
|
28
|
-
@pins = []
|
|
29
|
-
load_environment_to_pins(loader)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# @return [RBS::EnvironmentLoader]
|
|
33
|
-
attr_reader :loader
|
|
34
|
-
|
|
35
|
-
# @return [Array<Pin::Base>]
|
|
36
|
-
attr_reader :pins
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
|
|
40
|
-
# @
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
when RBS::AST::Declarations::
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
closure
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
# @param
|
|
200
|
-
# @
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
closure
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
#
|
|
314
|
-
#
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
# @param
|
|
355
|
-
# @
|
|
356
|
-
# @
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
type_location: location_decl_to_pin_location(decl.location),
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
)
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
# @param
|
|
590
|
-
# @
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
name: name,
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
# @param
|
|
735
|
-
# @
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
#
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rbs'
|
|
4
|
+
|
|
5
|
+
module Solargraph
|
|
6
|
+
class RbsMap
|
|
7
|
+
# Functions for converting RBS declarations to Solargraph pins
|
|
8
|
+
#
|
|
9
|
+
class Conversions
|
|
10
|
+
include Logging
|
|
11
|
+
|
|
12
|
+
# A container for tracking the current context of the RBS conversion
|
|
13
|
+
# process, e.g., what visibility is declared for methods in the current
|
|
14
|
+
# scope
|
|
15
|
+
#
|
|
16
|
+
class Context
|
|
17
|
+
attr_reader :visibility
|
|
18
|
+
|
|
19
|
+
# @param visibility [Symbol]
|
|
20
|
+
def initialize visibility = :public
|
|
21
|
+
@visibility = visibility
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# @param loader [RBS::EnvironmentLoader]
|
|
26
|
+
def initialize loader:
|
|
27
|
+
@loader = loader
|
|
28
|
+
@pins = []
|
|
29
|
+
load_environment_to_pins(loader)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# @return [RBS::EnvironmentLoader]
|
|
33
|
+
attr_reader :loader
|
|
34
|
+
|
|
35
|
+
# @return [Array<Pin::Base>]
|
|
36
|
+
attr_reader :pins
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
# @param loader [RBS::EnvironmentLoader]
|
|
41
|
+
#
|
|
42
|
+
# @return [void]
|
|
43
|
+
def load_environment_to_pins loader
|
|
44
|
+
environment = RBS::Environment.from_loader(loader).resolve_type_names
|
|
45
|
+
if environment.declarations.empty?
|
|
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}"
|
|
49
|
+
return
|
|
50
|
+
end
|
|
51
|
+
environment.declarations.each { |decl| convert_decl_to_pin(decl, Solargraph::Pin::ROOT_PIN) }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# @param decl [RBS::AST::Declarations::Base]
|
|
55
|
+
# @param closure [Pin::Closure]
|
|
56
|
+
# @return [void]
|
|
57
|
+
def convert_decl_to_pin decl, closure
|
|
58
|
+
case decl
|
|
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
|
|
64
|
+
class_decl_to_pin decl
|
|
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
|
|
70
|
+
# STDERR.puts "Skipping interface #{decl.name.relative!}"
|
|
71
|
+
interface_decl_to_pin decl
|
|
72
|
+
when RBS::AST::Declarations::TypeAlias
|
|
73
|
+
# @sg-ignore flow sensitive typing should support case/when
|
|
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
|
+
)
|
|
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
|
|
93
|
+
module_decl_to_pin decl
|
|
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
|
|
99
|
+
constant_decl_to_pin decl
|
|
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
|
|
105
|
+
class_alias_decl_to_pin decl
|
|
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
|
|
111
|
+
module_alias_decl_to_pin decl
|
|
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
|
|
116
|
+
global_decl_to_pin decl
|
|
117
|
+
else
|
|
118
|
+
Solargraph.logger.warn "Skipping declaration #{decl.class}"
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# @param decl [RBS::AST::Declarations::Module]
|
|
123
|
+
# @param module_pin [Pin::Namespace]
|
|
124
|
+
# @return [void]
|
|
125
|
+
def convert_self_types_to_pins decl, module_pin
|
|
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
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# @param decl [RBS::AST::Declarations::Module::Self]
|
|
184
|
+
# @param closure [Pin::Namespace]
|
|
185
|
+
# @return [void]
|
|
186
|
+
def convert_self_type_to_pins decl, closure
|
|
187
|
+
type = build_type(decl.name, decl.args)
|
|
188
|
+
generic_values = type.all_params.map(&:rooted_tags)
|
|
189
|
+
include_pin = Solargraph::Pin::Reference::Include.new(
|
|
190
|
+
name: type.name,
|
|
191
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
192
|
+
generic_values: generic_values,
|
|
193
|
+
closure: closure,
|
|
194
|
+
source: :rbs
|
|
195
|
+
)
|
|
196
|
+
pins.push include_pin
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# @param decl [RBS::AST::Declarations::Module,RBS::AST::Declarations::Class,RBS::AST::Declarations::Interface]
|
|
200
|
+
# @param closure [Pin::Namespace]
|
|
201
|
+
# @return [void]
|
|
202
|
+
def convert_members_to_pins decl, closure
|
|
203
|
+
context = Conversions::Context.new
|
|
204
|
+
decl.members.each { |m| context = convert_member_to_pin(m, closure, context) }
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
# @param member [RBS::AST::Members::Base,RBS::AST::Declarations::Base]
|
|
208
|
+
# @param closure [Pin::Namespace]
|
|
209
|
+
# @param context [Context]
|
|
210
|
+
# @return [Context]
|
|
211
|
+
def convert_member_to_pin member, closure, context
|
|
212
|
+
case member
|
|
213
|
+
when RBS::AST::Members::MethodDefinition
|
|
214
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
215
|
+
method_def_to_pin(member, closure, context)
|
|
216
|
+
when RBS::AST::Members::AttrReader
|
|
217
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
218
|
+
attr_reader_to_pin(member, closure, context)
|
|
219
|
+
when RBS::AST::Members::AttrWriter
|
|
220
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
221
|
+
attr_writer_to_pin(member, closure, context)
|
|
222
|
+
when RBS::AST::Members::AttrAccessor
|
|
223
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
224
|
+
attr_accessor_to_pin(member, closure, context)
|
|
225
|
+
when RBS::AST::Members::Include
|
|
226
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
227
|
+
include_to_pin(member, closure)
|
|
228
|
+
when RBS::AST::Members::Prepend
|
|
229
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
230
|
+
prepend_to_pin(member, closure)
|
|
231
|
+
when RBS::AST::Members::Extend
|
|
232
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
233
|
+
extend_to_pin(member, closure)
|
|
234
|
+
when RBS::AST::Members::Alias
|
|
235
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
236
|
+
alias_to_pin(member, closure)
|
|
237
|
+
when RBS::AST::Members::ClassInstanceVariable
|
|
238
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
239
|
+
civar_to_pin(member, closure)
|
|
240
|
+
when RBS::AST::Members::ClassVariable
|
|
241
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
242
|
+
cvar_to_pin(member, closure)
|
|
243
|
+
when RBS::AST::Members::InstanceVariable
|
|
244
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
245
|
+
ivar_to_pin(member, closure)
|
|
246
|
+
when RBS::AST::Members::Public
|
|
247
|
+
return Context.new(:public)
|
|
248
|
+
when RBS::AST::Members::Private
|
|
249
|
+
return Context.new(:private)
|
|
250
|
+
when RBS::AST::Declarations::Base
|
|
251
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
252
|
+
convert_decl_to_pin(member, closure)
|
|
253
|
+
else
|
|
254
|
+
Solargraph.logger.warn "Skipping member type #{member.class}"
|
|
255
|
+
end
|
|
256
|
+
context
|
|
257
|
+
end
|
|
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
|
+
|
|
271
|
+
# @param decl [RBS::AST::Declarations::Class]
|
|
272
|
+
# @return [void]
|
|
273
|
+
def class_decl_to_pin decl
|
|
274
|
+
# @type [Hash{String => ComplexType, ComplexType::UniqueType}]
|
|
275
|
+
generic_defaults = {}
|
|
276
|
+
decl.type_params.each do |param|
|
|
277
|
+
generic_defaults[param.name.to_s] = other_type_to_type param.default_type if param.default_type
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
class_name = fqns(decl.name)
|
|
281
|
+
|
|
282
|
+
generics = type_parameter_names(decl)
|
|
283
|
+
|
|
284
|
+
class_pin = Solargraph::Pin::Namespace.new(
|
|
285
|
+
type: :class,
|
|
286
|
+
name: class_name,
|
|
287
|
+
closure: Solargraph::Pin::ROOT_PIN,
|
|
288
|
+
comments: decl.comment&.string,
|
|
289
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
290
|
+
# @todo some type parameters in core/stdlib have default
|
|
291
|
+
# values; Solargraph doesn't support that yet as so these
|
|
292
|
+
# get treated as undefined if not specified
|
|
293
|
+
generics: generics,
|
|
294
|
+
generic_defaults: generic_defaults,
|
|
295
|
+
source: :rbs
|
|
296
|
+
)
|
|
297
|
+
pins.push class_pin
|
|
298
|
+
if decl.super_class
|
|
299
|
+
type = build_type(decl.super_class.name, decl.super_class.args)
|
|
300
|
+
generic_values = type.all_params.map(&:rooted_tags)
|
|
301
|
+
pins.push Solargraph::Pin::Reference::Superclass.new(
|
|
302
|
+
type_location: location_decl_to_pin_location(decl.super_class.location),
|
|
303
|
+
closure: class_pin,
|
|
304
|
+
generic_values: generic_values,
|
|
305
|
+
name: type.rooted_name, # reference pins use rooted names
|
|
306
|
+
source: :rbs
|
|
307
|
+
)
|
|
308
|
+
end
|
|
309
|
+
add_mixins decl, class_pin
|
|
310
|
+
convert_members_to_pins decl, class_pin
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
# @param decl [RBS::AST::Declarations::Interface]
|
|
314
|
+
# @return [void]
|
|
315
|
+
def interface_decl_to_pin decl
|
|
316
|
+
class_pin = Solargraph::Pin::Namespace.new(
|
|
317
|
+
type: :module,
|
|
318
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
319
|
+
name: fqns(decl.name),
|
|
320
|
+
closure: Solargraph::Pin::ROOT_PIN,
|
|
321
|
+
comments: decl.comment&.string,
|
|
322
|
+
generics: type_parameter_names(decl),
|
|
323
|
+
# HACK: Using :hidden to keep interfaces from appearing in
|
|
324
|
+
# autocompletion
|
|
325
|
+
visibility: :hidden,
|
|
326
|
+
source: :rbs
|
|
327
|
+
)
|
|
328
|
+
class_pin.docstring.add_tag(YARD::Tags::Tag.new(:abstract, '(RBS interface)'))
|
|
329
|
+
pins.push class_pin
|
|
330
|
+
convert_members_to_pins decl, class_pin
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
# @param decl [RBS::AST::Declarations::Module]
|
|
334
|
+
# @return [void]
|
|
335
|
+
def module_decl_to_pin decl
|
|
336
|
+
module_pin = Solargraph::Pin::Namespace.new(
|
|
337
|
+
type: :module,
|
|
338
|
+
name: fqns(decl.name),
|
|
339
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
340
|
+
closure: Solargraph::Pin::ROOT_PIN,
|
|
341
|
+
comments: decl.comment&.string,
|
|
342
|
+
generics: type_parameter_names(decl),
|
|
343
|
+
source: :rbs
|
|
344
|
+
)
|
|
345
|
+
pins.push module_pin
|
|
346
|
+
convert_self_types_to_pins decl, module_pin
|
|
347
|
+
convert_members_to_pins decl, module_pin
|
|
348
|
+
|
|
349
|
+
raise "Invalid type for module declaration: #{module_pin.class}" unless module_pin.is_a?(Pin::Namespace)
|
|
350
|
+
|
|
351
|
+
add_mixins decl, module_pin.closure
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
# @param fqns [String]
|
|
355
|
+
# @param type [ComplexType, ComplexType::UniqueType]
|
|
356
|
+
# @param comments [String, nil]
|
|
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
|
|
362
|
+
#
|
|
363
|
+
# @return [Solargraph::Pin::Constant]
|
|
364
|
+
def create_constant fqns, type, comments, decl, base = nil
|
|
365
|
+
parts = fqns.split('::')
|
|
366
|
+
if parts.length > 1
|
|
367
|
+
fqns = parts.last
|
|
368
|
+
# @sg-ignore Need to add nil check here
|
|
369
|
+
closure = pins.select { |pin| pin && pin.path == parts[0..-2].join('::') }.first
|
|
370
|
+
else
|
|
371
|
+
fqns = parts.first
|
|
372
|
+
closure = Solargraph::Pin::ROOT_PIN
|
|
373
|
+
end
|
|
374
|
+
constant_pin = Solargraph::Pin::Constant.new(
|
|
375
|
+
name: fqns,
|
|
376
|
+
closure: closure,
|
|
377
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
378
|
+
comments: comments,
|
|
379
|
+
source: :rbs
|
|
380
|
+
)
|
|
381
|
+
rooted_tag = type.rooted_tags
|
|
382
|
+
rooted_tag = "#{base}<#{rooted_tag}>" if base
|
|
383
|
+
constant_pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
|
|
384
|
+
constant_pin
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
# @param decl [RBS::AST::Declarations::ClassAlias]
|
|
388
|
+
# @return [void]
|
|
389
|
+
def class_alias_decl_to_pin decl
|
|
390
|
+
# See https://www.rubydoc.info/gems/rbs/3.4.3/RBS/AST/Declarations/ClassAlias
|
|
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')
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
# @param decl [RBS::AST::Declarations::ModuleAlias]
|
|
397
|
+
# @return [void]
|
|
398
|
+
def module_alias_decl_to_pin decl
|
|
399
|
+
# See https://www.rubydoc.info/gems/rbs/3.4.3/RBS/AST/Declarations/ModuleAlias
|
|
400
|
+
new_name = fqns(decl.new_name)
|
|
401
|
+
old_type = build_type(decl.old_name)
|
|
402
|
+
|
|
403
|
+
pins.push create_constant(new_name, old_type, decl.comment&.string, decl, '::Module')
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
# @param decl [RBS::AST::Declarations::Constant]
|
|
407
|
+
# @return [void]
|
|
408
|
+
def constant_decl_to_pin decl
|
|
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)
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
# @param decl [RBS::AST::Declarations::Global]
|
|
415
|
+
# @return [void]
|
|
416
|
+
def global_decl_to_pin decl
|
|
417
|
+
closure = Solargraph::Pin::ROOT_PIN
|
|
418
|
+
name = decl.name.to_s
|
|
419
|
+
pin = Solargraph::Pin::GlobalVariable.new(
|
|
420
|
+
name: name,
|
|
421
|
+
closure: closure,
|
|
422
|
+
comments: decl.comment&.string,
|
|
423
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
424
|
+
source: :rbs
|
|
425
|
+
)
|
|
426
|
+
rooted_tag = other_type_to_type(decl.type).rooted_tags
|
|
427
|
+
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
|
428
|
+
pins.push pin
|
|
429
|
+
end
|
|
430
|
+
|
|
431
|
+
# Visibility overrides that will allow the Solargraph project
|
|
432
|
+
# and plugins to pass typechecking using SOLARGRAPH_ASSERTS=on,
|
|
433
|
+
# so that we can detect any regressions/issues elsewhere in the
|
|
434
|
+
# visibility logic.
|
|
435
|
+
#
|
|
436
|
+
# These should either reflect a bug upstream in the RBS
|
|
437
|
+
# definitions, or include a @todo indicating what needs to be
|
|
438
|
+
# fixed in Solargraph to properly understand it.
|
|
439
|
+
#
|
|
440
|
+
# @todo PR these fixes upstream and list open PRs here above
|
|
441
|
+
# related overrides
|
|
442
|
+
# @todo externalize remaining overrides into yaml file, then
|
|
443
|
+
# allow that to be extended via .solargraph.yml
|
|
444
|
+
# @type [Hash{Array(String, Symbol, String) => Symbol}
|
|
445
|
+
VISIBILITY_OVERRIDE = {
|
|
446
|
+
['Rails::Engine', :instance, 'run_tasks_blocks'] => :protected,
|
|
447
|
+
# Should have been marked as both instance and class method in module -e.g., 'module_function'
|
|
448
|
+
['Kernel', :instance, 'pretty_inspect'] => :private,
|
|
449
|
+
# marked incorrectly in RBS
|
|
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]
|
|
472
|
+
# @param closure [Pin::Closure]
|
|
473
|
+
# @param context [Context]
|
|
474
|
+
# @param scope [Symbol] :instance or :class
|
|
475
|
+
# @param name [String] The name of the method
|
|
476
|
+
# @return [Symbol]
|
|
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
|
|
480
|
+
override_key = [closure.path, scope, name]
|
|
481
|
+
visibility = VISIBILITY_OVERRIDE[override_key]
|
|
482
|
+
simple_override_key = [closure.path, scope]
|
|
483
|
+
visibility ||= VISIBILITY_OVERRIDE[simple_override_key]
|
|
484
|
+
if closure.path == 'Kernel' && Kernel.private_instance_methods(false).include?(decl.name)
|
|
485
|
+
visibility ||= :private
|
|
486
|
+
end
|
|
487
|
+
if decl.kind == :singleton_instance
|
|
488
|
+
# this is a 'module function'
|
|
489
|
+
visibility ||= :private
|
|
490
|
+
end
|
|
491
|
+
visibility ||= decl.visibility
|
|
492
|
+
visibility ||= context.visibility
|
|
493
|
+
visibility ||= :public
|
|
494
|
+
visibility
|
|
495
|
+
end
|
|
496
|
+
|
|
497
|
+
# @param decl [RBS::AST::Members::MethodDefinition]
|
|
498
|
+
# @param closure [Pin::Closure]
|
|
499
|
+
# @param context [Context]
|
|
500
|
+
# @return [void]
|
|
501
|
+
def method_def_to_pin decl, closure, context
|
|
502
|
+
# there may be edge cases here around different signatures
|
|
503
|
+
# having different type params / orders - we may need to match
|
|
504
|
+
# this data model and have generics live in signatures to
|
|
505
|
+
# handle those correctly
|
|
506
|
+
generics = decl.overloads.map(&:method_type).map do |method_type|
|
|
507
|
+
type_parameter_names method_type
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
if decl.instance?
|
|
511
|
+
name = decl.name.to_s
|
|
512
|
+
final_scope = :instance
|
|
513
|
+
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
|
514
|
+
pin = Solargraph::Pin::Method.new(
|
|
515
|
+
name: name,
|
|
516
|
+
closure: closure,
|
|
517
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
518
|
+
comments: decl.comment&.string,
|
|
519
|
+
scope: final_scope,
|
|
520
|
+
signatures: [],
|
|
521
|
+
generics: generics,
|
|
522
|
+
visibility: visibility,
|
|
523
|
+
source: :rbs
|
|
524
|
+
)
|
|
525
|
+
pin.signatures.concat method_def_to_sigs(decl, pin)
|
|
526
|
+
pins.push pin
|
|
527
|
+
if pin.name == 'initialize'
|
|
528
|
+
pin.instance_variable_set(:@visibility, :private)
|
|
529
|
+
pin.instance_variable_set(:@return_type, ComplexType::VOID)
|
|
530
|
+
end
|
|
531
|
+
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
|
|
549
|
+
end
|
|
550
|
+
|
|
551
|
+
# @param decl [RBS::AST::Members::MethodDefinition]
|
|
552
|
+
# @param pin [Pin::Method]
|
|
553
|
+
# @return [void]
|
|
554
|
+
def method_def_to_sigs decl, pin
|
|
555
|
+
# @param overload [RBS::AST::Members::MethodDefinition::Overload]
|
|
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
|
|
559
|
+
type_location = location_decl_to_pin_location(overload.method_type.location)
|
|
560
|
+
generics = type_parameter_names(overload.method_type)
|
|
561
|
+
signature_parameters, signature_return_type = parts_of_function(overload.method_type, pin)
|
|
562
|
+
rbs_block = overload.method_type.block
|
|
563
|
+
block = if rbs_block
|
|
564
|
+
block_parameters, block_return_type = parts_of_function(rbs_block, pin)
|
|
565
|
+
Pin::Signature.new(generics: generics, parameters: block_parameters,
|
|
566
|
+
return_type: block_return_type, source: :rbs,
|
|
567
|
+
type_location: type_location, closure: pin)
|
|
568
|
+
end
|
|
569
|
+
Pin::Signature.new(generics: generics, parameters: signature_parameters,
|
|
570
|
+
return_type: signature_return_type, block: block, source: :rbs,
|
|
571
|
+
type_location: type_location, closure: pin)
|
|
572
|
+
end
|
|
573
|
+
end
|
|
574
|
+
|
|
575
|
+
# @param location [RBS::Location, nil]
|
|
576
|
+
# @return [Solargraph::Location, nil]
|
|
577
|
+
def location_decl_to_pin_location location
|
|
578
|
+
return nil if location&.name.nil?
|
|
579
|
+
|
|
580
|
+
# @sg-ignore flow sensitive typing should handle return nil if location&.name.nil?
|
|
581
|
+
start_pos = Position.new(location.start_line - 1, location.start_column)
|
|
582
|
+
# @sg-ignore flow sensitive typing should handle return nil if location&.name.nil?
|
|
583
|
+
end_pos = Position.new(location.end_line - 1, location.end_column)
|
|
584
|
+
range = Range.new(start_pos, end_pos)
|
|
585
|
+
# @sg-ignore flow sensitve typing should handle return nil if location&.name.nil?
|
|
586
|
+
Location.new(location.name.to_s, range)
|
|
587
|
+
end
|
|
588
|
+
|
|
589
|
+
# @param type [RBS::MethodType, RBS::Types::Block]
|
|
590
|
+
# @param pin [Pin::Method]
|
|
591
|
+
# @return [Array(Array<Pin::Parameter>, ComplexType)]
|
|
592
|
+
def parts_of_function type, pin
|
|
593
|
+
type_location = pin.type_location
|
|
594
|
+
if defined?(RBS::Types::UntypedFunction) && type.type.is_a?(RBS::Types::UntypedFunction)
|
|
595
|
+
return [
|
|
596
|
+
[Solargraph::Pin::Parameter.new(decl: :restarg, name: 'arg', closure: pin, source: :rbs,
|
|
597
|
+
type_location: type_location)],
|
|
598
|
+
method_type_to_type(type)
|
|
599
|
+
]
|
|
600
|
+
end
|
|
601
|
+
|
|
602
|
+
parameters = []
|
|
603
|
+
arg_num = -1
|
|
604
|
+
type.type.required_positionals.each do |param|
|
|
605
|
+
# @sg-ignore Unresolved call to name
|
|
606
|
+
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
|
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)
|
|
611
|
+
end
|
|
612
|
+
type.type.optional_positionals.each do |param|
|
|
613
|
+
# @sg-ignore Unresolved call to name
|
|
614
|
+
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
|
615
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :optarg, name: name, closure: pin,
|
|
616
|
+
# @sg-ignore RBS generic type understanding issue
|
|
617
|
+
return_type: other_type_to_type(param.type),
|
|
618
|
+
type_location: type_location,
|
|
619
|
+
source: :rbs)
|
|
620
|
+
end
|
|
621
|
+
if type.type.rest_positionals
|
|
622
|
+
name = type.type.rest_positionals.name ? type.type.rest_positionals.name.to_s : "arg_#{arg_num += 1}"
|
|
623
|
+
inner_rest_positional_type = other_type_to_type(type.type.rest_positionals.type)
|
|
624
|
+
rest_positional_type = ComplexType::UniqueType.new('Array',
|
|
625
|
+
[],
|
|
626
|
+
[inner_rest_positional_type],
|
|
627
|
+
rooted: true, parameters_type: :list)
|
|
628
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :restarg, name: name, closure: pin,
|
|
629
|
+
source: :rbs, type_location: type_location,
|
|
630
|
+
return_type: rest_positional_type)
|
|
631
|
+
end
|
|
632
|
+
type.type.trailing_positionals.each do |param|
|
|
633
|
+
# @sg-ignore Unresolved call to name
|
|
634
|
+
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
|
635
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin, source: :rbs,
|
|
636
|
+
type_location: type_location)
|
|
637
|
+
end
|
|
638
|
+
type.type.required_keywords.each do |orig, param|
|
|
639
|
+
# @sg-ignore Unresolved call to to_s
|
|
640
|
+
name = orig ? orig.to_s : "arg_#{arg_num += 1}"
|
|
641
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :kwarg, name: name, closure: pin,
|
|
642
|
+
# @sg-ignore RBS generic type understanding issue
|
|
643
|
+
return_type: other_type_to_type(param.type),
|
|
644
|
+
source: :rbs, type_location: type_location)
|
|
645
|
+
end
|
|
646
|
+
type.type.optional_keywords.each do |orig, param|
|
|
647
|
+
# @sg-ignore Unresolved call to to_s
|
|
648
|
+
name = orig ? orig.to_s : "arg_#{arg_num += 1}"
|
|
649
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :kwoptarg, name: name, closure: pin,
|
|
650
|
+
# @sg-ignore RBS generic type understanding issue
|
|
651
|
+
return_type: other_type_to_type(param.type),
|
|
652
|
+
type_location: type_location,
|
|
653
|
+
source: :rbs)
|
|
654
|
+
end
|
|
655
|
+
if type.type.rest_keywords
|
|
656
|
+
name = type.type.rest_keywords.name ? type.type.rest_keywords.name.to_s : "arg_#{arg_num += 1}"
|
|
657
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :kwrestarg,
|
|
658
|
+
name: type.type.rest_keywords.name.to_s, closure: pin,
|
|
659
|
+
source: :rbs, type_location: type_location)
|
|
660
|
+
end
|
|
661
|
+
|
|
662
|
+
return_type = method_type_to_type(type)
|
|
663
|
+
[parameters, return_type]
|
|
664
|
+
end
|
|
665
|
+
|
|
666
|
+
# @param decl [RBS::AST::Members::AttrReader,RBS::AST::Members::AttrAccessor]
|
|
667
|
+
# @param closure [Pin::Namespace]
|
|
668
|
+
# @param context [Context]
|
|
669
|
+
# @return [void]
|
|
670
|
+
def attr_reader_to_pin decl, closure, context
|
|
671
|
+
name = decl.name.to_s
|
|
672
|
+
final_scope = decl.kind == :instance ? :instance : :class
|
|
673
|
+
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
|
674
|
+
pin = Solargraph::Pin::Method.new(
|
|
675
|
+
name: name,
|
|
676
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
677
|
+
closure: closure,
|
|
678
|
+
comments: decl.comment&.string,
|
|
679
|
+
scope: final_scope,
|
|
680
|
+
attribute: true,
|
|
681
|
+
visibility: visibility,
|
|
682
|
+
source: :rbs
|
|
683
|
+
)
|
|
684
|
+
rooted_tag = other_type_to_type(decl.type).rooted_tags
|
|
685
|
+
pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
|
|
686
|
+
logger.debug do
|
|
687
|
+
"Conversions#attr_reader_to_pin(name=#{name.inspect}, visibility=#{visibility.inspect}) => #{pin.inspect}"
|
|
688
|
+
end
|
|
689
|
+
pins.push pin
|
|
690
|
+
end
|
|
691
|
+
|
|
692
|
+
# @param decl [RBS::AST::Members::AttrWriter, RBS::AST::Members::AttrAccessor]
|
|
693
|
+
# @param closure [Pin::Namespace]
|
|
694
|
+
# @param context [Context]
|
|
695
|
+
# @return [void]
|
|
696
|
+
def attr_writer_to_pin decl, closure, context
|
|
697
|
+
final_scope = decl.kind == :instance ? :instance : :class
|
|
698
|
+
name = "#{decl.name}="
|
|
699
|
+
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
|
700
|
+
type_location = location_decl_to_pin_location(decl.location)
|
|
701
|
+
pin = Solargraph::Pin::Method.new(
|
|
702
|
+
name: name,
|
|
703
|
+
type_location: type_location,
|
|
704
|
+
closure: closure,
|
|
705
|
+
parameters: [],
|
|
706
|
+
comments: decl.comment&.string,
|
|
707
|
+
scope: final_scope,
|
|
708
|
+
attribute: true,
|
|
709
|
+
visibility: visibility,
|
|
710
|
+
source: :rbs
|
|
711
|
+
)
|
|
712
|
+
pin.parameters <<
|
|
713
|
+
Solargraph::Pin::Parameter.new(
|
|
714
|
+
name: 'value',
|
|
715
|
+
return_type: other_type_to_type(decl.type),
|
|
716
|
+
source: :rbs,
|
|
717
|
+
closure: pin,
|
|
718
|
+
type_location: type_location
|
|
719
|
+
)
|
|
720
|
+
rooted_tags = other_type_to_type(decl.type).rooted_tags
|
|
721
|
+
pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tags))
|
|
722
|
+
pins.push pin
|
|
723
|
+
end
|
|
724
|
+
|
|
725
|
+
# @param decl [RBS::AST::Members::AttrAccessor]
|
|
726
|
+
# @param closure [Pin::Namespace]
|
|
727
|
+
# @param context [Context]
|
|
728
|
+
# @return [void]
|
|
729
|
+
def attr_accessor_to_pin decl, closure, context
|
|
730
|
+
attr_reader_to_pin(decl, closure, context)
|
|
731
|
+
attr_writer_to_pin(decl, closure, context)
|
|
732
|
+
end
|
|
733
|
+
|
|
734
|
+
# @param decl [RBS::AST::Members::InstanceVariable]
|
|
735
|
+
# @param closure [Pin::Namespace]
|
|
736
|
+
# @return [void]
|
|
737
|
+
def ivar_to_pin decl, closure
|
|
738
|
+
pin = Solargraph::Pin::InstanceVariable.new(
|
|
739
|
+
name: decl.name.to_s,
|
|
740
|
+
closure: closure,
|
|
741
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
742
|
+
comments: decl.comment&.string,
|
|
743
|
+
source: :rbs
|
|
744
|
+
)
|
|
745
|
+
rooted_tag = other_type_to_type(decl.type).rooted_tags
|
|
746
|
+
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
|
747
|
+
pins.push pin
|
|
748
|
+
end
|
|
749
|
+
|
|
750
|
+
# @param decl [RBS::AST::Members::ClassVariable]
|
|
751
|
+
# @param closure [Pin::Namespace]
|
|
752
|
+
# @return [void]
|
|
753
|
+
def cvar_to_pin decl, closure
|
|
754
|
+
name = decl.name.to_s
|
|
755
|
+
pin = Solargraph::Pin::ClassVariable.new(
|
|
756
|
+
name: name,
|
|
757
|
+
closure: closure,
|
|
758
|
+
comments: decl.comment&.string,
|
|
759
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
760
|
+
source: :rbs
|
|
761
|
+
)
|
|
762
|
+
rooted_tag = other_type_to_type(decl.type).rooted_tags
|
|
763
|
+
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
|
764
|
+
pins.push pin
|
|
765
|
+
end
|
|
766
|
+
|
|
767
|
+
# @param decl [RBS::AST::Members::ClassInstanceVariable]
|
|
768
|
+
# @param closure [Pin::Namespace]
|
|
769
|
+
# @return [void]
|
|
770
|
+
def civar_to_pin decl, closure
|
|
771
|
+
name = decl.name.to_s
|
|
772
|
+
pin = Solargraph::Pin::InstanceVariable.new(
|
|
773
|
+
name: name,
|
|
774
|
+
closure: closure,
|
|
775
|
+
comments: decl.comment&.string,
|
|
776
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
777
|
+
source: :rbs
|
|
778
|
+
)
|
|
779
|
+
rooted_tag = other_type_to_type(decl.type).rooted_tags
|
|
780
|
+
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
|
781
|
+
pins.push pin
|
|
782
|
+
end
|
|
783
|
+
|
|
784
|
+
# @param decl [RBS::AST::Members::Include]
|
|
785
|
+
# @param closure [Pin::Namespace]
|
|
786
|
+
# @return [void]
|
|
787
|
+
def include_to_pin decl, closure
|
|
788
|
+
type = build_type(decl.name, decl.args)
|
|
789
|
+
generic_values = type.all_params.map(&:rooted_tags)
|
|
790
|
+
pins.push Solargraph::Pin::Reference::Include.new(
|
|
791
|
+
name: type.rooted_name, # reference pins use rooted names
|
|
792
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
793
|
+
generic_values: generic_values,
|
|
794
|
+
closure: closure,
|
|
795
|
+
source: :rbs
|
|
796
|
+
)
|
|
797
|
+
end
|
|
798
|
+
|
|
799
|
+
# @param decl [RBS::AST::Members::Prepend]
|
|
800
|
+
# @param closure [Pin::Namespace]
|
|
801
|
+
# @return [void]
|
|
802
|
+
def prepend_to_pin decl, closure
|
|
803
|
+
type = build_type(decl.name, decl.args)
|
|
804
|
+
generic_values = type.all_params.map(&:rooted_tags)
|
|
805
|
+
pins.push Solargraph::Pin::Reference::Prepend.new(
|
|
806
|
+
name: type.rooted_name, # reference pins use rooted names
|
|
807
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
808
|
+
generic_values: generic_values,
|
|
809
|
+
closure: closure,
|
|
810
|
+
source: :rbs
|
|
811
|
+
)
|
|
812
|
+
end
|
|
813
|
+
|
|
814
|
+
# @param decl [RBS::AST::Members::Extend]
|
|
815
|
+
# @param closure [Pin::Namespace]
|
|
816
|
+
# @return [void]
|
|
817
|
+
def extend_to_pin decl, closure
|
|
818
|
+
type = build_type(decl.name, decl.args)
|
|
819
|
+
generic_values = type.all_params.map(&:rooted_tags)
|
|
820
|
+
pins.push Solargraph::Pin::Reference::Extend.new(
|
|
821
|
+
name: type.rooted_name, # reference pins use rooted names
|
|
822
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
823
|
+
generic_values: generic_values,
|
|
824
|
+
closure: closure,
|
|
825
|
+
source: :rbs
|
|
826
|
+
)
|
|
827
|
+
end
|
|
828
|
+
|
|
829
|
+
# @param decl [RBS::AST::Members::Alias]
|
|
830
|
+
# @param closure [Pin::Namespace]
|
|
831
|
+
# @return [void]
|
|
832
|
+
def alias_to_pin decl, closure
|
|
833
|
+
final_scope = decl.singleton? ? :class : :instance
|
|
834
|
+
pins.push Solargraph::Pin::MethodAlias.new(
|
|
835
|
+
name: decl.new_name.to_s,
|
|
836
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
837
|
+
original: decl.old_name.to_s,
|
|
838
|
+
closure: closure,
|
|
839
|
+
scope: final_scope,
|
|
840
|
+
source: :rbs
|
|
841
|
+
)
|
|
842
|
+
end
|
|
843
|
+
|
|
844
|
+
# @param type [RBS::MethodType, RBS::Types::Block]
|
|
845
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
846
|
+
def method_type_to_type type
|
|
847
|
+
other_type_to_type type.type.return_type
|
|
848
|
+
end
|
|
849
|
+
|
|
850
|
+
# @param type [RBS::Types::Bases::Base,Object] RBS type object.
|
|
851
|
+
# Note: Generally these extend from RBS::Types::Bases::Base,
|
|
852
|
+
# but not all.
|
|
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
|
|
876
|
+
# @todo Better record support
|
|
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
|
|
893
|
+
# top is the most super superclass
|
|
894
|
+
ComplexType::UniqueType.new('BasicObject', rooted: true)
|
|
895
|
+
when RBS::Types::Bases::Bottom
|
|
896
|
+
# bottom is used in contexts where nothing will ever return
|
|
897
|
+
# - e.g., it could be the return type of 'exit()' or 'raise'
|
|
898
|
+
#
|
|
899
|
+
# @todo define a specific bottom type and use it to
|
|
900
|
+
# determine dead code
|
|
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
|
|
908
|
+
# type-level alias use - e.g., 'bool' in "type bool = true | false"
|
|
909
|
+
# @todo ensure these get resolved after processing all aliases
|
|
910
|
+
# @todo handle recursive aliases
|
|
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
|
|
914
|
+
# represents a mix-in module which can be considered a
|
|
915
|
+
# subtype of a consumer of it
|
|
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
|
|
919
|
+
# e.g., singleton(String)
|
|
920
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
921
|
+
build_type(type.name)
|
|
922
|
+
else
|
|
923
|
+
# RBS doesn't provide a common base class for its type AST nodes
|
|
924
|
+
#
|
|
925
|
+
# @sg-ignore all types should include location
|
|
926
|
+
Solargraph.logger.warn "Unrecognized RBS type: #{type.class} at #{type.location}"
|
|
927
|
+
ComplexType::UNDEFINED
|
|
928
|
+
end
|
|
929
|
+
end
|
|
930
|
+
|
|
931
|
+
# @param decl [RBS::AST::Declarations::Class, RBS::AST::Declarations::Module]
|
|
932
|
+
# @param namespace [Pin::Namespace, nil]
|
|
933
|
+
# @return [void]
|
|
934
|
+
def add_mixins decl, namespace
|
|
935
|
+
# @param mixin [RBS::AST::Members::Include, RBS::AST::Members::Extend, RBS::AST::Members::Prepend]
|
|
936
|
+
decl.each_mixin do |mixin|
|
|
937
|
+
# @todo are we handling prepend correctly?
|
|
938
|
+
klass = mixin.is_a?(RBS::AST::Members::Include) ? Pin::Reference::Include : Pin::Reference::Extend
|
|
939
|
+
type = build_type(mixin.name, mixin.args)
|
|
940
|
+
generic_values = type.all_params.map(&:rooted_tags)
|
|
941
|
+
pins.push klass.new(
|
|
942
|
+
name: type.rooted_name, # reference pins use rooted names
|
|
943
|
+
type_location: location_decl_to_pin_location(mixin.location),
|
|
944
|
+
generic_values: generic_values,
|
|
945
|
+
closure: namespace,
|
|
946
|
+
source: :rbs
|
|
947
|
+
)
|
|
948
|
+
end
|
|
949
|
+
end
|
|
950
|
+
end
|
|
951
|
+
end
|
|
952
|
+
end
|