ruby-lsp 0.22.1 → 0.23.10
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 +12 -11
- data/exe/ruby-lsp-check +5 -5
- data/exe/ruby-lsp-launcher +41 -15
- data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +26 -20
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +191 -100
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +60 -30
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +174 -61
- data/lib/ruby_indexer/lib/ruby_indexer/location.rb +12 -0
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +16 -14
- data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +82 -61
- data/lib/{core_ext → ruby_indexer/lib/ruby_indexer}/uri.rb +29 -3
- data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +36 -0
- data/lib/ruby_indexer/ruby_indexer.rb +2 -1
- data/lib/ruby_indexer/test/class_variables_test.rb +140 -0
- data/lib/ruby_indexer/test/classes_and_modules_test.rb +30 -6
- data/lib/ruby_indexer/test/configuration_test.rb +116 -51
- data/lib/ruby_indexer/test/enhancements_test.rb +2 -2
- data/lib/ruby_indexer/test/index_test.rb +143 -44
- data/lib/ruby_indexer/test/instance_variables_test.rb +20 -0
- data/lib/ruby_indexer/test/method_test.rb +86 -8
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +1 -1
- data/lib/ruby_indexer/test/reference_finder_test.rb +90 -2
- data/lib/ruby_indexer/test/test_case.rb +2 -2
- data/lib/ruby_indexer/test/uri_test.rb +72 -0
- data/lib/ruby_lsp/addon.rb +9 -0
- data/lib/ruby_lsp/base_server.rb +17 -18
- data/lib/ruby_lsp/client_capabilities.rb +7 -1
- data/lib/ruby_lsp/document.rb +72 -10
- data/lib/ruby_lsp/erb_document.rb +5 -3
- data/lib/ruby_lsp/global_state.rb +42 -3
- data/lib/ruby_lsp/internal.rb +3 -1
- data/lib/ruby_lsp/listeners/code_lens.rb +9 -5
- data/lib/ruby_lsp/listeners/completion.rb +78 -6
- data/lib/ruby_lsp/listeners/definition.rb +80 -19
- data/lib/ruby_lsp/listeners/document_highlight.rb +3 -2
- data/lib/ruby_lsp/listeners/document_link.rb +21 -3
- data/lib/ruby_lsp/listeners/document_symbol.rb +12 -1
- data/lib/ruby_lsp/listeners/folding_ranges.rb +1 -1
- data/lib/ruby_lsp/listeners/hover.rb +59 -2
- data/lib/ruby_lsp/load_sorbet.rb +3 -3
- data/lib/ruby_lsp/rbs_document.rb +2 -2
- data/lib/ruby_lsp/requests/code_action_resolve.rb +90 -6
- data/lib/ruby_lsp/requests/code_actions.rb +57 -1
- data/lib/ruby_lsp/requests/completion.rb +8 -1
- data/lib/ruby_lsp/requests/completion_resolve.rb +2 -1
- data/lib/ruby_lsp/requests/definition.rb +7 -1
- data/lib/ruby_lsp/requests/diagnostics.rb +1 -1
- data/lib/ruby_lsp/requests/document_highlight.rb +1 -1
- data/lib/ruby_lsp/requests/folding_ranges.rb +2 -6
- data/lib/ruby_lsp/requests/formatting.rb +2 -6
- data/lib/ruby_lsp/requests/hover.rb +1 -1
- data/lib/ruby_lsp/requests/on_type_formatting.rb +2 -2
- data/lib/ruby_lsp/requests/prepare_rename.rb +51 -0
- data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +1 -1
- data/lib/ruby_lsp/requests/references.rb +29 -2
- data/lib/ruby_lsp/requests/rename.rb +17 -7
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +1 -1
- data/lib/ruby_lsp/requests/show_syntax_tree.rb +1 -4
- data/lib/ruby_lsp/requests/signature_help.rb +1 -1
- data/lib/ruby_lsp/requests/support/common.rb +2 -9
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +3 -3
- data/lib/ruby_lsp/requests/support/rubocop_runner.rb +13 -13
- data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +1 -1
- data/lib/ruby_lsp/requests/workspace_symbol.rb +4 -3
- data/lib/ruby_lsp/ruby_document.rb +80 -6
- data/lib/ruby_lsp/scripts/compose_bundle.rb +1 -1
- data/lib/ruby_lsp/server.rb +205 -61
- data/lib/ruby_lsp/setup_bundler.rb +50 -43
- data/lib/ruby_lsp/store.rb +7 -7
- data/lib/ruby_lsp/test_helper.rb +45 -11
- data/lib/ruby_lsp/type_inferrer.rb +60 -31
- data/lib/ruby_lsp/utils.rb +63 -3
- metadata +8 -8
- data/lib/ruby_indexer/lib/ruby_indexer/indexable_path.rb +0 -29
@@ -16,15 +16,15 @@ module RubyIndexer
|
|
16
16
|
index: Index,
|
17
17
|
dispatcher: Prism::Dispatcher,
|
18
18
|
parse_result: Prism::ParseResult,
|
19
|
-
|
19
|
+
uri: URI::Generic,
|
20
20
|
collect_comments: T::Boolean,
|
21
21
|
).void
|
22
22
|
end
|
23
|
-
def initialize(index, dispatcher, parse_result,
|
23
|
+
def initialize(index, dispatcher, parse_result, uri, collect_comments: false)
|
24
24
|
@index = index
|
25
|
-
@
|
25
|
+
@uri = uri
|
26
26
|
@enhancements = T.let(Enhancement.all(self), T::Array[Enhancement])
|
27
|
-
@visibility_stack = T.let([
|
27
|
+
@visibility_stack = T.let([VisibilityScope.public_scope], T::Array[VisibilityScope])
|
28
28
|
@comments_by_line = T.let(
|
29
29
|
parse_result.comments.to_h do |c|
|
30
30
|
[c.location.start_line, c]
|
@@ -64,7 +64,6 @@ module RubyIndexer
|
|
64
64
|
:on_constant_path_or_write_node_enter,
|
65
65
|
:on_constant_path_operator_write_node_enter,
|
66
66
|
:on_constant_path_and_write_node_enter,
|
67
|
-
:on_constant_or_write_node_enter,
|
68
67
|
:on_constant_write_node_enter,
|
69
68
|
:on_constant_or_write_node_enter,
|
70
69
|
:on_constant_and_write_node_enter,
|
@@ -80,6 +79,11 @@ module RubyIndexer
|
|
80
79
|
:on_instance_variable_or_write_node_enter,
|
81
80
|
:on_instance_variable_target_node_enter,
|
82
81
|
:on_alias_method_node_enter,
|
82
|
+
:on_class_variable_and_write_node_enter,
|
83
|
+
:on_class_variable_operator_write_node_enter,
|
84
|
+
:on_class_variable_or_write_node_enter,
|
85
|
+
:on_class_variable_target_node_enter,
|
86
|
+
:on_class_variable_write_node_enter,
|
83
87
|
)
|
84
88
|
end
|
85
89
|
|
@@ -87,7 +91,7 @@ module RubyIndexer
|
|
87
91
|
def on_class_node_enter(node)
|
88
92
|
constant_path = node.constant_path
|
89
93
|
superclass = node.superclass
|
90
|
-
nesting = actual_nesting(constant_path.slice)
|
94
|
+
nesting = Index.actual_nesting(@stack, constant_path.slice)
|
91
95
|
|
92
96
|
parent_class = case superclass
|
93
97
|
when Prism::ConstantReadNode, Prism::ConstantPathNode
|
@@ -133,14 +137,14 @@ module RubyIndexer
|
|
133
137
|
|
134
138
|
sig { params(node: Prism::SingletonClassNode).void }
|
135
139
|
def on_singleton_class_node_enter(node)
|
136
|
-
@visibility_stack.push(
|
140
|
+
@visibility_stack.push(VisibilityScope.public_scope)
|
137
141
|
|
138
142
|
current_owner = @owner_stack.last
|
139
143
|
|
140
144
|
if current_owner
|
141
145
|
expression = node.expression
|
142
|
-
name = (expression.is_a?(Prism::SelfNode) ? "<Class:#{
|
143
|
-
real_nesting = actual_nesting(name)
|
146
|
+
name = (expression.is_a?(Prism::SelfNode) ? "<Class:#{last_name_in_stack}>" : "<Class:#{expression.slice}>")
|
147
|
+
real_nesting = Index.actual_nesting(@stack, name)
|
144
148
|
|
145
149
|
existing_entries = T.cast(@index[real_nesting.join("::")], T.nilable(T::Array[Entry::SingletonClass]))
|
146
150
|
|
@@ -154,7 +158,7 @@ module RubyIndexer
|
|
154
158
|
else
|
155
159
|
entry = Entry::SingletonClass.new(
|
156
160
|
real_nesting,
|
157
|
-
@
|
161
|
+
@uri,
|
158
162
|
Location.from_prism_location(node.location, @code_units_cache),
|
159
163
|
Location.from_prism_location(expression.location, @code_units_cache),
|
160
164
|
collect_comments(node),
|
@@ -275,15 +279,14 @@ module RubyIndexer
|
|
275
279
|
when :include, :prepend, :extend
|
276
280
|
handle_module_operation(node, message)
|
277
281
|
when :public
|
278
|
-
@visibility_stack.push(
|
282
|
+
@visibility_stack.push(VisibilityScope.public_scope)
|
279
283
|
when :protected
|
280
|
-
@visibility_stack.push(Entry::Visibility::PROTECTED)
|
284
|
+
@visibility_stack.push(VisibilityScope.new(visibility: Entry::Visibility::PROTECTED))
|
281
285
|
when :private
|
282
|
-
@visibility_stack.push(Entry::Visibility::PRIVATE)
|
286
|
+
@visibility_stack.push(VisibilityScope.new(visibility: Entry::Visibility::PRIVATE))
|
283
287
|
when :module_function
|
284
288
|
handle_module_function(node)
|
285
289
|
when :private_class_method
|
286
|
-
@visibility_stack.push(Entry::Visibility::PRIVATE)
|
287
290
|
handle_private_class_method(node)
|
288
291
|
end
|
289
292
|
|
@@ -291,7 +294,7 @@ module RubyIndexer
|
|
291
294
|
enhancement.on_call_node_enter(node)
|
292
295
|
rescue StandardError => e
|
293
296
|
@indexing_errors << <<~MSG
|
294
|
-
Indexing error in #{@
|
297
|
+
Indexing error in #{@uri} with '#{enhancement.class.name}' on call node enter enhancement: #{e.message}
|
295
298
|
MSG
|
296
299
|
end
|
297
300
|
end
|
@@ -312,49 +315,67 @@ module RubyIndexer
|
|
312
315
|
enhancement.on_call_node_leave(node)
|
313
316
|
rescue StandardError => e
|
314
317
|
@indexing_errors << <<~MSG
|
315
|
-
Indexing error in #{@
|
318
|
+
Indexing error in #{@uri} with '#{enhancement.class.name}' on call node leave enhancement: #{e.message}
|
316
319
|
MSG
|
317
320
|
end
|
318
321
|
end
|
319
322
|
|
320
323
|
sig { params(node: Prism::DefNode).void }
|
321
324
|
def on_def_node_enter(node)
|
325
|
+
owner = @owner_stack.last
|
326
|
+
return unless owner
|
327
|
+
|
322
328
|
@inside_def = true
|
323
329
|
method_name = node.name.to_s
|
324
330
|
comments = collect_comments(node)
|
331
|
+
scope = current_visibility_scope
|
325
332
|
|
326
333
|
case node.receiver
|
327
334
|
when nil
|
335
|
+
location = Location.from_prism_location(node.location, @code_units_cache)
|
336
|
+
name_location = Location.from_prism_location(node.name_loc, @code_units_cache)
|
337
|
+
signatures = [Entry::Signature.new(list_params(node.parameters))]
|
338
|
+
|
328
339
|
@index.add(Entry::Method.new(
|
329
340
|
method_name,
|
330
|
-
@
|
331
|
-
|
332
|
-
|
341
|
+
@uri,
|
342
|
+
location,
|
343
|
+
name_location,
|
333
344
|
comments,
|
334
|
-
|
335
|
-
|
336
|
-
|
345
|
+
signatures,
|
346
|
+
scope.visibility,
|
347
|
+
owner,
|
337
348
|
))
|
338
|
-
when Prism::SelfNode
|
339
|
-
owner = @owner_stack.last
|
340
349
|
|
341
|
-
if
|
350
|
+
if scope.module_func
|
342
351
|
singleton = @index.existing_or_new_singleton_class(owner.name)
|
343
352
|
|
344
353
|
@index.add(Entry::Method.new(
|
345
354
|
method_name,
|
346
|
-
@
|
347
|
-
|
348
|
-
|
355
|
+
@uri,
|
356
|
+
location,
|
357
|
+
name_location,
|
349
358
|
comments,
|
350
|
-
|
351
|
-
|
359
|
+
signatures,
|
360
|
+
Entry::Visibility::PUBLIC,
|
352
361
|
singleton,
|
353
362
|
))
|
354
|
-
|
355
|
-
@owner_stack << singleton
|
356
|
-
@stack << "<Class:#{@stack.last}>"
|
357
363
|
end
|
364
|
+
when Prism::SelfNode
|
365
|
+
singleton = @index.existing_or_new_singleton_class(owner.name)
|
366
|
+
|
367
|
+
@index.add(Entry::Method.new(
|
368
|
+
method_name,
|
369
|
+
@uri,
|
370
|
+
Location.from_prism_location(node.location, @code_units_cache),
|
371
|
+
Location.from_prism_location(node.name_loc, @code_units_cache),
|
372
|
+
comments,
|
373
|
+
[Entry::Signature.new(list_params(node.parameters))],
|
374
|
+
scope.visibility,
|
375
|
+
singleton,
|
376
|
+
))
|
377
|
+
|
378
|
+
@owner_stack << singleton
|
358
379
|
end
|
359
380
|
end
|
360
381
|
|
@@ -364,7 +385,6 @@ module RubyIndexer
|
|
364
385
|
|
365
386
|
if node.receiver.is_a?(Prism::SelfNode)
|
366
387
|
@owner_stack.pop
|
367
|
-
@stack.pop
|
368
388
|
end
|
369
389
|
end
|
370
390
|
|
@@ -427,13 +447,38 @@ module RubyIndexer
|
|
427
447
|
method_name,
|
428
448
|
node.old_name.slice,
|
429
449
|
@owner_stack.last,
|
430
|
-
@
|
450
|
+
@uri,
|
431
451
|
Location.from_prism_location(node.new_name.location, @code_units_cache),
|
432
452
|
comments,
|
433
453
|
),
|
434
454
|
)
|
435
455
|
end
|
436
456
|
|
457
|
+
sig { params(node: Prism::ClassVariableAndWriteNode).void }
|
458
|
+
def on_class_variable_and_write_node_enter(node)
|
459
|
+
handle_class_variable(node, node.name_loc)
|
460
|
+
end
|
461
|
+
|
462
|
+
sig { params(node: Prism::ClassVariableOperatorWriteNode).void }
|
463
|
+
def on_class_variable_operator_write_node_enter(node)
|
464
|
+
handle_class_variable(node, node.name_loc)
|
465
|
+
end
|
466
|
+
|
467
|
+
sig { params(node: Prism::ClassVariableOrWriteNode).void }
|
468
|
+
def on_class_variable_or_write_node_enter(node)
|
469
|
+
handle_class_variable(node, node.name_loc)
|
470
|
+
end
|
471
|
+
|
472
|
+
sig { params(node: Prism::ClassVariableTargetNode).void }
|
473
|
+
def on_class_variable_target_node_enter(node)
|
474
|
+
handle_class_variable(node, node.location)
|
475
|
+
end
|
476
|
+
|
477
|
+
sig { params(node: Prism::ClassVariableWriteNode).void }
|
478
|
+
def on_class_variable_write_node_enter(node)
|
479
|
+
handle_class_variable(node, node.name_loc)
|
480
|
+
end
|
481
|
+
|
437
482
|
sig do
|
438
483
|
params(
|
439
484
|
name: String,
|
@@ -448,7 +493,7 @@ module RubyIndexer
|
|
448
493
|
|
449
494
|
@index.add(Entry::Method.new(
|
450
495
|
name,
|
451
|
-
@
|
496
|
+
@uri,
|
452
497
|
location,
|
453
498
|
location,
|
454
499
|
comments,
|
@@ -471,8 +516,8 @@ module RubyIndexer
|
|
471
516
|
name_loc = Location.from_prism_location(name_location, @code_units_cache)
|
472
517
|
|
473
518
|
entry = Entry::Module.new(
|
474
|
-
actual_nesting(name),
|
475
|
-
@
|
519
|
+
Index.actual_nesting(@stack, name),
|
520
|
+
@uri,
|
476
521
|
location,
|
477
522
|
name_loc,
|
478
523
|
comments,
|
@@ -491,10 +536,10 @@ module RubyIndexer
|
|
491
536
|
).void
|
492
537
|
end
|
493
538
|
def add_class(name_or_nesting, full_location, name_location, parent_class_name: nil, comments: nil)
|
494
|
-
nesting = name_or_nesting.is_a?(Array) ? name_or_nesting : actual_nesting(name_or_nesting)
|
539
|
+
nesting = name_or_nesting.is_a?(Array) ? name_or_nesting : Index.actual_nesting(@stack, name_or_nesting)
|
495
540
|
entry = Entry::Class.new(
|
496
541
|
nesting,
|
497
|
-
@
|
542
|
+
@uri,
|
498
543
|
Location.from_prism_location(full_location, @code_units_cache),
|
499
544
|
Location.from_prism_location(name_location, @code_units_cache),
|
500
545
|
comments,
|
@@ -546,9 +591,45 @@ module RubyIndexer
|
|
546
591
|
|
547
592
|
@index.add(Entry::GlobalVariable.new(
|
548
593
|
name,
|
549
|
-
@
|
594
|
+
@uri,
|
595
|
+
Location.from_prism_location(loc, @code_units_cache),
|
596
|
+
comments,
|
597
|
+
))
|
598
|
+
end
|
599
|
+
|
600
|
+
sig do
|
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
|
612
|
+
def handle_class_variable(node, loc)
|
613
|
+
name = node.name.to_s
|
614
|
+
# Ignore incomplete class variable names, which aren't valid Ruby syntax.
|
615
|
+
# This could occur if the code is in an incomplete or temporary state.
|
616
|
+
return if name == "@@"
|
617
|
+
|
618
|
+
comments = collect_comments(node)
|
619
|
+
|
620
|
+
owner = @owner_stack.last
|
621
|
+
|
622
|
+
# set the class variable's owner to the attached context when defined within a singleton scope.
|
623
|
+
if owner.is_a?(Entry::SingletonClass)
|
624
|
+
owner = @owner_stack.reverse.find { |entry| !entry.name.include?("<Class:") }
|
625
|
+
end
|
626
|
+
|
627
|
+
@index.add(Entry::ClassVariable.new(
|
628
|
+
name,
|
629
|
+
@uri,
|
550
630
|
Location.from_prism_location(loc, @code_units_cache),
|
551
631
|
comments,
|
632
|
+
owner,
|
552
633
|
))
|
553
634
|
end
|
554
635
|
|
@@ -578,7 +659,7 @@ module RubyIndexer
|
|
578
659
|
|
579
660
|
@index.add(Entry::InstanceVariable.new(
|
580
661
|
name,
|
581
|
-
@
|
662
|
+
@uri,
|
582
663
|
Location.from_prism_location(loc, @code_units_cache),
|
583
664
|
collect_comments(node),
|
584
665
|
owner,
|
@@ -642,7 +723,7 @@ module RubyIndexer
|
|
642
723
|
new_name_value,
|
643
724
|
old_name_value,
|
644
725
|
@owner_stack.last,
|
645
|
-
@
|
726
|
+
@uri,
|
646
727
|
Location.from_prism_location(new_name.location, @code_units_cache),
|
647
728
|
comments,
|
648
729
|
),
|
@@ -678,7 +759,7 @@ module RubyIndexer
|
|
678
759
|
value.slice,
|
679
760
|
@stack.dup,
|
680
761
|
name,
|
681
|
-
@
|
762
|
+
@uri,
|
682
763
|
Location.from_prism_location(node.location, @code_units_cache),
|
683
764
|
comments,
|
684
765
|
)
|
@@ -691,7 +772,7 @@ module RubyIndexer
|
|
691
772
|
value.name.to_s,
|
692
773
|
@stack.dup,
|
693
774
|
name,
|
694
|
-
@
|
775
|
+
@uri,
|
695
776
|
Location.from_prism_location(node.location, @code_units_cache),
|
696
777
|
comments,
|
697
778
|
)
|
@@ -702,14 +783,14 @@ module RubyIndexer
|
|
702
783
|
value.target.slice,
|
703
784
|
@stack.dup,
|
704
785
|
name,
|
705
|
-
@
|
786
|
+
@uri,
|
706
787
|
Location.from_prism_location(node.location, @code_units_cache),
|
707
788
|
comments,
|
708
789
|
)
|
709
790
|
else
|
710
791
|
Entry::Constant.new(
|
711
792
|
name,
|
712
|
-
@
|
793
|
+
@uri,
|
713
794
|
Location.from_prism_location(node.location, @code_units_cache),
|
714
795
|
comments,
|
715
796
|
)
|
@@ -768,6 +849,8 @@ module RubyIndexer
|
|
768
849
|
return unless receiver.nil? || receiver.is_a?(Prism::SelfNode)
|
769
850
|
|
770
851
|
comments = collect_comments(node)
|
852
|
+
scope = current_visibility_scope
|
853
|
+
|
771
854
|
arguments.each do |argument|
|
772
855
|
name, loc = case argument
|
773
856
|
when Prism::SymbolNode
|
@@ -781,10 +864,10 @@ module RubyIndexer
|
|
781
864
|
if reader
|
782
865
|
@index.add(Entry::Accessor.new(
|
783
866
|
name,
|
784
|
-
@
|
867
|
+
@uri,
|
785
868
|
Location.from_prism_location(loc, @code_units_cache),
|
786
869
|
comments,
|
787
|
-
|
870
|
+
scope.visibility,
|
788
871
|
@owner_stack.last,
|
789
872
|
))
|
790
873
|
end
|
@@ -793,10 +876,10 @@ module RubyIndexer
|
|
793
876
|
|
794
877
|
@index.add(Entry::Accessor.new(
|
795
878
|
"#{name}=",
|
796
|
-
@
|
879
|
+
@uri,
|
797
880
|
Location.from_prism_location(loc, @code_units_cache),
|
798
881
|
comments,
|
799
|
-
|
882
|
+
scope.visibility,
|
800
883
|
@owner_stack.last,
|
801
884
|
))
|
802
885
|
end
|
@@ -838,11 +921,20 @@ module RubyIndexer
|
|
838
921
|
|
839
922
|
sig { params(node: Prism::CallNode).void }
|
840
923
|
def handle_module_function(node)
|
924
|
+
# Invoking `module_function` in a class raises
|
925
|
+
owner = @owner_stack.last
|
926
|
+
return unless owner.is_a?(Entry::Module)
|
927
|
+
|
841
928
|
arguments_node = node.arguments
|
842
|
-
return unless arguments_node
|
843
929
|
|
844
|
-
|
845
|
-
|
930
|
+
# If `module_function` is invoked without arguments, all methods defined after it become singleton methods and the
|
931
|
+
# visibility for instance methods changes to private
|
932
|
+
unless arguments_node
|
933
|
+
@visibility_stack.push(VisibilityScope.module_function_scope)
|
934
|
+
return
|
935
|
+
end
|
936
|
+
|
937
|
+
owner_name = owner.name
|
846
938
|
|
847
939
|
arguments_node.arguments.each do |argument|
|
848
940
|
method_name = case argument
|
@@ -866,7 +958,7 @@ module RubyIndexer
|
|
866
958
|
location = Location.from_prism_location(argument.location, @code_units_cache)
|
867
959
|
@index.add(Entry::Method.new(
|
868
960
|
method_name,
|
869
|
-
@
|
961
|
+
@uri,
|
870
962
|
location,
|
871
963
|
location,
|
872
964
|
collect_comments(node)&.concat(entry.comments),
|
@@ -880,45 +972,48 @@ module RubyIndexer
|
|
880
972
|
|
881
973
|
sig { params(node: Prism::CallNode).void }
|
882
974
|
def handle_private_class_method(node)
|
883
|
-
node.arguments&.arguments
|
884
|
-
|
885
|
-
when Prism::StringNode, Prism::SymbolNode
|
886
|
-
[argument]
|
887
|
-
when Prism::ArrayNode
|
888
|
-
argument.elements
|
889
|
-
else
|
890
|
-
[]
|
891
|
-
end
|
975
|
+
arguments = node.arguments&.arguments
|
976
|
+
return unless arguments
|
892
977
|
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
978
|
+
# If we're passing a method definition directly to `private_class_method`, push a new private scope. That will be
|
979
|
+
# applied when the indexer finds the method definition and then popped on `call_node_leave`
|
980
|
+
if arguments.first.is_a?(Prism::DefNode)
|
981
|
+
@visibility_stack.push(VisibilityScope.new(visibility: Entry::Visibility::PRIVATE))
|
982
|
+
return
|
983
|
+
end
|
897
984
|
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
985
|
+
owner_name = @owner_stack.last&.name
|
986
|
+
return unless owner_name
|
987
|
+
|
988
|
+
# private_class_method accepts strings, symbols or arrays of strings and symbols as arguments. Here we build a
|
989
|
+
# single list of all of the method names that have to be made private
|
990
|
+
arrays, others = T.cast(
|
991
|
+
arguments.partition { |argument| argument.is_a?(Prism::ArrayNode) },
|
992
|
+
[T::Array[Prism::ArrayNode], T::Array[Prism::Node]],
|
993
|
+
)
|
994
|
+
arrays.each { |array| others.concat(array.elements) }
|
906
995
|
|
907
|
-
|
908
|
-
|
996
|
+
names = others.filter_map do |argument|
|
997
|
+
case argument
|
998
|
+
when Prism::StringNode
|
999
|
+
argument.unescaped
|
1000
|
+
when Prism::SymbolNode
|
1001
|
+
argument.value
|
1002
|
+
end
|
1003
|
+
end
|
909
1004
|
|
910
|
-
|
911
|
-
|
1005
|
+
names.each do |name|
|
1006
|
+
entries = @index.resolve_method(name, @index.existing_or_new_singleton_class(owner_name).name)
|
1007
|
+
next unless entries
|
912
1008
|
|
913
|
-
|
914
|
-
|
915
|
-
end
|
1009
|
+
entries.each do |entry|
|
1010
|
+
entry.visibility = Entry::Visibility::PRIVATE
|
916
1011
|
end
|
917
1012
|
end
|
918
1013
|
end
|
919
1014
|
|
920
|
-
sig { returns(
|
921
|
-
def
|
1015
|
+
sig { returns(VisibilityScope) }
|
1016
|
+
def current_visibility_scope
|
922
1017
|
T.must(@visibility_stack.last)
|
923
1018
|
end
|
924
1019
|
|
@@ -1009,26 +1104,22 @@ module RubyIndexer
|
|
1009
1104
|
end
|
1010
1105
|
end
|
1011
1106
|
|
1012
|
-
sig { params(name: String).returns(T::Array[String]) }
|
1013
|
-
def actual_nesting(name)
|
1014
|
-
nesting = @stack + [name]
|
1015
|
-
corrected_nesting = []
|
1016
|
-
|
1017
|
-
nesting.reverse_each do |name|
|
1018
|
-
corrected_nesting.prepend(name.delete_prefix("::"))
|
1019
|
-
|
1020
|
-
break if name.start_with?("::")
|
1021
|
-
end
|
1022
|
-
|
1023
|
-
corrected_nesting
|
1024
|
-
end
|
1025
|
-
|
1026
1107
|
sig { params(short_name: String, entry: Entry::Namespace).void }
|
1027
1108
|
def advance_namespace_stack(short_name, entry)
|
1028
|
-
@visibility_stack.push(
|
1109
|
+
@visibility_stack.push(VisibilityScope.public_scope)
|
1029
1110
|
@owner_stack << entry
|
1030
1111
|
@index.add(entry)
|
1031
1112
|
@stack << short_name
|
1032
1113
|
end
|
1114
|
+
|
1115
|
+
# Returns the last name in the stack not as we found it, but in terms of declared constants. For example, if the
|
1116
|
+
# last entry in the stack is a compact namespace like `Foo::Bar`, then the last name is `Bar`
|
1117
|
+
sig { returns(T.nilable(String)) }
|
1118
|
+
def last_name_in_stack
|
1119
|
+
name = @stack.last
|
1120
|
+
return unless name
|
1121
|
+
|
1122
|
+
name.split("::").last
|
1123
|
+
end
|
1033
1124
|
end
|
1034
1125
|
end
|