ruby-lsp 0.23.11 → 0.23.13
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-launcher +12 -11
- data/lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb +1 -1
- data/lib/rubocop/cop/ruby_lsp/use_register_with_handler_method.rb +3 -5
- data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +81 -115
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +117 -166
- data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +9 -7
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +88 -200
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +56 -192
- data/lib/ruby_indexer/lib/ruby_indexer/location.rb +4 -27
- data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +14 -16
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +22 -45
- data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +42 -60
- data/lib/ruby_indexer/lib/ruby_indexer/uri.rb +9 -16
- data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +5 -9
- data/lib/ruby_indexer/test/configuration_test.rb +42 -3
- data/lib/ruby_indexer/test/method_test.rb +28 -2
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +1 -1
- data/lib/ruby_lsp/addon.rb +44 -71
- data/lib/ruby_lsp/base_server.rb +29 -32
- data/lib/ruby_lsp/client_capabilities.rb +10 -12
- data/lib/ruby_lsp/document.rb +34 -45
- data/lib/ruby_lsp/erb_document.rb +24 -36
- data/lib/ruby_lsp/global_state.rb +51 -56
- data/lib/ruby_lsp/internal.rb +2 -0
- data/lib/ruby_lsp/listeners/code_lens.rb +81 -88
- data/lib/ruby_lsp/listeners/completion.rb +36 -55
- data/lib/ruby_lsp/listeners/definition.rb +37 -51
- data/lib/ruby_lsp/listeners/document_highlight.rb +123 -150
- data/lib/ruby_lsp/listeners/document_link.rb +43 -62
- data/lib/ruby_lsp/listeners/document_symbol.rb +35 -49
- data/lib/ruby_lsp/listeners/folding_ranges.rb +32 -39
- data/lib/ruby_lsp/listeners/hover.rb +81 -100
- data/lib/ruby_lsp/listeners/inlay_hints.rb +4 -11
- data/lib/ruby_lsp/listeners/semantic_highlighting.rb +42 -51
- data/lib/ruby_lsp/listeners/signature_help.rb +6 -25
- data/lib/ruby_lsp/listeners/spec_style.rb +155 -0
- data/lib/ruby_lsp/listeners/test_discovery.rb +89 -0
- data/lib/ruby_lsp/listeners/test_style.rb +160 -88
- data/lib/ruby_lsp/node_context.rb +12 -39
- data/lib/ruby_lsp/rbs_document.rb +8 -6
- data/lib/ruby_lsp/requests/code_action_resolve.rb +10 -10
- data/lib/ruby_lsp/requests/code_actions.rb +14 -26
- data/lib/ruby_lsp/requests/code_lens.rb +6 -17
- data/lib/ruby_lsp/requests/completion.rb +7 -20
- data/lib/ruby_lsp/requests/completion_resolve.rb +5 -5
- data/lib/ruby_lsp/requests/definition.rb +8 -17
- data/lib/ruby_lsp/requests/diagnostics.rb +8 -11
- data/lib/ruby_lsp/requests/discover_tests.rb +18 -5
- data/lib/ruby_lsp/requests/document_highlight.rb +5 -15
- 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 +87 -0
- data/lib/ruby_lsp/requests/hover.rb +8 -18
- data/lib/ruby_lsp/requests/inlay_hints.rb +6 -17
- data/lib/ruby_lsp/requests/on_type_formatting.rb +28 -38
- data/lib/ruby_lsp/requests/prepare_rename.rb +4 -9
- data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +4 -13
- data/lib/ruby_lsp/requests/range_formatting.rb +5 -6
- data/lib/ruby_lsp/requests/references.rb +6 -36
- data/lib/ruby_lsp/requests/rename.rb +11 -37
- data/lib/ruby_lsp/requests/request.rb +7 -19
- data/lib/ruby_lsp/requests/selection_ranges.rb +5 -5
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +12 -31
- data/lib/ruby_lsp/requests/show_syntax_tree.rb +5 -6
- data/lib/ruby_lsp/requests/signature_help.rb +8 -26
- data/lib/ruby_lsp/requests/support/annotation.rb +4 -10
- data/lib/ruby_lsp/requests/support/common.rb +13 -50
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +27 -35
- data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +9 -12
- data/lib/ruby_lsp/requests/support/rubocop_runner.rb +22 -34
- 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 +16 -30
- data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +12 -19
- data/lib/ruby_lsp/requests/support/test_item.rb +10 -14
- data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +5 -6
- data/lib/ruby_lsp/requests/workspace_symbol.rb +4 -4
- data/lib/ruby_lsp/response_builders/collection_response_builder.rb +5 -5
- data/lib/ruby_lsp/response_builders/document_symbol.rb +10 -16
- data/lib/ruby_lsp/response_builders/hover.rb +10 -13
- data/lib/ruby_lsp/response_builders/response_builder.rb +1 -1
- data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +59 -87
- data/lib/ruby_lsp/response_builders/signature_help.rb +5 -6
- data/lib/ruby_lsp/response_builders/test_collection.rb +6 -10
- data/lib/ruby_lsp/ruby_document.rb +22 -60
- data/lib/ruby_lsp/ruby_lsp_reporter_plugin.rb +109 -0
- data/lib/ruby_lsp/scope.rb +7 -11
- data/lib/ruby_lsp/server.rb +133 -74
- data/lib/ruby_lsp/setup_bundler.rb +58 -57
- data/lib/ruby_lsp/static_docs.rb +4 -7
- data/lib/ruby_lsp/store.rb +21 -40
- data/lib/ruby_lsp/test_helper.rb +3 -12
- data/lib/ruby_lsp/test_reporter.rb +207 -0
- data/lib/ruby_lsp/test_unit_test_runner.rb +98 -0
- data/lib/ruby_lsp/type_inferrer.rb +9 -13
- data/lib/ruby_lsp/utils.rb +37 -81
- metadata +9 -3
@@ -3,48 +3,34 @@
|
|
3
3
|
|
4
4
|
module RubyIndexer
|
5
5
|
class DeclarationListener
|
6
|
-
|
6
|
+
OBJECT_NESTING = ["Object"].freeze #: Array[String]
|
7
|
+
BASIC_OBJECT_NESTING = ["BasicObject"].freeze #: Array[String]
|
7
8
|
|
8
|
-
|
9
|
-
BASIC_OBJECT_NESTING = T.let(["BasicObject"].freeze, T::Array[String])
|
10
|
-
|
11
|
-
sig { returns(T::Array[String]) }
|
9
|
+
#: Array[String]
|
12
10
|
attr_reader :indexing_errors
|
13
11
|
|
14
|
-
|
15
|
-
params(
|
16
|
-
index: Index,
|
17
|
-
dispatcher: Prism::Dispatcher,
|
18
|
-
parse_result: Prism::ParseResult,
|
19
|
-
uri: URI::Generic,
|
20
|
-
collect_comments: T::Boolean,
|
21
|
-
).void
|
22
|
-
end
|
12
|
+
#: (Index index, Prism::Dispatcher dispatcher, Prism::ParseResult parse_result, URI::Generic uri, ?collect_comments: bool) -> void
|
23
13
|
def initialize(index, dispatcher, parse_result, uri, collect_comments: false)
|
24
14
|
@index = index
|
25
15
|
@uri = uri
|
26
|
-
@enhancements =
|
27
|
-
@visibility_stack =
|
28
|
-
@comments_by_line =
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@
|
36
|
-
parse_result.code_units_cache(@index.configuration.encoding),
|
37
|
-
T.any(T.proc.params(arg0: Integer).returns(Integer), Prism::CodeUnitsCache),
|
38
|
-
)
|
39
|
-
@source_lines = T.let(parse_result.source.lines, T::Array[String])
|
16
|
+
@enhancements = Enhancement.all(self) #: Array[Enhancement]
|
17
|
+
@visibility_stack = [VisibilityScope.public_scope] #: Array[VisibilityScope]
|
18
|
+
@comments_by_line = parse_result.comments.to_h do |c|
|
19
|
+
[c.location.start_line, c]
|
20
|
+
end #: Hash[Integer, Prism::Comment]
|
21
|
+
@inside_def = false #: bool
|
22
|
+
@code_units_cache = parse_result
|
23
|
+
.code_units_cache(@index.configuration.encoding) #: (^(Integer arg0) -> Integer | Prism::CodeUnitsCache)
|
24
|
+
|
25
|
+
@source_lines = parse_result.source.lines #: Array[String]
|
40
26
|
|
41
27
|
# The nesting stack we're currently inside. Used to determine the fully qualified name of constants, but only
|
42
28
|
# stored by unresolved aliases which need the original nesting to be lazily resolved
|
43
|
-
@stack =
|
29
|
+
@stack = [] #: Array[String]
|
44
30
|
|
45
31
|
# A stack of namespace entries that represent where we currently are. Used to properly assign methods to an owner
|
46
|
-
@owner_stack =
|
47
|
-
@indexing_errors =
|
32
|
+
@owner_stack = [] #: Array[Entry::Namespace]
|
33
|
+
@indexing_errors = [] #: Array[String]
|
48
34
|
@collect_comments = collect_comments
|
49
35
|
|
50
36
|
dispatcher.register(
|
@@ -87,7 +73,7 @@ module RubyIndexer
|
|
87
73
|
)
|
88
74
|
end
|
89
75
|
|
90
|
-
|
76
|
+
#: (Prism::ClassNode node) -> void
|
91
77
|
def on_class_node_enter(node)
|
92
78
|
constant_path = node.constant_path
|
93
79
|
superclass = node.superclass
|
@@ -119,23 +105,23 @@ module RubyIndexer
|
|
119
105
|
)
|
120
106
|
end
|
121
107
|
|
122
|
-
|
108
|
+
#: (Prism::ClassNode node) -> void
|
123
109
|
def on_class_node_leave(node)
|
124
110
|
pop_namespace_stack
|
125
111
|
end
|
126
112
|
|
127
|
-
|
113
|
+
#: (Prism::ModuleNode node) -> void
|
128
114
|
def on_module_node_enter(node)
|
129
115
|
constant_path = node.constant_path
|
130
116
|
add_module(constant_path.slice, node.location, constant_path.location, comments: collect_comments(node))
|
131
117
|
end
|
132
118
|
|
133
|
-
|
119
|
+
#: (Prism::ModuleNode node) -> void
|
134
120
|
def on_module_node_leave(node)
|
135
121
|
pop_namespace_stack
|
136
122
|
end
|
137
123
|
|
138
|
-
|
124
|
+
#: (Prism::SingletonClassNode node) -> void
|
139
125
|
def on_singleton_class_node_enter(node)
|
140
126
|
@visibility_stack.push(VisibilityScope.public_scope)
|
141
127
|
|
@@ -172,12 +158,12 @@ module RubyIndexer
|
|
172
158
|
end
|
173
159
|
end
|
174
160
|
|
175
|
-
|
161
|
+
#: (Prism::SingletonClassNode node) -> void
|
176
162
|
def on_singleton_class_node_leave(node)
|
177
163
|
pop_namespace_stack
|
178
164
|
end
|
179
165
|
|
180
|
-
|
166
|
+
#: (Prism::MultiWriteNode node) -> void
|
181
167
|
def on_multi_write_node_enter(node)
|
182
168
|
value = node.value
|
183
169
|
values = value.is_a?(Prism::ArrayNode) && value.opening_loc ? value.elements : []
|
@@ -197,7 +183,7 @@ module RubyIndexer
|
|
197
183
|
end
|
198
184
|
end
|
199
185
|
|
200
|
-
|
186
|
+
#: (Prism::ConstantPathWriteNode node) -> void
|
201
187
|
def on_constant_path_write_node_enter(node)
|
202
188
|
# ignore variable constants like `var::FOO` or `self.class::FOO`
|
203
189
|
target = node.target
|
@@ -207,7 +193,7 @@ module RubyIndexer
|
|
207
193
|
add_constant(node, name)
|
208
194
|
end
|
209
195
|
|
210
|
-
|
196
|
+
#: (Prism::ConstantPathOrWriteNode node) -> void
|
211
197
|
def on_constant_path_or_write_node_enter(node)
|
212
198
|
# ignore variable constants like `var::FOO` or `self.class::FOO`
|
213
199
|
target = node.target
|
@@ -217,7 +203,7 @@ module RubyIndexer
|
|
217
203
|
add_constant(node, name)
|
218
204
|
end
|
219
205
|
|
220
|
-
|
206
|
+
#: (Prism::ConstantPathOperatorWriteNode node) -> void
|
221
207
|
def on_constant_path_operator_write_node_enter(node)
|
222
208
|
# ignore variable constants like `var::FOO` or `self.class::FOO`
|
223
209
|
target = node.target
|
@@ -227,7 +213,7 @@ module RubyIndexer
|
|
227
213
|
add_constant(node, name)
|
228
214
|
end
|
229
215
|
|
230
|
-
|
216
|
+
#: (Prism::ConstantPathAndWriteNode node) -> void
|
231
217
|
def on_constant_path_and_write_node_enter(node)
|
232
218
|
# ignore variable constants like `var::FOO` or `self.class::FOO`
|
233
219
|
target = node.target
|
@@ -237,31 +223,31 @@ module RubyIndexer
|
|
237
223
|
add_constant(node, name)
|
238
224
|
end
|
239
225
|
|
240
|
-
|
226
|
+
#: (Prism::ConstantWriteNode node) -> void
|
241
227
|
def on_constant_write_node_enter(node)
|
242
228
|
name = fully_qualify_name(node.name.to_s)
|
243
229
|
add_constant(node, name)
|
244
230
|
end
|
245
231
|
|
246
|
-
|
232
|
+
#: (Prism::ConstantOrWriteNode node) -> void
|
247
233
|
def on_constant_or_write_node_enter(node)
|
248
234
|
name = fully_qualify_name(node.name.to_s)
|
249
235
|
add_constant(node, name)
|
250
236
|
end
|
251
237
|
|
252
|
-
|
238
|
+
#: (Prism::ConstantAndWriteNode node) -> void
|
253
239
|
def on_constant_and_write_node_enter(node)
|
254
240
|
name = fully_qualify_name(node.name.to_s)
|
255
241
|
add_constant(node, name)
|
256
242
|
end
|
257
243
|
|
258
|
-
|
244
|
+
#: (Prism::ConstantOperatorWriteNode node) -> void
|
259
245
|
def on_constant_operator_write_node_enter(node)
|
260
246
|
name = fully_qualify_name(node.name.to_s)
|
261
247
|
add_constant(node, name)
|
262
248
|
end
|
263
249
|
|
264
|
-
|
250
|
+
#: (Prism::CallNode node) -> void
|
265
251
|
def on_call_node_enter(node)
|
266
252
|
message = node.name
|
267
253
|
|
@@ -279,11 +265,11 @@ module RubyIndexer
|
|
279
265
|
when :include, :prepend, :extend
|
280
266
|
handle_module_operation(node, message)
|
281
267
|
when :public
|
282
|
-
|
268
|
+
handle_visibility_change(node, Entry::Visibility::PUBLIC)
|
283
269
|
when :protected
|
284
|
-
|
270
|
+
handle_visibility_change(node, Entry::Visibility::PROTECTED)
|
285
271
|
when :private
|
286
|
-
|
272
|
+
handle_visibility_change(node, Entry::Visibility::PRIVATE)
|
287
273
|
when :module_function
|
288
274
|
handle_module_function(node)
|
289
275
|
when :private_class_method
|
@@ -299,7 +285,7 @@ module RubyIndexer
|
|
299
285
|
end
|
300
286
|
end
|
301
287
|
|
302
|
-
|
288
|
+
#: (Prism::CallNode node) -> void
|
303
289
|
def on_call_node_leave(node)
|
304
290
|
message = node.name
|
305
291
|
case message
|
@@ -320,7 +306,7 @@ module RubyIndexer
|
|
320
306
|
end
|
321
307
|
end
|
322
308
|
|
323
|
-
|
309
|
+
#: (Prism::DefNode node) -> void
|
324
310
|
def on_def_node_enter(node)
|
325
311
|
owner = @owner_stack.last
|
326
312
|
return unless owner
|
@@ -379,7 +365,7 @@ module RubyIndexer
|
|
379
365
|
end
|
380
366
|
end
|
381
367
|
|
382
|
-
|
368
|
+
#: (Prism::DefNode node) -> void
|
383
369
|
def on_def_node_leave(node)
|
384
370
|
@inside_def = false
|
385
371
|
|
@@ -388,57 +374,57 @@ module RubyIndexer
|
|
388
374
|
end
|
389
375
|
end
|
390
376
|
|
391
|
-
|
377
|
+
#: (Prism::GlobalVariableAndWriteNode node) -> void
|
392
378
|
def on_global_variable_and_write_node_enter(node)
|
393
379
|
handle_global_variable(node, node.name_loc)
|
394
380
|
end
|
395
381
|
|
396
|
-
|
382
|
+
#: (Prism::GlobalVariableOperatorWriteNode node) -> void
|
397
383
|
def on_global_variable_operator_write_node_enter(node)
|
398
384
|
handle_global_variable(node, node.name_loc)
|
399
385
|
end
|
400
386
|
|
401
|
-
|
387
|
+
#: (Prism::GlobalVariableOrWriteNode node) -> void
|
402
388
|
def on_global_variable_or_write_node_enter(node)
|
403
389
|
handle_global_variable(node, node.name_loc)
|
404
390
|
end
|
405
391
|
|
406
|
-
|
392
|
+
#: (Prism::GlobalVariableTargetNode node) -> void
|
407
393
|
def on_global_variable_target_node_enter(node)
|
408
394
|
handle_global_variable(node, node.location)
|
409
395
|
end
|
410
396
|
|
411
|
-
|
397
|
+
#: (Prism::GlobalVariableWriteNode node) -> void
|
412
398
|
def on_global_variable_write_node_enter(node)
|
413
399
|
handle_global_variable(node, node.name_loc)
|
414
400
|
end
|
415
401
|
|
416
|
-
|
402
|
+
#: (Prism::InstanceVariableWriteNode node) -> void
|
417
403
|
def on_instance_variable_write_node_enter(node)
|
418
404
|
handle_instance_variable(node, node.name_loc)
|
419
405
|
end
|
420
406
|
|
421
|
-
|
407
|
+
#: (Prism::InstanceVariableAndWriteNode node) -> void
|
422
408
|
def on_instance_variable_and_write_node_enter(node)
|
423
409
|
handle_instance_variable(node, node.name_loc)
|
424
410
|
end
|
425
411
|
|
426
|
-
|
412
|
+
#: (Prism::InstanceVariableOperatorWriteNode node) -> void
|
427
413
|
def on_instance_variable_operator_write_node_enter(node)
|
428
414
|
handle_instance_variable(node, node.name_loc)
|
429
415
|
end
|
430
416
|
|
431
|
-
|
417
|
+
#: (Prism::InstanceVariableOrWriteNode node) -> void
|
432
418
|
def on_instance_variable_or_write_node_enter(node)
|
433
419
|
handle_instance_variable(node, node.name_loc)
|
434
420
|
end
|
435
421
|
|
436
|
-
|
422
|
+
#: (Prism::InstanceVariableTargetNode node) -> void
|
437
423
|
def on_instance_variable_target_node_enter(node)
|
438
424
|
handle_instance_variable(node, node.location)
|
439
425
|
end
|
440
426
|
|
441
|
-
|
427
|
+
#: (Prism::AliasMethodNode node) -> void
|
442
428
|
def on_alias_method_node_enter(node)
|
443
429
|
method_name = node.new_name.slice
|
444
430
|
comments = collect_comments(node)
|
@@ -454,40 +440,32 @@ module RubyIndexer
|
|
454
440
|
)
|
455
441
|
end
|
456
442
|
|
457
|
-
|
443
|
+
#: (Prism::ClassVariableAndWriteNode node) -> void
|
458
444
|
def on_class_variable_and_write_node_enter(node)
|
459
445
|
handle_class_variable(node, node.name_loc)
|
460
446
|
end
|
461
447
|
|
462
|
-
|
448
|
+
#: (Prism::ClassVariableOperatorWriteNode node) -> void
|
463
449
|
def on_class_variable_operator_write_node_enter(node)
|
464
450
|
handle_class_variable(node, node.name_loc)
|
465
451
|
end
|
466
452
|
|
467
|
-
|
453
|
+
#: (Prism::ClassVariableOrWriteNode node) -> void
|
468
454
|
def on_class_variable_or_write_node_enter(node)
|
469
455
|
handle_class_variable(node, node.name_loc)
|
470
456
|
end
|
471
457
|
|
472
|
-
|
458
|
+
#: (Prism::ClassVariableTargetNode node) -> void
|
473
459
|
def on_class_variable_target_node_enter(node)
|
474
460
|
handle_class_variable(node, node.location)
|
475
461
|
end
|
476
462
|
|
477
|
-
|
463
|
+
#: (Prism::ClassVariableWriteNode node) -> void
|
478
464
|
def on_class_variable_write_node_enter(node)
|
479
465
|
handle_class_variable(node, node.name_loc)
|
480
466
|
end
|
481
467
|
|
482
|
-
|
483
|
-
params(
|
484
|
-
name: String,
|
485
|
-
node_location: Prism::Location,
|
486
|
-
signatures: T::Array[Entry::Signature],
|
487
|
-
visibility: Entry::Visibility,
|
488
|
-
comments: T.nilable(String),
|
489
|
-
).void
|
490
|
-
end
|
468
|
+
#: (String name, Prism::Location node_location, Array[Entry::Signature] signatures, ?visibility: Entry::Visibility, ?comments: String?) -> void
|
491
469
|
def add_method(name, node_location, signatures, visibility: Entry::Visibility::PUBLIC, comments: nil)
|
492
470
|
location = Location.from_prism_location(node_location, @code_units_cache)
|
493
471
|
|
@@ -503,14 +481,7 @@ module RubyIndexer
|
|
503
481
|
))
|
504
482
|
end
|
505
483
|
|
506
|
-
|
507
|
-
params(
|
508
|
-
name: String,
|
509
|
-
full_location: Prism::Location,
|
510
|
-
name_location: Prism::Location,
|
511
|
-
comments: T.nilable(String),
|
512
|
-
).void
|
513
|
-
end
|
484
|
+
#: (String name, Prism::Location full_location, Prism::Location name_location, ?comments: String?) -> void
|
514
485
|
def add_module(name, full_location, name_location, comments: nil)
|
515
486
|
location = Location.from_prism_location(full_location, @code_units_cache)
|
516
487
|
name_loc = Location.from_prism_location(name_location, @code_units_cache)
|
@@ -526,15 +497,7 @@ module RubyIndexer
|
|
526
497
|
advance_namespace_stack(name, entry)
|
527
498
|
end
|
528
499
|
|
529
|
-
|
530
|
-
params(
|
531
|
-
name_or_nesting: T.any(String, T::Array[String]),
|
532
|
-
full_location: Prism::Location,
|
533
|
-
name_location: Prism::Location,
|
534
|
-
parent_class_name: T.nilable(String),
|
535
|
-
comments: T.nilable(String),
|
536
|
-
).void
|
537
|
-
end
|
500
|
+
#: ((String | Array[String]) name_or_nesting, Prism::Location full_location, Prism::Location name_location, ?parent_class_name: String?, ?comments: String?) -> void
|
538
501
|
def add_class(name_or_nesting, full_location, name_location, parent_class_name: nil, comments: nil)
|
539
502
|
nesting = name_or_nesting.is_a?(Array) ? name_or_nesting : Index.actual_nesting(@stack, name_or_nesting)
|
540
503
|
entry = Entry::Class.new(
|
@@ -549,7 +512,7 @@ module RubyIndexer
|
|
549
512
|
advance_namespace_stack(T.must(nesting.last), entry)
|
550
513
|
end
|
551
514
|
|
552
|
-
|
515
|
+
#: { (Index index, Entry::Namespace base) -> void } -> void
|
553
516
|
def register_included_hook(&block)
|
554
517
|
owner = @owner_stack.last
|
555
518
|
return unless owner
|
@@ -559,32 +522,21 @@ module RubyIndexer
|
|
559
522
|
end
|
560
523
|
end
|
561
524
|
|
562
|
-
|
525
|
+
#: -> void
|
563
526
|
def pop_namespace_stack
|
564
527
|
@stack.pop
|
565
528
|
@owner_stack.pop
|
566
529
|
@visibility_stack.pop
|
567
530
|
end
|
568
531
|
|
569
|
-
|
532
|
+
#: -> Entry::Namespace?
|
570
533
|
def current_owner
|
571
534
|
@owner_stack.last
|
572
535
|
end
|
573
536
|
|
574
537
|
private
|
575
538
|
|
576
|
-
|
577
|
-
params(
|
578
|
-
node: T.any(
|
579
|
-
Prism::GlobalVariableAndWriteNode,
|
580
|
-
Prism::GlobalVariableOperatorWriteNode,
|
581
|
-
Prism::GlobalVariableOrWriteNode,
|
582
|
-
Prism::GlobalVariableTargetNode,
|
583
|
-
Prism::GlobalVariableWriteNode,
|
584
|
-
),
|
585
|
-
loc: Prism::Location,
|
586
|
-
).void
|
587
|
-
end
|
539
|
+
#: ((Prism::GlobalVariableAndWriteNode | Prism::GlobalVariableOperatorWriteNode | Prism::GlobalVariableOrWriteNode | Prism::GlobalVariableTargetNode | Prism::GlobalVariableWriteNode) node, Prism::Location loc) -> void
|
588
540
|
def handle_global_variable(node, loc)
|
589
541
|
name = node.name.to_s
|
590
542
|
comments = collect_comments(node)
|
@@ -597,18 +549,7 @@ module RubyIndexer
|
|
597
549
|
))
|
598
550
|
end
|
599
551
|
|
600
|
-
|
601
|
-
params(
|
602
|
-
node: T.any(
|
603
|
-
Prism::ClassVariableAndWriteNode,
|
604
|
-
Prism::ClassVariableOperatorWriteNode,
|
605
|
-
Prism::ClassVariableOrWriteNode,
|
606
|
-
Prism::ClassVariableTargetNode,
|
607
|
-
Prism::ClassVariableWriteNode,
|
608
|
-
),
|
609
|
-
loc: Prism::Location,
|
610
|
-
).void
|
611
|
-
end
|
552
|
+
#: ((Prism::ClassVariableAndWriteNode | Prism::ClassVariableOperatorWriteNode | Prism::ClassVariableOrWriteNode | Prism::ClassVariableTargetNode | Prism::ClassVariableWriteNode) node, Prism::Location loc) -> void
|
612
553
|
def handle_class_variable(node, loc)
|
613
554
|
name = node.name.to_s
|
614
555
|
# Ignore incomplete class variable names, which aren't valid Ruby syntax.
|
@@ -633,18 +574,7 @@ module RubyIndexer
|
|
633
574
|
))
|
634
575
|
end
|
635
576
|
|
636
|
-
|
637
|
-
params(
|
638
|
-
node: T.any(
|
639
|
-
Prism::InstanceVariableAndWriteNode,
|
640
|
-
Prism::InstanceVariableOperatorWriteNode,
|
641
|
-
Prism::InstanceVariableOrWriteNode,
|
642
|
-
Prism::InstanceVariableTargetNode,
|
643
|
-
Prism::InstanceVariableWriteNode,
|
644
|
-
),
|
645
|
-
loc: Prism::Location,
|
646
|
-
).void
|
647
|
-
end
|
577
|
+
#: ((Prism::InstanceVariableAndWriteNode | Prism::InstanceVariableOperatorWriteNode | Prism::InstanceVariableOrWriteNode | Prism::InstanceVariableTargetNode | Prism::InstanceVariableWriteNode) node, Prism::Location loc) -> void
|
648
578
|
def handle_instance_variable(node, loc)
|
649
579
|
name = node.name.to_s
|
650
580
|
return if name == "@"
|
@@ -666,7 +596,7 @@ module RubyIndexer
|
|
666
596
|
))
|
667
597
|
end
|
668
598
|
|
669
|
-
|
599
|
+
#: (Prism::CallNode node) -> void
|
670
600
|
def handle_private_constant(node)
|
671
601
|
arguments = node.arguments&.arguments
|
672
602
|
return unless arguments
|
@@ -691,7 +621,7 @@ module RubyIndexer
|
|
691
621
|
entries&.each { |entry| entry.visibility = Entry::Visibility::PRIVATE }
|
692
622
|
end
|
693
623
|
|
694
|
-
|
624
|
+
#: (Prism::CallNode node) -> void
|
695
625
|
def handle_alias_method(node)
|
696
626
|
arguments = node.arguments&.arguments
|
697
627
|
return unless arguments
|
@@ -730,24 +660,7 @@ module RubyIndexer
|
|
730
660
|
)
|
731
661
|
end
|
732
662
|
|
733
|
-
|
734
|
-
params(
|
735
|
-
node: T.any(
|
736
|
-
Prism::ConstantWriteNode,
|
737
|
-
Prism::ConstantOrWriteNode,
|
738
|
-
Prism::ConstantAndWriteNode,
|
739
|
-
Prism::ConstantOperatorWriteNode,
|
740
|
-
Prism::ConstantPathWriteNode,
|
741
|
-
Prism::ConstantPathOrWriteNode,
|
742
|
-
Prism::ConstantPathOperatorWriteNode,
|
743
|
-
Prism::ConstantPathAndWriteNode,
|
744
|
-
Prism::ConstantTargetNode,
|
745
|
-
Prism::ConstantPathTargetNode,
|
746
|
-
),
|
747
|
-
name: String,
|
748
|
-
value: T.nilable(Prism::Node),
|
749
|
-
).void
|
750
|
-
end
|
663
|
+
#: ((Prism::ConstantWriteNode | Prism::ConstantOrWriteNode | Prism::ConstantAndWriteNode | Prism::ConstantOperatorWriteNode | Prism::ConstantPathWriteNode | Prism::ConstantPathOrWriteNode | Prism::ConstantPathOperatorWriteNode | Prism::ConstantPathAndWriteNode | Prism::ConstantTargetNode | Prism::ConstantPathTargetNode) node, String name, ?Prism::Node? value) -> void
|
751
664
|
def add_constant(node, name, value = nil)
|
752
665
|
value = node.value unless node.is_a?(Prism::ConstantTargetNode) || node.is_a?(Prism::ConstantPathTargetNode)
|
753
666
|
comments = collect_comments(node)
|
@@ -798,7 +711,7 @@ module RubyIndexer
|
|
798
711
|
)
|
799
712
|
end
|
800
713
|
|
801
|
-
|
714
|
+
#: (Prism::Node node) -> String?
|
802
715
|
def collect_comments(node)
|
803
716
|
return unless @collect_comments
|
804
717
|
|
@@ -826,12 +739,12 @@ module RubyIndexer
|
|
826
739
|
comments
|
827
740
|
end
|
828
741
|
|
829
|
-
|
742
|
+
#: (Integer line) -> bool
|
830
743
|
def comment_exists_at?(line)
|
831
744
|
@comments_by_line.key?(line) || !@source_lines[line - 1].to_s.strip.empty?
|
832
745
|
end
|
833
746
|
|
834
|
-
|
747
|
+
#: (String name) -> String
|
835
748
|
def fully_qualify_name(name)
|
836
749
|
if @stack.empty? || name.start_with?("::")
|
837
750
|
name
|
@@ -840,7 +753,7 @@ module RubyIndexer
|
|
840
753
|
end.delete_prefix("::")
|
841
754
|
end
|
842
755
|
|
843
|
-
|
756
|
+
#: (Prism::CallNode node, reader: bool, writer: bool) -> void
|
844
757
|
def handle_attribute(node, reader:, writer:)
|
845
758
|
arguments = node.arguments&.arguments
|
846
759
|
return unless arguments
|
@@ -885,7 +798,7 @@ module RubyIndexer
|
|
885
798
|
end
|
886
799
|
end
|
887
800
|
|
888
|
-
|
801
|
+
#: (Prism::CallNode node, Symbol operation) -> void
|
889
802
|
def handle_module_operation(node, operation)
|
890
803
|
return if @inside_def
|
891
804
|
|
@@ -919,7 +832,7 @@ module RubyIndexer
|
|
919
832
|
end
|
920
833
|
end
|
921
834
|
|
922
|
-
|
835
|
+
#: (Prism::CallNode node) -> void
|
923
836
|
def handle_module_function(node)
|
924
837
|
# Invoking `module_function` in a class raises
|
925
838
|
owner = @owner_stack.last
|
@@ -970,7 +883,7 @@ module RubyIndexer
|
|
970
883
|
end
|
971
884
|
end
|
972
885
|
|
973
|
-
|
886
|
+
#: (Prism::CallNode node) -> void
|
974
887
|
def handle_private_class_method(node)
|
975
888
|
arguments = node.arguments&.arguments
|
976
889
|
return unless arguments
|
@@ -1012,12 +925,12 @@ module RubyIndexer
|
|
1012
925
|
end
|
1013
926
|
end
|
1014
927
|
|
1015
|
-
|
928
|
+
#: -> VisibilityScope
|
1016
929
|
def current_visibility_scope
|
1017
930
|
T.must(@visibility_stack.last)
|
1018
931
|
end
|
1019
932
|
|
1020
|
-
|
933
|
+
#: (Prism::ParametersNode? parameters_node) -> Array[Entry::Parameter]
|
1021
934
|
def list_params(parameters_node)
|
1022
935
|
return [] unless parameters_node
|
1023
936
|
|
@@ -1079,7 +992,7 @@ module RubyIndexer
|
|
1079
992
|
parameters
|
1080
993
|
end
|
1081
994
|
|
1082
|
-
|
995
|
+
#: (Prism::Node? node) -> Symbol?
|
1083
996
|
def parameter_name(node)
|
1084
997
|
case node
|
1085
998
|
when Prism::RequiredParameterNode, Prism::OptionalParameterNode,
|
@@ -1104,7 +1017,7 @@ module RubyIndexer
|
|
1104
1017
|
end
|
1105
1018
|
end
|
1106
1019
|
|
1107
|
-
|
1020
|
+
#: (String short_name, Entry::Namespace entry) -> void
|
1108
1021
|
def advance_namespace_stack(short_name, entry)
|
1109
1022
|
@visibility_stack.push(VisibilityScope.public_scope)
|
1110
1023
|
@owner_stack << entry
|
@@ -1114,12 +1027,50 @@ module RubyIndexer
|
|
1114
1027
|
|
1115
1028
|
# Returns the last name in the stack not as we found it, but in terms of declared constants. For example, if the
|
1116
1029
|
# last entry in the stack is a compact namespace like `Foo::Bar`, then the last name is `Bar`
|
1117
|
-
|
1030
|
+
#: -> String?
|
1118
1031
|
def last_name_in_stack
|
1119
1032
|
name = @stack.last
|
1120
1033
|
return unless name
|
1121
1034
|
|
1122
1035
|
name.split("::").last
|
1123
1036
|
end
|
1037
|
+
|
1038
|
+
#: (Prism::CallNode, Entry::Visibility) -> void
|
1039
|
+
def handle_visibility_change(node, visibility)
|
1040
|
+
owner = @owner_stack.last
|
1041
|
+
return unless owner
|
1042
|
+
|
1043
|
+
owner_name = owner.name
|
1044
|
+
method_names = string_or_symbol_argument_values(node)
|
1045
|
+
|
1046
|
+
if method_names.empty?
|
1047
|
+
@visibility_stack.push(VisibilityScope.new(visibility: visibility))
|
1048
|
+
return
|
1049
|
+
end
|
1050
|
+
|
1051
|
+
method_names.each do |method_name|
|
1052
|
+
entries = @index.resolve_method(method_name, owner_name)
|
1053
|
+
next unless entries
|
1054
|
+
|
1055
|
+
entries.each do |entry|
|
1056
|
+
entry.visibility = visibility
|
1057
|
+
end
|
1058
|
+
end
|
1059
|
+
end
|
1060
|
+
|
1061
|
+
#: (Prism::CallNode) -> Array[String]
|
1062
|
+
def string_or_symbol_argument_values(node)
|
1063
|
+
arguments = node.arguments&.arguments
|
1064
|
+
return [] unless arguments
|
1065
|
+
|
1066
|
+
arguments.filter_map do |argument|
|
1067
|
+
case argument
|
1068
|
+
when Prism::StringNode
|
1069
|
+
argument.content
|
1070
|
+
when Prism::SymbolNode
|
1071
|
+
argument.value
|
1072
|
+
end
|
1073
|
+
end
|
1074
|
+
end
|
1124
1075
|
end
|
1125
1076
|
end
|