Skip to content

Commit e6ed0b9

Browse files
committed
Switch singleton class names to new style
1 parent d3fa68d commit e6ed0b9

17 files changed

Lines changed: 125 additions & 125 deletions

lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def on_singleton_class_node_enter(node)
129129

130130
if current_owner
131131
expression = node.expression
132-
name = (expression.is_a?(Prism::SelfNode) ? "<Class:#{last_name_in_stack}>" : "<Class:#{expression.slice}>")
132+
name = (expression.is_a?(Prism::SelfNode) ? "<#{last_name_in_stack}>" : "<#{expression.slice}>")
133133
real_nesting = Index.actual_nesting(@stack, name)
134134

135135
existing_entries = @index[real_nesting.join("::")] #: as Array[Entry::SingletonClass]?
@@ -577,7 +577,7 @@ def handle_class_variable(node, loc)
577577

578578
# set the class variable's owner to the attached context when defined within a singleton scope.
579579
if owner.is_a?(Entry::SingletonClass)
580-
owner = @owner_stack.reverse.find { |entry| !entry.name.include?("<Class:") }
580+
owner = @owner_stack.reverse.find { |entry| !entry.name.include?("<") }
581581
end
582582

583583
@index.add(Entry::ClassVariable.new(

lib/ruby_indexer/lib/ruby_indexer/index.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def linearized_ancestors_of(fully_qualified_name)
507507
singleton_levels = 0
508508

509509
parts.reverse_each do |part|
510-
break unless part.include?("<Class:")
510+
break unless part.start_with?("<")
511511

512512
singleton_levels += 1
513513
parts.pop
@@ -551,7 +551,7 @@ def linearized_ancestors_of(fully_qualified_name)
551551

552552
if nesting.any?
553553
singleton_levels.times do
554-
nesting << "<Class:#{nesting.last}>"
554+
nesting << "<#{nesting.last}>"
555555
end
556556
end
557557

@@ -616,7 +616,7 @@ def instance_variable_completion_candidates(name, owner_name)
616616
if class_variables.any?
617617
name_parts = owner_name.split("::")
618618

619-
if name_parts.last&.start_with?("<Class:")
619+
if name_parts.last&.start_with?("<")
620620
attached_name = name_parts[0..-2] #: as !nil
621621
.join("::")
622622
attached_ancestors = linearized_ancestors_of(attached_name)
@@ -707,7 +707,7 @@ def length
707707
#: (String name) -> Entry::SingletonClass
708708
def existing_or_new_singleton_class(name)
709709
*_namespace, unqualified_name = name.split("::")
710-
full_singleton_name = "#{name}::<Class:#{unqualified_name}>"
710+
full_singleton_name = "#{name}::<#{unqualified_name}>"
711711
singleton = self[full_singleton_name]&.first #: as Entry::SingletonClass?
712712

713713
unless singleton
@@ -744,7 +744,7 @@ def entries_for(uri, type = nil)
744744
def linearized_attached_ancestors(name)
745745
name_parts = name.split("::")
746746

747-
if name_parts.last&.start_with?("<Class:")
747+
if name_parts.last&.start_with?("<")
748748
attached_name = name_parts[0..-2] #: as !nil
749749
.join("::")
750750
linearized_ancestors_of(attached_name)
@@ -866,7 +866,7 @@ def linearize_superclass( # rubocop:disable Metrics/ParameterLists
866866

867867
parent_name_parts = parent_class_name.split("::")
868868
singleton_levels.times do
869-
parent_name_parts << "<Class:#{parent_name_parts.last}>"
869+
parent_name_parts << "<#{parent_name_parts.last}>"
870870
end
871871

872872
ancestors.concat(linearized_ancestors_of(parent_name_parts.join("::")))
@@ -878,7 +878,7 @@ def linearize_superclass( # rubocop:disable Metrics/ParameterLists
878878
class_class_name_parts = ["Class"]
879879

880880
(singleton_levels - 1).times do
881-
class_class_name_parts << "<Class:#{class_class_name_parts.last}>"
881+
class_class_name_parts << "<#{class_class_name_parts.last}>"
882882
end
883883

884884
ancestors.concat(linearized_ancestors_of(class_class_name_parts.join("::")))
@@ -892,7 +892,7 @@ def linearize_superclass( # rubocop:disable Metrics/ParameterLists
892892
module_class_name_parts = ["Module"]
893893

894894
(singleton_levels - 1).times do
895-
module_class_name_parts << "<Class:#{module_class_name_parts.last}>"
895+
module_class_name_parts << "<#{module_class_name_parts.last}>"
896896
end
897897

898898
ancestors.concat(linearized_ancestors_of(module_class_name_parts.join("::")))

lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def on_singleton_class_node_enter(node)
134134
expression = node.expression
135135
return unless expression.is_a?(Prism::SelfNode)
136136

137-
@stack << "<Class:#{@stack.last}>"
137+
@stack << "<#{@stack.last}>"
138138
end
139139

140140
#: (Prism::SingletonClassNode node) -> void
@@ -239,7 +239,7 @@ def on_def_node_enter(node)
239239
end
240240

241241
if node.receiver.is_a?(Prism::SelfNode)
242-
@stack << "<Class:#{@stack.last}>"
242+
@stack << "<#{@stack.last}>"
243243
end
244244
end
245245

lib/ruby_indexer/test/classes_and_modules_test.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -489,15 +489,15 @@ class ConstantPathReferences
489489
end
490490
RUBY
491491

492-
foo = @index["Foo::<Class:Foo>"] #: as !nil
492+
foo = @index["Foo::<Foo>"] #: as !nil
493493
.first #: as Entry::Class
494494
assert_equal(["A1", "A2", "A3", "A4", "A5", "A6"], foo.mixin_operation_module_names)
495495

496-
qux = @index["Foo::Qux::<Class:Qux>"] #: as !nil
496+
qux = @index["Foo::Qux::<Qux>"] #: as !nil
497497
.first #: as Entry::Class
498498
assert_equal(["Corge", "Corge", "Baz"], qux.mixin_operation_module_names)
499499

500-
constant_path_references = @index["ConstantPathReferences::<Class:ConstantPathReferences>"] #: as !nil
500+
constant_path_references = @index["ConstantPathReferences::<ConstantPathReferences>"] #: as !nil
501501
.first #: as Entry::Class
502502
assert_equal(["Foo::Bar", "Foo::Bar2"], constant_path_references.mixin_operation_module_names)
503503
end
@@ -512,7 +512,7 @@ class << self
512512
end
513513
RUBY
514514

515-
foo = @index["Foo::<Class:Foo>"] #: as !nil
515+
foo = @index["Foo::<Foo>"] #: as !nil
516516
.first #: as Entry::SingletonClass
517517
assert_equal(4, foo.location.start_line)
518518
assert_equal("Some extra comments", foo.comments)
@@ -527,7 +527,7 @@ class << bar
527527
end
528528
RUBY
529529

530-
singleton = @index["Foo::<Class:bar>"] #: as !nil
530+
singleton = @index["Foo::<bar>"] #: as !nil
531531
.first #: as Entry::SingletonClass
532532

533533
# Even though this is not correct, we consider any dynamic singleton class block as a regular singleton class.
@@ -547,7 +547,7 @@ class Bar
547547
end
548548
RUBY
549549

550-
assert_entry("Foo::<Class:Foo>::Bar", Entry::Class, "/fake/path/foo.rb:2-4:3-7")
550+
assert_entry("Foo::<Foo>::Bar", Entry::Class, "/fake/path/foo.rb:2-4:3-7")
551551
end
552552

553553
def test_name_location_points_to_constant_path_location
@@ -614,10 +614,10 @@ class << self
614614
entries = @index.instance_variable_get(:@entries)
615615
refute(entries.key?("::Foo"))
616616
refute(entries.key?("::Foo::Bar"))
617-
refute(entries.key?("::Foo::Bar::<Class:Bar>"))
617+
refute(entries.key?("::Foo::Bar::<Bar>"))
618618
assert_entry("Foo", Entry::Module, "/fake/path/foo.rb:0-0:5-3")
619619
assert_entry("Foo::Bar", Entry::Class, "/fake/path/foo.rb:1-2:4-5")
620-
assert_entry("Foo::Bar::<Class:Bar>", Entry::SingletonClass, "/fake/path/foo.rb:2-4:3-7")
620+
assert_entry("Foo::Bar::<Bar>", Entry::SingletonClass, "/fake/path/foo.rb:2-4:3-7")
621621
end
622622

623623
def test_indexing_namespaces_inside_nested_top_level_references
@@ -683,13 +683,13 @@ def baz; end
683683
RUBY
684684

685685
# Verify we didn't index the incorrect name
686-
assert_nil(@index["Foo::Bar::<Class:Foo::Bar>"])
686+
assert_nil(@index["Foo::Bar::<Foo::Bar>"])
687687

688688
# Verify we indexed the correct name
689-
assert_entry("Foo::Bar::<Class:Bar>", Entry::SingletonClass, "/fake/path/foo.rb:1-2:3-5")
689+
assert_entry("Foo::Bar::<Bar>", Entry::SingletonClass, "/fake/path/foo.rb:1-2:3-5")
690690

691691
method = @index["baz"]&.first #: as Entry::Method
692-
assert_equal("Foo::Bar::<Class:Bar>", method.owner&.name)
692+
assert_equal("Foo::Bar::<Bar>", method.owner&.name)
693693
end
694694

695695
def test_lazy_comments_with_spaces_are_properly_attributed

lib/ruby_indexer/test/enhancements_test.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ class User < ActiveRecord::Base
7676

7777
assert_equal(
7878
[
79-
"User::<Class:User>",
80-
"ActiveRecord::Base::<Class:Base>",
79+
"User::<User>",
80+
"ActiveRecord::Base::<Base>",
8181
"ActiveRecord::Associations::ClassMethods",
82-
"Object::<Class:Object>",
83-
"BasicObject::<Class:BasicObject>",
82+
"Object::<Object>",
83+
"BasicObject::<BasicObject>",
8484
"Class",
8585
"Module",
8686
"Object",
8787
"Kernel",
8888
"BasicObject",
8989
],
90-
@index.linearized_ancestors_of("User::<Class:User>"),
90+
@index.linearized_ancestors_of("User::<User>"),
9191
)
9292

9393
assert_entry("new_method", Entry::Method, "/fake/path/foo.rb:10-4:10-33")
@@ -271,20 +271,20 @@ class User
271271

272272
assert_equal(
273273
[
274-
"User::<Class:User>",
274+
"User::<User>",
275275
"MyConcern::ClassMethods",
276-
"Object::<Class:Object>",
277-
"BasicObject::<Class:BasicObject>",
276+
"Object::<Object>",
277+
"BasicObject::<BasicObject>",
278278
"Class",
279279
"Module",
280280
"Object",
281281
"Kernel",
282282
"BasicObject",
283283
],
284-
@index.linearized_ancestors_of("User::<Class:User>"),
284+
@index.linearized_ancestors_of("User::<User>"),
285285
)
286286

287-
refute_nil(@index.resolve_method("foo", "User::<Class:User>"))
287+
refute_nil(@index.resolve_method("foo", "User::<User>"))
288288
end
289289

290290
def test_creating_anonymous_classes_from_enhancement

0 commit comments

Comments
 (0)