ruby-lsp 0.23.11 → 0.26.6
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/README.md +2 -2
- data/VERSION +1 -1
- data/exe/ruby-lsp +10 -4
- data/exe/ruby-lsp-check +0 -4
- data/exe/ruby-lsp-launcher +46 -22
- data/exe/ruby-lsp-test-exec +6 -0
- data/lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb +1 -2
- data/lib/rubocop/cop/ruby_lsp/use_register_with_handler_method.rb +3 -6
- data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +85 -118
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +159 -183
- data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +10 -14
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +130 -253
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +189 -285
- data/lib/ruby_indexer/lib/ruby_indexer/location.rb +4 -27
- data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +23 -27
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +31 -59
- data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +58 -68
- data/lib/ruby_indexer/lib/ruby_indexer/uri.rb +17 -19
- data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +7 -11
- data/lib/ruby_lsp/addon.rb +88 -86
- data/lib/ruby_lsp/base_server.rb +79 -65
- data/lib/ruby_lsp/client_capabilities.rb +16 -13
- data/lib/ruby_lsp/document.rb +205 -104
- data/lib/ruby_lsp/erb_document.rb +45 -47
- data/lib/ruby_lsp/global_state.rb +134 -86
- data/lib/ruby_lsp/internal.rb +8 -3
- data/lib/ruby_lsp/listeners/code_lens.rb +82 -89
- data/lib/ruby_lsp/listeners/completion.rb +81 -76
- data/lib/ruby_lsp/listeners/definition.rb +78 -72
- data/lib/ruby_lsp/listeners/document_highlight.rb +149 -151
- data/lib/ruby_lsp/listeners/document_link.rb +93 -86
- data/lib/ruby_lsp/listeners/document_symbol.rb +38 -52
- data/lib/ruby_lsp/listeners/folding_ranges.rb +40 -43
- data/lib/ruby_lsp/listeners/hover.rb +109 -117
- data/lib/ruby_lsp/listeners/inlay_hints.rb +8 -13
- data/lib/ruby_lsp/listeners/semantic_highlighting.rb +54 -56
- data/lib/ruby_lsp/listeners/signature_help.rb +12 -27
- data/lib/ruby_lsp/listeners/spec_style.rb +231 -0
- data/lib/ruby_lsp/listeners/test_discovery.rb +107 -0
- data/lib/ruby_lsp/listeners/test_style.rb +207 -95
- data/lib/ruby_lsp/node_context.rb +12 -39
- data/lib/ruby_lsp/rbs_document.rb +10 -11
- data/lib/ruby_lsp/requests/code_action_resolve.rb +92 -66
- data/lib/ruby_lsp/requests/code_actions.rb +34 -31
- data/lib/ruby_lsp/requests/code_lens.rb +31 -21
- data/lib/ruby_lsp/requests/completion.rb +8 -21
- data/lib/ruby_lsp/requests/completion_resolve.rb +14 -12
- data/lib/ruby_lsp/requests/definition.rb +8 -20
- data/lib/ruby_lsp/requests/diagnostics.rb +8 -11
- data/lib/ruby_lsp/requests/discover_tests.rb +20 -7
- data/lib/ruby_lsp/requests/document_highlight.rb +6 -16
- data/lib/ruby_lsp/requests/document_link.rb +6 -17
- data/lib/ruby_lsp/requests/document_symbol.rb +5 -8
- data/lib/ruby_lsp/requests/folding_ranges.rb +7 -15
- data/lib/ruby_lsp/requests/formatting.rb +6 -9
- data/lib/ruby_lsp/requests/go_to_relevant_file.rb +139 -0
- data/lib/ruby_lsp/requests/hover.rb +12 -25
- data/lib/ruby_lsp/requests/inlay_hints.rb +8 -19
- data/lib/ruby_lsp/requests/on_type_formatting.rb +32 -40
- data/lib/ruby_lsp/requests/prepare_rename.rb +5 -10
- data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +5 -15
- data/lib/ruby_lsp/requests/range_formatting.rb +5 -6
- data/lib/ruby_lsp/requests/references.rb +17 -57
- data/lib/ruby_lsp/requests/rename.rb +27 -51
- data/lib/ruby_lsp/requests/request.rb +13 -25
- data/lib/ruby_lsp/requests/selection_ranges.rb +7 -7
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +16 -35
- data/lib/ruby_lsp/requests/show_syntax_tree.rb +7 -8
- data/lib/ruby_lsp/requests/signature_help.rb +9 -27
- data/lib/ruby_lsp/requests/support/annotation.rb +4 -10
- data/lib/ruby_lsp/requests/support/common.rb +23 -61
- data/lib/ruby_lsp/requests/support/formatter.rb +16 -15
- data/lib/ruby_lsp/requests/support/package_url.rb +414 -0
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +27 -35
- data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +13 -16
- data/lib/ruby_lsp/requests/support/rubocop_runner.rb +34 -36
- data/lib/ruby_lsp/requests/support/selection_range.rb +1 -3
- data/lib/ruby_lsp/requests/support/sorbet.rb +29 -38
- data/lib/ruby_lsp/requests/support/source_uri.rb +22 -33
- data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +12 -19
- data/lib/ruby_lsp/requests/support/test_item.rb +16 -14
- data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +5 -6
- data/lib/ruby_lsp/requests/workspace_symbol.rb +24 -16
- data/lib/ruby_lsp/response_builders/collection_response_builder.rb +6 -9
- data/lib/ruby_lsp/response_builders/document_symbol.rb +15 -21
- data/lib/ruby_lsp/response_builders/hover.rb +12 -18
- data/lib/ruby_lsp/response_builders/response_builder.rb +6 -7
- data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +62 -91
- data/lib/ruby_lsp/response_builders/signature_help.rb +6 -8
- data/lib/ruby_lsp/response_builders/test_collection.rb +35 -13
- data/lib/ruby_lsp/ruby_document.rb +32 -98
- data/lib/ruby_lsp/scope.rb +7 -11
- data/lib/ruby_lsp/scripts/compose_bundle.rb +7 -5
- data/lib/ruby_lsp/server.rb +305 -198
- data/lib/ruby_lsp/setup_bundler.rb +160 -97
- data/lib/ruby_lsp/static_docs.rb +12 -7
- data/lib/ruby_lsp/store.rb +21 -49
- data/lib/ruby_lsp/test_helper.rb +3 -16
- data/lib/ruby_lsp/test_reporters/lsp_reporter.rb +241 -0
- data/lib/ruby_lsp/test_reporters/minitest_reporter.rb +145 -0
- data/lib/ruby_lsp/test_reporters/test_unit_reporter.rb +92 -0
- data/lib/ruby_lsp/type_inferrer.rb +13 -14
- data/lib/ruby_lsp/utils.rb +138 -93
- data/static_docs/break.md +103 -0
- metadata +15 -34
- data/lib/ruby_indexer/test/class_variables_test.rb +0 -140
- data/lib/ruby_indexer/test/classes_and_modules_test.rb +0 -745
- data/lib/ruby_indexer/test/configuration_test.rb +0 -239
- data/lib/ruby_indexer/test/constant_test.rb +0 -402
- data/lib/ruby_indexer/test/enhancements_test.rb +0 -325
- data/lib/ruby_indexer/test/global_variable_test.rb +0 -49
- data/lib/ruby_indexer/test/index_test.rb +0 -2186
- data/lib/ruby_indexer/test/instance_variables_test.rb +0 -240
- data/lib/ruby_indexer/test/method_test.rb +0 -947
- data/lib/ruby_indexer/test/prefix_tree_test.rb +0 -150
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +0 -386
- data/lib/ruby_indexer/test/reference_finder_test.rb +0 -330
- data/lib/ruby_indexer/test/test_case.rb +0 -51
- data/lib/ruby_indexer/test/uri_test.rb +0 -72
- data/lib/ruby_lsp/load_sorbet.rb +0 -62
|
@@ -3,76 +3,65 @@
|
|
|
3
3
|
|
|
4
4
|
module RubyIndexer
|
|
5
5
|
class Entry
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
PUBLIC = new(:public)
|
|
9
|
-
PROTECTED = new(:protected)
|
|
10
|
-
PRIVATE = new(:private)
|
|
11
|
-
end
|
|
12
|
-
end
|
|
6
|
+
#: Configuration
|
|
7
|
+
attr_reader :configuration
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
sig { returns(String) }
|
|
9
|
+
#: String
|
|
17
10
|
attr_reader :name
|
|
18
11
|
|
|
19
|
-
|
|
12
|
+
#: URI::Generic
|
|
20
13
|
attr_reader :uri
|
|
21
14
|
|
|
22
|
-
|
|
15
|
+
#: RubyIndexer::Location
|
|
23
16
|
attr_reader :location
|
|
24
17
|
|
|
25
18
|
alias_method :name_location, :location
|
|
26
19
|
|
|
27
|
-
|
|
20
|
+
#: Symbol
|
|
28
21
|
attr_accessor :visibility
|
|
29
22
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
uri: URI::Generic,
|
|
34
|
-
location: Location,
|
|
35
|
-
comments: T.nilable(String),
|
|
36
|
-
).void
|
|
37
|
-
end
|
|
38
|
-
def initialize(name, uri, location, comments)
|
|
23
|
+
#: (Configuration configuration, String name, URI::Generic uri, Location location, String? comments) -> void
|
|
24
|
+
def initialize(configuration, name, uri, location, comments)
|
|
25
|
+
@configuration = configuration
|
|
39
26
|
@name = name
|
|
40
27
|
@uri = uri
|
|
41
28
|
@comments = comments
|
|
42
|
-
@visibility =
|
|
29
|
+
@visibility = :public #: Symbol
|
|
43
30
|
@location = location
|
|
44
31
|
end
|
|
45
32
|
|
|
46
|
-
|
|
33
|
+
#: -> bool
|
|
47
34
|
def public?
|
|
48
|
-
visibility ==
|
|
35
|
+
@visibility == :public
|
|
49
36
|
end
|
|
50
37
|
|
|
51
|
-
|
|
38
|
+
#: -> bool
|
|
52
39
|
def protected?
|
|
53
|
-
visibility ==
|
|
40
|
+
@visibility == :protected
|
|
54
41
|
end
|
|
55
42
|
|
|
56
|
-
|
|
43
|
+
#: -> bool
|
|
57
44
|
def private?
|
|
58
|
-
visibility ==
|
|
45
|
+
@visibility == :private
|
|
59
46
|
end
|
|
60
47
|
|
|
61
|
-
|
|
48
|
+
#: -> String
|
|
62
49
|
def file_name
|
|
63
50
|
if @uri.scheme == "untitled"
|
|
64
|
-
|
|
51
|
+
@uri.opaque #: as !nil
|
|
65
52
|
else
|
|
66
|
-
File.basename(
|
|
53
|
+
File.basename(
|
|
54
|
+
file_path, #: as !nil
|
|
55
|
+
)
|
|
67
56
|
end
|
|
68
57
|
end
|
|
69
58
|
|
|
70
|
-
|
|
59
|
+
#: -> String?
|
|
71
60
|
def file_path
|
|
72
61
|
@uri.full_path
|
|
73
62
|
end
|
|
74
63
|
|
|
75
|
-
|
|
64
|
+
#: -> String
|
|
76
65
|
def comments
|
|
77
66
|
@comments ||= begin
|
|
78
67
|
# Parse only the comments based on the file path, which is much faster than parsing the entire file
|
|
@@ -97,7 +86,7 @@ module RubyIndexer
|
|
|
97
86
|
correct_group.filter_map do |comment|
|
|
98
87
|
content = comment.slice.chomp
|
|
99
88
|
|
|
100
|
-
if content.valid_encoding?
|
|
89
|
+
if content.valid_encoding? && !content.match?(@configuration.magic_comment_regex)
|
|
101
90
|
content.delete_prefix!("#")
|
|
102
91
|
content.delete_prefix!(" ")
|
|
103
92
|
content
|
|
@@ -113,16 +102,12 @@ module RubyIndexer
|
|
|
113
102
|
end
|
|
114
103
|
end
|
|
115
104
|
|
|
105
|
+
# @abstract
|
|
116
106
|
class ModuleOperation
|
|
117
|
-
|
|
118
|
-
extend T::Helpers
|
|
119
|
-
|
|
120
|
-
abstract!
|
|
121
|
-
|
|
122
|
-
sig { returns(String) }
|
|
107
|
+
#: String
|
|
123
108
|
attr_reader :module_name
|
|
124
109
|
|
|
125
|
-
|
|
110
|
+
#: (String module_name) -> void
|
|
126
111
|
def initialize(module_name)
|
|
127
112
|
@module_name = module_name
|
|
128
113
|
end
|
|
@@ -131,39 +116,27 @@ module RubyIndexer
|
|
|
131
116
|
class Include < ModuleOperation; end
|
|
132
117
|
class Prepend < ModuleOperation; end
|
|
133
118
|
|
|
119
|
+
# @abstract
|
|
134
120
|
class Namespace < Entry
|
|
135
|
-
|
|
136
|
-
extend T::Helpers
|
|
137
|
-
|
|
138
|
-
abstract!
|
|
139
|
-
|
|
140
|
-
sig { returns(T::Array[String]) }
|
|
121
|
+
#: Array[String]
|
|
141
122
|
attr_reader :nesting
|
|
142
123
|
|
|
143
124
|
# Returns the location of the constant name, excluding the parent class or the body
|
|
144
|
-
|
|
125
|
+
#: Location
|
|
145
126
|
attr_reader :name_location
|
|
146
127
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
uri: URI::Generic,
|
|
151
|
-
location: Location,
|
|
152
|
-
name_location: Location,
|
|
153
|
-
comments: T.nilable(String),
|
|
154
|
-
).void
|
|
155
|
-
end
|
|
156
|
-
def initialize(nesting, uri, location, name_location, comments)
|
|
157
|
-
@name = T.let(nesting.join("::"), String)
|
|
128
|
+
#: (Configuration configuration, Array[String] nesting, URI::Generic uri, Location location, Location name_location, String? comments) -> void
|
|
129
|
+
def initialize(configuration, nesting, uri, location, name_location, comments) # rubocop:disable Metrics/ParameterLists
|
|
130
|
+
@name = nesting.join("::") #: String
|
|
158
131
|
# The original nesting where this namespace was discovered
|
|
159
132
|
@nesting = nesting
|
|
160
133
|
|
|
161
|
-
super(@name, uri, location, comments)
|
|
134
|
+
super(configuration, @name, uri, location, comments)
|
|
162
135
|
|
|
163
136
|
@name_location = name_location
|
|
164
137
|
end
|
|
165
138
|
|
|
166
|
-
|
|
139
|
+
#: -> Array[String]
|
|
167
140
|
def mixin_operation_module_names
|
|
168
141
|
mixin_operations.map(&:module_name)
|
|
169
142
|
end
|
|
@@ -171,12 +144,12 @@ module RubyIndexer
|
|
|
171
144
|
# Stores all explicit prepend, include and extend operations in the exact order they were discovered in the source
|
|
172
145
|
# code. Maintaining the order is essential to linearize ancestors the right way when a module is both included
|
|
173
146
|
# and prepended
|
|
174
|
-
|
|
147
|
+
#: -> Array[ModuleOperation]
|
|
175
148
|
def mixin_operations
|
|
176
|
-
@mixin_operations ||=
|
|
149
|
+
@mixin_operations ||= [] #: Array[ModuleOperation]?
|
|
177
150
|
end
|
|
178
151
|
|
|
179
|
-
|
|
152
|
+
#: -> Integer
|
|
180
153
|
def ancestor_hash
|
|
181
154
|
mixin_operation_module_names.hash
|
|
182
155
|
end
|
|
@@ -186,44 +159,26 @@ module RubyIndexer
|
|
|
186
159
|
end
|
|
187
160
|
|
|
188
161
|
class Class < Namespace
|
|
189
|
-
extend T::Sig
|
|
190
|
-
|
|
191
162
|
# The unresolved name of the parent class. This may return `nil`, which indicates the lack of an explicit parent
|
|
192
163
|
# and therefore ::Object is the correct parent class
|
|
193
|
-
|
|
164
|
+
#: String?
|
|
194
165
|
attr_reader :parent_class
|
|
195
166
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
uri: URI::Generic,
|
|
200
|
-
location: Location,
|
|
201
|
-
name_location: Location,
|
|
202
|
-
comments: T.nilable(String),
|
|
203
|
-
parent_class: T.nilable(String),
|
|
204
|
-
).void
|
|
205
|
-
end
|
|
206
|
-
def initialize(nesting, uri, location, name_location, comments, parent_class) # rubocop:disable Metrics/ParameterLists
|
|
207
|
-
super(nesting, uri, location, name_location, comments)
|
|
167
|
+
#: (Configuration configuration, Array[String] nesting, URI::Generic uri, Location location, Location name_location, String? comments, String? parent_class) -> void
|
|
168
|
+
def initialize(configuration, nesting, uri, location, name_location, comments, parent_class) # rubocop:disable Metrics/ParameterLists
|
|
169
|
+
super(configuration, nesting, uri, location, name_location, comments)
|
|
208
170
|
@parent_class = parent_class
|
|
209
171
|
end
|
|
210
172
|
|
|
211
|
-
|
|
173
|
+
# @override
|
|
174
|
+
#: -> Integer
|
|
212
175
|
def ancestor_hash
|
|
213
176
|
[mixin_operation_module_names, @parent_class].hash
|
|
214
177
|
end
|
|
215
178
|
end
|
|
216
179
|
|
|
217
180
|
class SingletonClass < Class
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
sig do
|
|
221
|
-
params(
|
|
222
|
-
location: Location,
|
|
223
|
-
name_location: Location,
|
|
224
|
-
comments: T.nilable(String),
|
|
225
|
-
).void
|
|
226
|
-
end
|
|
181
|
+
#: (Location location, Location name_location, String? comments) -> void
|
|
227
182
|
def update_singleton_information(location, name_location, comments)
|
|
228
183
|
@location = location
|
|
229
184
|
@name_location = name_location
|
|
@@ -234,20 +189,16 @@ module RubyIndexer
|
|
|
234
189
|
class Constant < Entry
|
|
235
190
|
end
|
|
236
191
|
|
|
192
|
+
# @abstract
|
|
237
193
|
class Parameter
|
|
238
|
-
extend T::Helpers
|
|
239
|
-
extend T::Sig
|
|
240
|
-
|
|
241
|
-
abstract!
|
|
242
|
-
|
|
243
194
|
# Name includes just the name of the parameter, excluding symbols like splats
|
|
244
|
-
|
|
195
|
+
#: Symbol
|
|
245
196
|
attr_reader :name
|
|
246
197
|
|
|
247
198
|
# Decorated name is the parameter name including the splat or block prefix, e.g.: `*foo`, `**foo` or `&block`
|
|
248
199
|
alias_method :decorated_name, :name
|
|
249
200
|
|
|
250
|
-
|
|
201
|
+
#: (name: Symbol) -> void
|
|
251
202
|
def initialize(name:)
|
|
252
203
|
@name = name
|
|
253
204
|
end
|
|
@@ -259,7 +210,8 @@ module RubyIndexer
|
|
|
259
210
|
|
|
260
211
|
# An optional method parameter, e.g. `def foo(a = 123)`
|
|
261
212
|
class OptionalParameter < Parameter
|
|
262
|
-
|
|
213
|
+
# @override
|
|
214
|
+
#: -> Symbol
|
|
263
215
|
def decorated_name
|
|
264
216
|
:"#{@name} = <default>"
|
|
265
217
|
end
|
|
@@ -267,7 +219,8 @@ module RubyIndexer
|
|
|
267
219
|
|
|
268
220
|
# An required keyword method parameter, e.g. `def foo(a:)`
|
|
269
221
|
class KeywordParameter < Parameter
|
|
270
|
-
|
|
222
|
+
# @override
|
|
223
|
+
#: -> Symbol
|
|
271
224
|
def decorated_name
|
|
272
225
|
:"#{@name}:"
|
|
273
226
|
end
|
|
@@ -275,7 +228,8 @@ module RubyIndexer
|
|
|
275
228
|
|
|
276
229
|
# An optional keyword method parameter, e.g. `def foo(a: 123)`
|
|
277
230
|
class OptionalKeywordParameter < Parameter
|
|
278
|
-
|
|
231
|
+
# @override
|
|
232
|
+
#: -> Symbol
|
|
279
233
|
def decorated_name
|
|
280
234
|
:"#{@name}: <default>"
|
|
281
235
|
end
|
|
@@ -283,9 +237,10 @@ module RubyIndexer
|
|
|
283
237
|
|
|
284
238
|
# A rest method parameter, e.g. `def foo(*a)`
|
|
285
239
|
class RestParameter < Parameter
|
|
286
|
-
DEFAULT_NAME =
|
|
240
|
+
DEFAULT_NAME = :"<anonymous splat>" #: Symbol
|
|
287
241
|
|
|
288
|
-
|
|
242
|
+
# @override
|
|
243
|
+
#: -> Symbol
|
|
289
244
|
def decorated_name
|
|
290
245
|
:"*#{@name}"
|
|
291
246
|
end
|
|
@@ -293,9 +248,10 @@ module RubyIndexer
|
|
|
293
248
|
|
|
294
249
|
# A keyword rest method parameter, e.g. `def foo(**a)`
|
|
295
250
|
class KeywordRestParameter < Parameter
|
|
296
|
-
DEFAULT_NAME =
|
|
251
|
+
DEFAULT_NAME = :"<anonymous keyword splat>" #: Symbol
|
|
297
252
|
|
|
298
|
-
|
|
253
|
+
# @override
|
|
254
|
+
#: -> Symbol
|
|
299
255
|
def decorated_name
|
|
300
256
|
:"**#{@name}"
|
|
301
257
|
end
|
|
@@ -303,17 +259,17 @@ module RubyIndexer
|
|
|
303
259
|
|
|
304
260
|
# A block method parameter, e.g. `def foo(&block)`
|
|
305
261
|
class BlockParameter < Parameter
|
|
306
|
-
DEFAULT_NAME =
|
|
262
|
+
DEFAULT_NAME = :"<anonymous block>" #: Symbol
|
|
307
263
|
|
|
308
264
|
class << self
|
|
309
|
-
|
|
310
|
-
sig { returns(BlockParameter) }
|
|
265
|
+
#: -> BlockParameter
|
|
311
266
|
def anonymous
|
|
312
267
|
new(name: DEFAULT_NAME)
|
|
313
268
|
end
|
|
314
269
|
end
|
|
315
270
|
|
|
316
|
-
|
|
271
|
+
# @override
|
|
272
|
+
#: -> Symbol
|
|
317
273
|
def decorated_name
|
|
318
274
|
:"&#{@name}"
|
|
319
275
|
end
|
|
@@ -321,44 +277,32 @@ module RubyIndexer
|
|
|
321
277
|
|
|
322
278
|
# A forwarding method parameter, e.g. `def foo(...)`
|
|
323
279
|
class ForwardingParameter < Parameter
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
sig { void }
|
|
280
|
+
#: -> void
|
|
327
281
|
def initialize
|
|
328
282
|
# You can't name a forwarding parameter, it's always called `...`
|
|
329
283
|
super(name: :"...")
|
|
330
284
|
end
|
|
331
285
|
end
|
|
332
286
|
|
|
287
|
+
# @abstract
|
|
333
288
|
class Member < Entry
|
|
334
|
-
|
|
335
|
-
extend T::Helpers
|
|
336
|
-
|
|
337
|
-
abstract!
|
|
338
|
-
|
|
339
|
-
sig { returns(T.nilable(Entry::Namespace)) }
|
|
289
|
+
#: Entry::Namespace?
|
|
340
290
|
attr_reader :owner
|
|
341
291
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
uri: URI::Generic,
|
|
346
|
-
location: Location,
|
|
347
|
-
comments: T.nilable(String),
|
|
348
|
-
visibility: Visibility,
|
|
349
|
-
owner: T.nilable(Entry::Namespace),
|
|
350
|
-
).void
|
|
351
|
-
end
|
|
352
|
-
def initialize(name, uri, location, comments, visibility, owner) # rubocop:disable Metrics/ParameterLists
|
|
353
|
-
super(name, uri, location, comments)
|
|
292
|
+
#: (Configuration configuration, String name, URI::Generic uri, Location location, String? comments, Symbol visibility, Entry::Namespace? owner) -> void
|
|
293
|
+
def initialize(configuration, name, uri, location, comments, visibility, owner) # rubocop:disable Metrics/ParameterLists
|
|
294
|
+
super(configuration, name, uri, location, comments)
|
|
354
295
|
@visibility = visibility
|
|
355
296
|
@owner = owner
|
|
356
297
|
end
|
|
357
298
|
|
|
358
|
-
|
|
359
|
-
|
|
299
|
+
# @abstract
|
|
300
|
+
#: -> Array[Signature]
|
|
301
|
+
def signatures
|
|
302
|
+
raise AbstractMethodInvokedError
|
|
303
|
+
end
|
|
360
304
|
|
|
361
|
-
|
|
305
|
+
#: -> String
|
|
362
306
|
def decorated_parameters
|
|
363
307
|
first_signature = signatures.first
|
|
364
308
|
return "()" unless first_signature
|
|
@@ -366,7 +310,7 @@ module RubyIndexer
|
|
|
366
310
|
"(#{first_signature.format})"
|
|
367
311
|
end
|
|
368
312
|
|
|
369
|
-
|
|
313
|
+
#: -> String
|
|
370
314
|
def formatted_signatures
|
|
371
315
|
overloads_count = signatures.size
|
|
372
316
|
case overloads_count
|
|
@@ -381,45 +325,29 @@ module RubyIndexer
|
|
|
381
325
|
end
|
|
382
326
|
|
|
383
327
|
class Accessor < Member
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
sig { override.returns(T::Array[Signature]) }
|
|
328
|
+
# @override
|
|
329
|
+
#: -> Array[Signature]
|
|
387
330
|
def signatures
|
|
388
|
-
@signatures ||=
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
end,
|
|
394
|
-
T.nilable(T::Array[Signature]),
|
|
395
|
-
)
|
|
331
|
+
@signatures ||= begin
|
|
332
|
+
params = []
|
|
333
|
+
params << RequiredParameter.new(name: name.delete_suffix("=").to_sym) if name.end_with?("=")
|
|
334
|
+
[Entry::Signature.new(params)]
|
|
335
|
+
end #: Array[Signature]?
|
|
396
336
|
end
|
|
397
337
|
end
|
|
398
338
|
|
|
399
339
|
class Method < Member
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
sig { override.returns(T::Array[Signature]) }
|
|
340
|
+
# @override
|
|
341
|
+
#: Array[Signature]
|
|
403
342
|
attr_reader :signatures
|
|
404
343
|
|
|
405
344
|
# Returns the location of the method name, excluding parameters or the body
|
|
406
|
-
|
|
345
|
+
#: Location
|
|
407
346
|
attr_reader :name_location
|
|
408
347
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
uri: URI::Generic,
|
|
413
|
-
location: Location,
|
|
414
|
-
name_location: Location,
|
|
415
|
-
comments: T.nilable(String),
|
|
416
|
-
signatures: T::Array[Signature],
|
|
417
|
-
visibility: Visibility,
|
|
418
|
-
owner: T.nilable(Entry::Namespace),
|
|
419
|
-
).void
|
|
420
|
-
end
|
|
421
|
-
def initialize(name, uri, location, name_location, comments, signatures, visibility, owner) # rubocop:disable Metrics/ParameterLists
|
|
422
|
-
super(name, uri, location, comments, visibility, owner)
|
|
348
|
+
#: (Configuration configuration, String name, URI::Generic uri, Location location, Location name_location, String? comments, Array[Signature] signatures, Symbol visibility, Entry::Namespace? owner) -> void
|
|
349
|
+
def initialize(configuration, name, uri, location, name_location, comments, signatures, visibility, owner) # rubocop:disable Metrics/ParameterLists
|
|
350
|
+
super(configuration, name, uri, location, comments, visibility, owner)
|
|
423
351
|
@signatures = signatures
|
|
424
352
|
@name_location = name_location
|
|
425
353
|
end
|
|
@@ -436,26 +364,15 @@ module RubyIndexer
|
|
|
436
364
|
# target in [rdoc-ref:Index#resolve]. If the right hand side contains a constant that doesn't exist, then it's not
|
|
437
365
|
# possible to resolve the alias and it will remain an UnresolvedAlias until the right hand side constant exists
|
|
438
366
|
class UnresolvedConstantAlias < Entry
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
sig { returns(String) }
|
|
367
|
+
#: String
|
|
442
368
|
attr_reader :target
|
|
443
369
|
|
|
444
|
-
|
|
370
|
+
#: Array[String]
|
|
445
371
|
attr_reader :nesting
|
|
446
372
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
nesting: T::Array[String],
|
|
451
|
-
name: String,
|
|
452
|
-
uri: URI::Generic,
|
|
453
|
-
location: Location,
|
|
454
|
-
comments: T.nilable(String),
|
|
455
|
-
).void
|
|
456
|
-
end
|
|
457
|
-
def initialize(target, nesting, name, uri, location, comments) # rubocop:disable Metrics/ParameterLists
|
|
458
|
-
super(name, uri, location, comments)
|
|
373
|
+
#: (Configuration configuration, String target, Array[String] nesting, String name, URI::Generic uri, Location location, String? comments) -> void
|
|
374
|
+
def initialize(configuration, target, nesting, name, uri, location, comments) # rubocop:disable Metrics/ParameterLists
|
|
375
|
+
super(configuration, name, uri, location, comments)
|
|
459
376
|
|
|
460
377
|
@target = target
|
|
461
378
|
@nesting = nesting
|
|
@@ -464,14 +381,13 @@ module RubyIndexer
|
|
|
464
381
|
|
|
465
382
|
# Alias represents a resolved alias, which points to an existing constant target
|
|
466
383
|
class ConstantAlias < Entry
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
sig { returns(String) }
|
|
384
|
+
#: String
|
|
470
385
|
attr_reader :target
|
|
471
386
|
|
|
472
|
-
|
|
387
|
+
#: (String target, UnresolvedConstantAlias unresolved_alias) -> void
|
|
473
388
|
def initialize(target, unresolved_alias)
|
|
474
389
|
super(
|
|
390
|
+
unresolved_alias.configuration,
|
|
475
391
|
unresolved_alias.name,
|
|
476
392
|
unresolved_alias.uri,
|
|
477
393
|
unresolved_alias.location,
|
|
@@ -488,40 +404,24 @@ module RubyIndexer
|
|
|
488
404
|
|
|
489
405
|
# Represents a class variable e.g.: @@a = 1
|
|
490
406
|
class ClassVariable < Entry
|
|
491
|
-
|
|
407
|
+
#: Entry::Namespace?
|
|
492
408
|
attr_reader :owner
|
|
493
409
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
uri: URI::Generic,
|
|
498
|
-
location: Location,
|
|
499
|
-
comments: T.nilable(String),
|
|
500
|
-
owner: T.nilable(Entry::Namespace),
|
|
501
|
-
).void
|
|
502
|
-
end
|
|
503
|
-
def initialize(name, uri, location, comments, owner)
|
|
504
|
-
super(name, uri, location, comments)
|
|
410
|
+
#: (Configuration configuration, String name, URI::Generic uri, Location location, String? comments, Entry::Namespace? owner) -> void
|
|
411
|
+
def initialize(configuration, name, uri, location, comments, owner) # rubocop:disable Metrics/ParameterLists
|
|
412
|
+
super(configuration, name, uri, location, comments)
|
|
505
413
|
@owner = owner
|
|
506
414
|
end
|
|
507
415
|
end
|
|
508
416
|
|
|
509
417
|
# Represents an instance variable e.g.: @a = 1
|
|
510
418
|
class InstanceVariable < Entry
|
|
511
|
-
|
|
419
|
+
#: Entry::Namespace?
|
|
512
420
|
attr_reader :owner
|
|
513
421
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
uri: URI::Generic,
|
|
518
|
-
location: Location,
|
|
519
|
-
comments: T.nilable(String),
|
|
520
|
-
owner: T.nilable(Entry::Namespace),
|
|
521
|
-
).void
|
|
522
|
-
end
|
|
523
|
-
def initialize(name, uri, location, comments, owner)
|
|
524
|
-
super(name, uri, location, comments)
|
|
422
|
+
#: (Configuration configuration, String name, URI::Generic uri, Location location, String? comments, Entry::Namespace? owner) -> void
|
|
423
|
+
def initialize(configuration, name, uri, location, comments, owner) # rubocop:disable Metrics/ParameterLists
|
|
424
|
+
super(configuration, name, uri, location, comments)
|
|
525
425
|
@owner = owner
|
|
526
426
|
end
|
|
527
427
|
end
|
|
@@ -530,26 +430,15 @@ module RubyIndexer
|
|
|
530
430
|
# example, if we have `alias a b`, we create an unresolved alias for `a` because we aren't sure immediate what `b`
|
|
531
431
|
# is referring to
|
|
532
432
|
class UnresolvedMethodAlias < Entry
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
sig { returns(String) }
|
|
433
|
+
#: String
|
|
536
434
|
attr_reader :new_name, :old_name
|
|
537
435
|
|
|
538
|
-
|
|
436
|
+
#: Entry::Namespace?
|
|
539
437
|
attr_reader :owner
|
|
540
438
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
old_name: String,
|
|
545
|
-
owner: T.nilable(Entry::Namespace),
|
|
546
|
-
uri: URI::Generic,
|
|
547
|
-
location: Location,
|
|
548
|
-
comments: T.nilable(String),
|
|
549
|
-
).void
|
|
550
|
-
end
|
|
551
|
-
def initialize(new_name, old_name, owner, uri, location, comments) # rubocop:disable Metrics/ParameterLists
|
|
552
|
-
super(new_name, uri, location, comments)
|
|
439
|
+
#: (Configuration configuration, String new_name, String old_name, Entry::Namespace? owner, URI::Generic uri, Location location, String? comments) -> void
|
|
440
|
+
def initialize(configuration, new_name, old_name, owner, uri, location, comments) # rubocop:disable Metrics/ParameterLists
|
|
441
|
+
super(configuration, new_name, uri, location, comments)
|
|
553
442
|
|
|
554
443
|
@new_name = new_name
|
|
555
444
|
@old_name = old_name
|
|
@@ -559,23 +448,20 @@ module RubyIndexer
|
|
|
559
448
|
|
|
560
449
|
# A method alias is a resolved alias entry that points to the exact method target it refers to
|
|
561
450
|
class MethodAlias < Entry
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
sig { returns(T.any(Member, MethodAlias)) }
|
|
451
|
+
#: (Member | MethodAlias)
|
|
565
452
|
attr_reader :target
|
|
566
453
|
|
|
567
|
-
|
|
454
|
+
#: Entry::Namespace?
|
|
568
455
|
attr_reader :owner
|
|
569
456
|
|
|
570
|
-
|
|
571
|
-
params(target: T.any(Member, MethodAlias), unresolved_alias: UnresolvedMethodAlias).void
|
|
572
|
-
end
|
|
457
|
+
#: ((Member | MethodAlias) target, UnresolvedMethodAlias unresolved_alias) -> void
|
|
573
458
|
def initialize(target, unresolved_alias)
|
|
574
459
|
full_comments = +"Alias for #{target.name}\n"
|
|
575
460
|
full_comments << "#{unresolved_alias.comments}\n"
|
|
576
461
|
full_comments << target.comments
|
|
577
462
|
|
|
578
463
|
super(
|
|
464
|
+
unresolved_alias.configuration,
|
|
579
465
|
unresolved_alias.new_name,
|
|
580
466
|
unresolved_alias.uri,
|
|
581
467
|
unresolved_alias.location,
|
|
@@ -583,20 +469,20 @@ module RubyIndexer
|
|
|
583
469
|
)
|
|
584
470
|
|
|
585
471
|
@target = target
|
|
586
|
-
@owner =
|
|
472
|
+
@owner = unresolved_alias.owner #: Entry::Namespace?
|
|
587
473
|
end
|
|
588
474
|
|
|
589
|
-
|
|
475
|
+
#: -> String
|
|
590
476
|
def decorated_parameters
|
|
591
477
|
@target.decorated_parameters
|
|
592
478
|
end
|
|
593
479
|
|
|
594
|
-
|
|
480
|
+
#: -> String
|
|
595
481
|
def formatted_signatures
|
|
596
482
|
@target.formatted_signatures
|
|
597
483
|
end
|
|
598
484
|
|
|
599
|
-
|
|
485
|
+
#: -> Array[Signature]
|
|
600
486
|
def signatures
|
|
601
487
|
@target.signatures
|
|
602
488
|
end
|
|
@@ -606,18 +492,16 @@ module RubyIndexer
|
|
|
606
492
|
# However RBS can represent the concept of method overloading, with different return types based on the arguments
|
|
607
493
|
# passed, so we need to store all the signatures.
|
|
608
494
|
class Signature
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
sig { returns(T::Array[Parameter]) }
|
|
495
|
+
#: Array[Parameter]
|
|
612
496
|
attr_reader :parameters
|
|
613
497
|
|
|
614
|
-
|
|
498
|
+
#: (Array[Parameter] parameters) -> void
|
|
615
499
|
def initialize(parameters)
|
|
616
500
|
@parameters = parameters
|
|
617
501
|
end
|
|
618
502
|
|
|
619
503
|
# Returns a string with the decorated names of the parameters of this member. E.g.: `(a, b = 1, c: 2)`
|
|
620
|
-
|
|
504
|
+
#: -> String
|
|
621
505
|
def format
|
|
622
506
|
@parameters.map(&:decorated_name).join(", ")
|
|
623
507
|
end
|
|
@@ -637,13 +521,13 @@ module RubyIndexer
|
|
|
637
521
|
# foo(1)
|
|
638
522
|
# foo(1, 2)
|
|
639
523
|
# ```
|
|
640
|
-
|
|
524
|
+
#: (Array[Prism::Node] arguments) -> bool
|
|
641
525
|
def matches?(arguments)
|
|
642
526
|
min_pos = 0
|
|
643
|
-
max_pos =
|
|
527
|
+
max_pos = 0 #: (Integer | Float)
|
|
644
528
|
names = []
|
|
645
|
-
has_forward =
|
|
646
|
-
has_keyword_rest =
|
|
529
|
+
has_forward = false #: bool
|
|
530
|
+
has_keyword_rest = false #: bool
|
|
647
531
|
|
|
648
532
|
@parameters.each do |param|
|
|
649
533
|
case param
|
|
@@ -665,7 +549,8 @@ module RubyIndexer
|
|
|
665
549
|
end
|
|
666
550
|
|
|
667
551
|
keyword_hash_nodes, positional_args = arguments.partition { |arg| arg.is_a?(Prism::KeywordHashNode) }
|
|
668
|
-
keyword_args =
|
|
552
|
+
keyword_args = keyword_hash_nodes.first #: as Prism::KeywordHashNode?
|
|
553
|
+
&.elements
|
|
669
554
|
forwarding_arguments, positionals = positional_args.partition do |arg|
|
|
670
555
|
arg.is_a?(Prism::ForwardingArgumentsNode)
|
|
671
556
|
end
|
|
@@ -688,15 +573,7 @@ module RubyIndexer
|
|
|
688
573
|
)
|
|
689
574
|
end
|
|
690
575
|
|
|
691
|
-
|
|
692
|
-
params(
|
|
693
|
-
positional_args: T::Array[Prism::Node],
|
|
694
|
-
forwarding_arguments: T::Array[Prism::Node],
|
|
695
|
-
keyword_args: T.nilable(T::Array[Prism::Node]),
|
|
696
|
-
min_pos: Integer,
|
|
697
|
-
max_pos: T.any(Integer, Float),
|
|
698
|
-
).returns(T::Boolean)
|
|
699
|
-
end
|
|
576
|
+
#: (Array[Prism::Node] positional_args, Array[Prism::Node] forwarding_arguments, Array[Prism::Node]? keyword_args, Integer min_pos, (Integer | Float) max_pos) -> bool
|
|
700
577
|
def positional_arguments_match?(positional_args, forwarding_arguments, keyword_args, min_pos, max_pos)
|
|
701
578
|
# If the method accepts at least one positional argument and a splat has been passed
|
|
702
579
|
(min_pos > 0 && positional_args.any? { |arg| arg.is_a?(Prism::SplatNode) }) ||
|
|
@@ -709,7 +586,7 @@ module RubyIndexer
|
|
|
709
586
|
(min_pos == 0 && positional_args.empty?)
|
|
710
587
|
end
|
|
711
588
|
|
|
712
|
-
|
|
589
|
+
#: (Array[Prism::Node]? args, Array[Symbol] names) -> bool
|
|
713
590
|
def keyword_arguments_match?(args, names)
|
|
714
591
|
return true unless args
|
|
715
592
|
return true if args.any? { |arg| arg.is_a?(Prism::AssocSplatNode) }
|