Skip to content

Commit ab75352

Browse files
Pass index configuration to entries
This commit adds the index configuration to entries which will later be used to fix an issue with magic comments appearing in documentation.
1 parent 48f7d85 commit ab75352

File tree

4 files changed

+58
-28
lines changed

4 files changed

+58
-28
lines changed

lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def on_singleton_class_node_enter(node)
143143
)
144144
else
145145
entry = Entry::SingletonClass.new(
146+
@index.configuration,
146147
real_nesting,
147148
@uri,
148149
Location.from_prism_location(node.location, @code_units_cache),
@@ -326,6 +327,7 @@ def on_def_node_enter(node)
326327
signatures = [Entry::Signature.new(list_params(node.parameters))]
327328

328329
@index.add(Entry::Method.new(
330+
@index.configuration,
329331
method_name,
330332
@uri,
331333
location,
@@ -340,6 +342,7 @@ def on_def_node_enter(node)
340342
singleton = @index.existing_or_new_singleton_class(owner.name)
341343

342344
@index.add(Entry::Method.new(
345+
@index.configuration,
343346
method_name,
344347
@uri,
345348
location,
@@ -354,6 +357,7 @@ def on_def_node_enter(node)
354357
singleton = @index.existing_or_new_singleton_class(owner.name)
355358

356359
@index.add(Entry::Method.new(
360+
@index.configuration,
357361
method_name,
358362
@uri,
359363
Location.from_prism_location(node.location, @code_units_cache),
@@ -433,6 +437,7 @@ def on_alias_method_node_enter(node)
433437
comments = collect_comments(node)
434438
@index.add(
435439
Entry::UnresolvedMethodAlias.new(
440+
@index.configuration,
436441
method_name,
437442
node.old_name.slice,
438443
@owner_stack.last,
@@ -473,6 +478,7 @@ def add_method(name, node_location, signatures, visibility: :public, comments: n
473478
location = Location.from_prism_location(node_location, @code_units_cache)
474479

475480
@index.add(Entry::Method.new(
481+
@index.configuration,
476482
name,
477483
@uri,
478484
location,
@@ -490,6 +496,7 @@ def add_module(name, full_location, name_location, comments: nil)
490496
name_loc = Location.from_prism_location(name_location, @code_units_cache)
491497

492498
entry = Entry::Module.new(
499+
@index.configuration,
493500
Index.actual_nesting(@stack, name),
494501
@uri,
495502
location,
@@ -504,6 +511,7 @@ def add_module(name, full_location, name_location, comments: nil)
504511
def add_class(name_or_nesting, full_location, name_location, parent_class_name: nil, comments: nil)
505512
nesting = name_or_nesting.is_a?(Array) ? name_or_nesting : Index.actual_nesting(@stack, name_or_nesting)
506513
entry = Entry::Class.new(
514+
@index.configuration,
507515
nesting,
508516
@uri,
509517
Location.from_prism_location(full_location, @code_units_cache),
@@ -548,6 +556,7 @@ def handle_global_variable(node, loc)
548556
comments = collect_comments(node)
549557

550558
@index.add(Entry::GlobalVariable.new(
559+
@index.configuration,
551560
name,
552561
@uri,
553562
Location.from_prism_location(loc, @code_units_cache),
@@ -572,6 +581,7 @@ def handle_class_variable(node, loc)
572581
end
573582

574583
@index.add(Entry::ClassVariable.new(
584+
@index.configuration,
575585
name,
576586
@uri,
577587
Location.from_prism_location(loc, @code_units_cache),
@@ -594,6 +604,7 @@ def handle_instance_variable(node, loc)
594604
end
595605

596606
@index.add(Entry::InstanceVariable.new(
607+
@index.configuration,
597608
name,
598609
@uri,
599610
Location.from_prism_location(loc, @code_units_cache),
@@ -656,6 +667,7 @@ def handle_alias_method(node)
656667
comments = collect_comments(node)
657668
@index.add(
658669
Entry::UnresolvedMethodAlias.new(
670+
@index.configuration,
659671
new_name_value,
660672
old_name_value,
661673
@owner_stack.last,
@@ -675,6 +687,7 @@ def add_constant(node, name, value = nil)
675687
case value
676688
when Prism::ConstantReadNode, Prism::ConstantPathNode
677689
Entry::UnresolvedConstantAlias.new(
690+
@index.configuration,
678691
value.slice,
679692
@stack.dup,
680693
name,
@@ -688,6 +701,7 @@ def add_constant(node, name, value = nil)
688701
# If the right hand side is another constant assignment, we need to visit it because that constant has to be
689702
# indexed too
690703
Entry::UnresolvedConstantAlias.new(
704+
@index.configuration,
691705
value.name.to_s,
692706
@stack.dup,
693707
name,
@@ -699,6 +713,7 @@ def add_constant(node, name, value = nil)
699713
Prism::ConstantPathAndWriteNode
700714

701715
Entry::UnresolvedConstantAlias.new(
716+
@index.configuration,
702717
value.target.slice,
703718
@stack.dup,
704719
name,
@@ -708,6 +723,7 @@ def add_constant(node, name, value = nil)
708723
)
709724
else
710725
Entry::Constant.new(
726+
@index.configuration,
711727
name,
712728
@uri,
713729
Location.from_prism_location(node.location, @code_units_cache),
@@ -785,6 +801,7 @@ def handle_attribute(node, reader:, writer:)
785801

786802
if reader
787803
@index.add(Entry::Accessor.new(
804+
@index.configuration,
788805
name,
789806
@uri,
790807
Location.from_prism_location(loc, @code_units_cache),
@@ -797,6 +814,7 @@ def handle_attribute(node, reader:, writer:)
797814
next unless writer
798815

799816
@index.add(Entry::Accessor.new(
817+
@index.configuration,
800818
"#{name}=",
801819
@uri,
802820
Location.from_prism_location(loc, @code_units_cache),
@@ -879,6 +897,7 @@ def handle_module_function(node)
879897
singleton = @index.existing_or_new_singleton_class(entry_owner_name)
880898
location = Location.from_prism_location(argument.location, @code_units_cache)
881899
@index.add(Entry::Method.new(
900+
@index.configuration,
882901
method_name,
883902
@uri,
884903
location,

lib/ruby_indexer/lib/ruby_indexer/entry.rb

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
module RubyIndexer
55
class Entry
6+
#: Configuration
7+
attr_reader :configuration
8+
69
#: String
710
attr_reader :name
811

@@ -17,8 +20,9 @@ class Entry
1720
#: Symbol
1821
attr_accessor :visibility
1922

20-
#: (String name, URI::Generic uri, Location location, String? comments) -> void
21-
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
2226
@name = name
2327
@uri = uri
2428
@comments = comments
@@ -121,13 +125,13 @@ class Namespace < Entry
121125
#: Location
122126
attr_reader :name_location
123127

124-
#: (Array[String] nesting, URI::Generic uri, Location location, Location name_location, String? comments) -> void
125-
def initialize(nesting, uri, location, name_location, comments)
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
126130
@name = nesting.join("::") #: String
127131
# The original nesting where this namespace was discovered
128132
@nesting = nesting
129133

130-
super(@name, uri, location, comments)
134+
super(configuration, @name, uri, location, comments)
131135

132136
@name_location = name_location
133137
end
@@ -160,9 +164,9 @@ class Class < Namespace
160164
#: String?
161165
attr_reader :parent_class
162166

163-
#: (Array[String] nesting, URI::Generic uri, Location location, Location name_location, String? comments, String? parent_class) -> void
164-
def initialize(nesting, uri, location, name_location, comments, parent_class) # rubocop:disable Metrics/ParameterLists
165-
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)
166170
@parent_class = parent_class
167171
end
168172

@@ -285,9 +289,9 @@ class Member < Entry
285289
#: Entry::Namespace?
286290
attr_reader :owner
287291

288-
#: (String name, URI::Generic uri, Location location, String? comments, Symbol visibility, Entry::Namespace? owner) -> void
289-
def initialize(name, uri, location, comments, visibility, owner) # rubocop:disable Metrics/ParameterLists
290-
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)
291295
@visibility = visibility
292296
@owner = owner
293297
end
@@ -341,9 +345,9 @@ class Method < Member
341345
#: Location
342346
attr_reader :name_location
343347

344-
#: (String name, URI::Generic uri, Location location, Location name_location, String? comments, Array[Signature] signatures, Symbol visibility, Entry::Namespace? owner) -> void
345-
def initialize(name, uri, location, name_location, comments, signatures, visibility, owner) # rubocop:disable Metrics/ParameterLists
346-
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)
347351
@signatures = signatures
348352
@name_location = name_location
349353
end
@@ -366,9 +370,9 @@ class UnresolvedConstantAlias < Entry
366370
#: Array[String]
367371
attr_reader :nesting
368372

369-
#: (String target, Array[String] nesting, String name, URI::Generic uri, Location location, String? comments) -> void
370-
def initialize(target, nesting, name, uri, location, comments) # rubocop:disable Metrics/ParameterLists
371-
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)
372376

373377
@target = target
374378
@nesting = nesting
@@ -383,6 +387,7 @@ class ConstantAlias < Entry
383387
#: (String target, UnresolvedConstantAlias unresolved_alias) -> void
384388
def initialize(target, unresolved_alias)
385389
super(
390+
unresolved_alias.configuration,
386391
unresolved_alias.name,
387392
unresolved_alias.uri,
388393
unresolved_alias.location,
@@ -402,9 +407,9 @@ class ClassVariable < Entry
402407
#: Entry::Namespace?
403408
attr_reader :owner
404409

405-
#: (String name, URI::Generic uri, Location location, String? comments, Entry::Namespace? owner) -> void
406-
def initialize(name, uri, location, comments, owner)
407-
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)
408413
@owner = owner
409414
end
410415
end
@@ -414,9 +419,9 @@ class InstanceVariable < Entry
414419
#: Entry::Namespace?
415420
attr_reader :owner
416421

417-
#: (String name, URI::Generic uri, Location location, String? comments, Entry::Namespace? owner) -> void
418-
def initialize(name, uri, location, comments, owner)
419-
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)
420425
@owner = owner
421426
end
422427
end
@@ -431,9 +436,9 @@ class UnresolvedMethodAlias < Entry
431436
#: Entry::Namespace?
432437
attr_reader :owner
433438

434-
#: (String new_name, String old_name, Entry::Namespace? owner, URI::Generic uri, Location location, String? comments) -> void
435-
def initialize(new_name, old_name, owner, uri, location, comments) # rubocop:disable Metrics/ParameterLists
436-
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)
437442

438443
@new_name = new_name
439444
@old_name = old_name
@@ -456,6 +461,7 @@ def initialize(target, unresolved_alias)
456461
full_comments << target.comments
457462

458463
super(
464+
unresolved_alias.configuration,
459465
unresolved_alias.new_name,
460466
unresolved_alias.uri,
461467
unresolved_alias.location,

lib/ruby_indexer/lib/ruby_indexer/index.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ def existing_or_new_singleton_class(name)
714714
attached_ancestor = self[name]&.first #: as !nil
715715

716716
singleton = Entry::SingletonClass.new(
717+
@configuration,
717718
[full_singleton_name],
718719
attached_ancestor.uri,
719720
attached_ancestor.location,

lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def handle_class_or_module_declaration(declaration, pathname)
5252
comments = comments_to_string(declaration)
5353
entry = if declaration.is_a?(RBS::AST::Declarations::Class)
5454
parent_class = declaration.super_class&.name&.name&.to_s
55-
Entry::Class.new(nesting, uri, location, location, comments, parent_class)
55+
Entry::Class.new(@index.configuration, nesting, uri, location, location, comments, parent_class)
5656
else
57-
Entry::Module.new(nesting, uri, location, location, comments)
57+
Entry::Module.new(@index.configuration, nesting, uri, location, location, comments)
5858
end
5959

6060
add_declaration_mixins_to_entry(declaration, entry)
@@ -110,6 +110,7 @@ def handle_method(member, owner)
110110
real_owner = member.singleton? ? @index.existing_or_new_singleton_class(owner.name) : owner
111111
signatures = signatures(member)
112112
@index.add(Entry::Method.new(
113+
@index.configuration,
113114
name,
114115
uri,
115116
location,
@@ -243,6 +244,7 @@ def process_rest_keywords(function)
243244
def handle_constant(declaration, nesting, uri)
244245
fully_qualified_name = [*nesting, declaration.name.name.to_s].join("::")
245246
@index.add(Entry::Constant.new(
247+
@index.configuration,
246248
fully_qualified_name,
247249
uri,
248250
to_ruby_indexer_location(declaration.location),
@@ -258,6 +260,7 @@ def handle_global_variable(declaration, pathname)
258260
comments = comments_to_string(declaration)
259261

260262
@index.add(Entry::GlobalVariable.new(
263+
@index.configuration,
261264
name,
262265
uri,
263266
location,
@@ -271,6 +274,7 @@ def handle_signature_alias(member, owner_entry)
271274
comments = comments_to_string(member)
272275

273276
entry = Entry::UnresolvedMethodAlias.new(
277+
@index.configuration,
274278
member.new_name.to_s,
275279
member.old_name.to_s,
276280
owner_entry,

0 commit comments

Comments
 (0)