From 1bd081704b6c06b499213f91995d76ef585e31a1 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Wed, 24 Jul 2024 23:04:53 +0100 Subject: [PATCH] Rename constant alias class names - Alias should be ConstantAlias - UnresolvedAlias should be UnresolvedConstantAlias This is to match MethodAlias and UnresolvedMethodAlias. --- .../lib/ruby_indexer/declaration_listener.rb | 6 +-- lib/ruby_indexer/lib/ruby_indexer/entry.rb | 6 +-- lib/ruby_indexer/lib/ruby_indexer/index.rb | 44 +++++++++---------- lib/ruby_indexer/test/constant_test.rb | 34 +++++++------- lib/ruby_indexer/test/index_test.rb | 12 ++--- 5 files changed, 51 insertions(+), 51 deletions(-) diff --git a/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb b/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb index 947a2de9f..412953f22 100644 --- a/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +++ b/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb @@ -504,17 +504,17 @@ def add_constant(node, name, value = nil) @index.add( case value when Prism::ConstantReadNode, Prism::ConstantPathNode - Entry::UnresolvedAlias.new(value.slice, @stack.dup, name, @file_path, node.location, comments) + Entry::UnresolvedConstantAlias.new(value.slice, @stack.dup, name, @file_path, node.location, comments) when Prism::ConstantWriteNode, Prism::ConstantAndWriteNode, Prism::ConstantOrWriteNode, Prism::ConstantOperatorWriteNode # If the right hand side is another constant assignment, we need to visit it because that constant has to be # indexed too - Entry::UnresolvedAlias.new(value.name.to_s, @stack.dup, name, @file_path, node.location, comments) + Entry::UnresolvedConstantAlias.new(value.name.to_s, @stack.dup, name, @file_path, node.location, comments) when Prism::ConstantPathWriteNode, Prism::ConstantPathOrWriteNode, Prism::ConstantPathOperatorWriteNode, Prism::ConstantPathAndWriteNode - Entry::UnresolvedAlias.new(value.target.slice, @stack.dup, name, @file_path, node.location, comments) + Entry::UnresolvedConstantAlias.new(value.target.slice, @stack.dup, name, @file_path, node.location, comments) else Entry::Constant.new(name, @file_path, node.location, comments) end, diff --git a/lib/ruby_indexer/lib/ruby_indexer/entry.rb b/lib/ruby_indexer/lib/ruby_indexer/entry.rb index 1e4cc445c..fb1755a2a 100644 --- a/lib/ruby_indexer/lib/ruby_indexer/entry.rb +++ b/lib/ruby_indexer/lib/ruby_indexer/entry.rb @@ -411,7 +411,7 @@ def initialize(name, file_path, location, name_location, comments, signatures, v # All aliases are inserted as UnresolvedAlias in the index first and then we lazily resolve them to the correct # target in [rdoc-ref:Index#resolve]. If the right hand side contains a constant that doesn't exist, then it's not # possible to resolve the alias and it will remain an UnresolvedAlias until the right hand side constant exists - class UnresolvedAlias < Entry + class UnresolvedConstantAlias < Entry extend T::Sig sig { returns(String) } @@ -439,13 +439,13 @@ def initialize(target, nesting, name, file_path, location, comments) # rubocop:d end # Alias represents a resolved alias, which points to an existing constant target - class Alias < Entry + class ConstantAlias < Entry extend T::Sig sig { returns(String) } attr_reader :target - sig { params(target: String, unresolved_alias: UnresolvedAlias).void } + sig { params(target: String, unresolved_alias: UnresolvedConstantAlias).void } def initialize(target, unresolved_alias) super(unresolved_alias.name, unresolved_alias.file_path, unresolved_alias.location, unresolved_alias.comments) diff --git a/lib/ruby_indexer/lib/ruby_indexer/index.rb b/lib/ruby_indexer/lib/ruby_indexer/index.rb index 3c8b7a979..f7adbcd63 100644 --- a/lib/ruby_indexer/lib/ruby_indexer/index.rb +++ b/lib/ruby_indexer/lib/ruby_indexer/index.rb @@ -91,8 +91,8 @@ def search_require_paths(query) name: String, ).returns(T.nilable(T::Array[T.any( Entry::Namespace, - Entry::Alias, - Entry::UnresolvedAlias, + Entry::ConstantAlias, + Entry::UnresolvedConstantAlias, Entry::Constant, )])) end @@ -105,8 +105,8 @@ def first_unqualified_const(name) entries, T.nilable(T::Array[T.any( Entry::Namespace, - Entry::Alias, - Entry::UnresolvedAlias, + Entry::ConstantAlias, + Entry::UnresolvedConstantAlias, Entry::Constant, )]), ) @@ -230,8 +230,8 @@ def method_completion_candidates(name, receiver_name) seen_names: T::Array[String], ).returns(T.nilable(T::Array[T.any( Entry::Namespace, - Entry::Alias, - Entry::UnresolvedAlias, + Entry::ConstantAlias, + Entry::UnresolvedConstantAlias, )])) end def resolve(name, nesting, seen_names = []) @@ -334,13 +334,13 @@ def follow_aliased_namespace(name, seen_names = []) entry = @entries[current_name]&.first case entry - when Entry::Alias + when Entry::ConstantAlias target = entry.target return follow_aliased_namespace("#{target}::#{real_parts.join("::")}", seen_names) - when Entry::UnresolvedAlias + when Entry::UnresolvedConstantAlias resolved = resolve_alias(entry, seen_names) - if resolved.is_a?(Entry::UnresolvedAlias) + if resolved.is_a?(Entry::UnresolvedConstantAlias) raise UnresolvableAliasError, "The constant #{resolved.name} is an alias to a non existing constant" end @@ -439,7 +439,7 @@ def linearized_ancestors_of(fully_qualified_name) case entry when Entry::Namespace entry - when Entry::Alias + when Entry::ConstantAlias self[entry.target]&.grep(Entry::Namespace) end end.flatten @@ -698,9 +698,9 @@ def linearize_superclass( # rubocop:disable Metrics/ParameterLists # that doesn't exist, then we return the same UnresolvedAlias sig do params( - entry: Entry::UnresolvedAlias, + entry: Entry::UnresolvedConstantAlias, seen_names: T::Array[String], - ).returns(T.any(Entry::Alias, Entry::UnresolvedAlias)) + ).returns(T.any(Entry::ConstantAlias, Entry::UnresolvedConstantAlias)) end def resolve_alias(entry, seen_names) alias_name = entry.name @@ -712,7 +712,7 @@ def resolve_alias(entry, seen_names) return entry unless target target_name = T.must(target.first).name - resolved_alias = Entry::Alias.new(target_name, entry) + resolved_alias = Entry::ConstantAlias.new(target_name, entry) # Replace the UnresolvedAlias by a resolved one so that we don't have to do this again later original_entries = T.must(@entries[alias_name]) @@ -731,8 +731,8 @@ def resolve_alias(entry, seen_names) seen_names: T::Array[String], ).returns(T.nilable(T::Array[T.any( Entry::Namespace, - Entry::Alias, - Entry::UnresolvedAlias, + Entry::ConstantAlias, + Entry::UnresolvedConstantAlias, )])) end def lookup_enclosing_scopes(name, nesting, seen_names) @@ -760,8 +760,8 @@ def lookup_enclosing_scopes(name, nesting, seen_names) seen_names: T::Array[String], ).returns(T.nilable(T::Array[T.any( Entry::Namespace, - Entry::Alias, - Entry::UnresolvedAlias, + Entry::ConstantAlias, + Entry::UnresolvedConstantAlias, )])) end def lookup_ancestor_chain(name, nesting, seen_names) @@ -821,8 +821,8 @@ def build_non_redundant_full_name(name, nesting) ).returns( T.nilable(T::Array[T.any( Entry::Namespace, - Entry::Alias, - Entry::UnresolvedAlias, + Entry::ConstantAlias, + Entry::UnresolvedConstantAlias, )]), ) end @@ -830,11 +830,11 @@ def direct_or_aliased_constant(full_name, seen_names) entries = @entries[full_name] || @entries[follow_aliased_namespace(full_name)] T.cast( - entries&.map { |e| e.is_a?(Entry::UnresolvedAlias) ? resolve_alias(e, seen_names) : e }, + entries&.map { |e| e.is_a?(Entry::UnresolvedConstantAlias) ? resolve_alias(e, seen_names) : e }, T.nilable(T::Array[T.any( Entry::Namespace, - Entry::Alias, - Entry::UnresolvedAlias, + Entry::ConstantAlias, + Entry::UnresolvedConstantAlias, )]), ) end diff --git a/lib/ruby_indexer/test/constant_test.rb b/lib/ruby_indexer/test/constant_test.rb index 702ae8e36..7f64e2aa7 100644 --- a/lib/ruby_indexer/test/constant_test.rb +++ b/lib/ruby_indexer/test/constant_test.rb @@ -200,12 +200,12 @@ module C RUBY unresolve_entry = @index["A::FIRST"].first - assert_instance_of(Entry::UnresolvedAlias, unresolve_entry) + assert_instance_of(Entry::UnresolvedConstantAlias, unresolve_entry) assert_equal(["A"], unresolve_entry.nesting) assert_equal("B::C", unresolve_entry.target) resolved_entry = @index.resolve("A::FIRST", []).first - assert_instance_of(Entry::Alias, resolved_entry) + assert_instance_of(Entry::ConstantAlias, resolved_entry) assert_equal("A::B::C", resolved_entry.target) end @@ -226,12 +226,12 @@ module Other RUBY unresolve_entry = @index["A::ALIAS"].first - assert_instance_of(Entry::UnresolvedAlias, unresolve_entry) + assert_instance_of(Entry::UnresolvedConstantAlias, unresolve_entry) assert_equal(["A"], unresolve_entry.nesting) assert_equal("B", unresolve_entry.target) resolved_entry = @index.resolve("ALIAS", ["A"]).first - assert_instance_of(Entry::Alias, resolved_entry) + assert_instance_of(Entry::ConstantAlias, resolved_entry) assert_equal("A::B", resolved_entry.target) resolved_entry = @index.resolve("ALIAS::C", ["A"]).first @@ -239,7 +239,7 @@ module Other assert_equal("A::B::C", resolved_entry.name) unresolve_entry = @index["Other::ONE_MORE"].first - assert_instance_of(Entry::UnresolvedAlias, unresolve_entry) + assert_instance_of(Entry::UnresolvedConstantAlias, unresolve_entry) assert_equal(["Other"], unresolve_entry.nesting) assert_equal("A::ALIAS", unresolve_entry.target) @@ -259,12 +259,12 @@ module A # B and C unresolve_entry = @index["A::B"].first - assert_instance_of(Entry::UnresolvedAlias, unresolve_entry) + assert_instance_of(Entry::UnresolvedConstantAlias, unresolve_entry) assert_equal(["A"], unresolve_entry.nesting) assert_equal("C", unresolve_entry.target) resolved_entry = @index.resolve("A::B", []).first - assert_instance_of(Entry::Alias, resolved_entry) + assert_instance_of(Entry::ConstantAlias, resolved_entry) assert_equal("A::C", resolved_entry.target) constant = @index["A::C"].first @@ -272,38 +272,38 @@ module A # D and E unresolve_entry = @index["A::D"].first - assert_instance_of(Entry::UnresolvedAlias, unresolve_entry) + assert_instance_of(Entry::UnresolvedConstantAlias, unresolve_entry) assert_equal(["A"], unresolve_entry.nesting) assert_equal("E", unresolve_entry.target) resolved_entry = @index.resolve("A::D", []).first - assert_instance_of(Entry::Alias, resolved_entry) + assert_instance_of(Entry::ConstantAlias, resolved_entry) assert_equal("A::E", resolved_entry.target) # F and G::H unresolve_entry = @index["A::F"].first - assert_instance_of(Entry::UnresolvedAlias, unresolve_entry) + assert_instance_of(Entry::UnresolvedConstantAlias, unresolve_entry) assert_equal(["A"], unresolve_entry.nesting) assert_equal("G::H", unresolve_entry.target) resolved_entry = @index.resolve("A::F", []).first - assert_instance_of(Entry::Alias, resolved_entry) + assert_instance_of(Entry::ConstantAlias, resolved_entry) assert_equal("A::G::H", resolved_entry.target) # I::J, K::L and M unresolve_entry = @index["A::I::J"].first - assert_instance_of(Entry::UnresolvedAlias, unresolve_entry) + assert_instance_of(Entry::UnresolvedConstantAlias, unresolve_entry) assert_equal(["A"], unresolve_entry.nesting) assert_equal("K::L", unresolve_entry.target) resolved_entry = @index.resolve("A::I::J", []).first - assert_instance_of(Entry::Alias, resolved_entry) + assert_instance_of(Entry::ConstantAlias, resolved_entry) assert_equal("A::K::L", resolved_entry.target) # When we are resolving A::I::J, we invoke `resolve("K::L", ["A"])`, which recursively resolves A::K::L too. # Therefore, both A::I::J and A::K::L point to A::M by the end of the previous resolve invocation resolved_entry = @index["A::K::L"].first - assert_instance_of(Entry::Alias, resolved_entry) + assert_instance_of(Entry::ConstantAlias, resolved_entry) assert_equal("A::M", resolved_entry.target) constant = @index["A::M"].first @@ -344,11 +344,11 @@ module Real RUBY assert_entry("A::B", Entry::Constant, "/fake/path/foo.rb:1-2:1-3") - assert_entry("A::C", Entry::UnresolvedAlias, "/fake/path/foo.rb:1-5:1-6") - assert_entry("A::D::E", Entry::UnresolvedAlias, "/fake/path/foo.rb:2-2:2-6") + assert_entry("A::C", Entry::UnresolvedConstantAlias, "/fake/path/foo.rb:1-5:1-6") + assert_entry("A::D::E", Entry::UnresolvedConstantAlias, "/fake/path/foo.rb:2-2:2-6") assert_entry("A::F::G", Entry::Constant, "/fake/path/foo.rb:2-8:2-12") assert_entry("A::H", Entry::Constant, "/fake/path/foo.rb:3-2:3-3") - assert_entry("A::I::J", Entry::UnresolvedAlias, "/fake/path/foo.rb:3-5:3-9") + assert_entry("A::I::J", Entry::UnresolvedConstantAlias, "/fake/path/foo.rb:3-5:3-9") assert_entry("A::K", Entry::Constant, "/fake/path/foo.rb:4-2:4-3") assert_entry("A::L", Entry::Constant, "/fake/path/foo.rb:4-5:4-6") end diff --git a/lib/ruby_indexer/test/index_test.rb b/lib/ruby_indexer/test/index_test.rb index fa21059c9..4a959db08 100644 --- a/lib/ruby_indexer/test/index_test.rb +++ b/lib/ruby_indexer/test/index_test.rb @@ -194,7 +194,7 @@ class Bar < self entry = @index.resolve("BAZ", ["Foo", "Bar"]).first refute_nil(entry) - assert_instance_of(Entry::UnresolvedAlias, entry) + assert_instance_of(Entry::UnresolvedConstantAlias, entry) end def test_visitor_does_not_visit_unnecessary_nodes @@ -1015,11 +1015,11 @@ module Namespace foo_entry = T.must(@index.resolve("FOO", ["Namespace"])&.first) assert_equal(2, foo_entry.location.start_line) - assert_instance_of(Entry::Alias, foo_entry) + assert_instance_of(Entry::ConstantAlias, foo_entry) bar_entry = T.must(@index.resolve("BAR", ["Namespace"])&.first) assert_equal(3, bar_entry.location.start_line) - assert_instance_of(Entry::Alias, bar_entry) + assert_instance_of(Entry::ConstantAlias, bar_entry) end def test_resolving_circular_alias_three_levels @@ -1033,15 +1033,15 @@ module Namespace foo_entry = T.must(@index.resolve("FOO", ["Namespace"])&.first) assert_equal(2, foo_entry.location.start_line) - assert_instance_of(Entry::Alias, foo_entry) + assert_instance_of(Entry::ConstantAlias, foo_entry) bar_entry = T.must(@index.resolve("BAR", ["Namespace"])&.first) assert_equal(3, bar_entry.location.start_line) - assert_instance_of(Entry::Alias, bar_entry) + assert_instance_of(Entry::ConstantAlias, bar_entry) baz_entry = T.must(@index.resolve("BAZ", ["Namespace"])&.first) assert_equal(4, baz_entry.location.start_line) - assert_instance_of(Entry::Alias, baz_entry) + assert_instance_of(Entry::ConstantAlias, baz_entry) end def test_resolving_constants_in_aliased_namespace