@@ -60,7 +60,7 @@ def initialize
6060 @entries = { } #: Hash[String, Array[Entry]]
6161
6262 # Holds all entries in the index using a prefix tree for searching based on prefixes to provide autocompletion
63- @entries_tree = PrefixTree [ T :: Array [ Entry ] ] . new #: PrefixTree[Array[Entry]]
63+ @entries_tree = PrefixTree . new #: PrefixTree[Array[Entry]]
6464
6565 # Holds references to where entries where discovered so that we can easily delete them
6666 # {
@@ -71,7 +71,7 @@ def initialize
7171 @uris_to_entries = { } #: Hash[String, Array[Entry]]
7272
7373 # Holds all require paths for every indexed item so that we can provide autocomplete for requires
74- @require_paths_tree = PrefixTree [ URI :: Generic ] . new #: PrefixTree[URI::Generic]
74+ @require_paths_tree = PrefixTree . new #: PrefixTree[URI::Generic]
7575
7676 # Holds the linearized ancestors list for every namespace
7777 @ancestors = { } #: Hash[String, Array[String]]
@@ -147,7 +147,7 @@ def search_require_paths(query)
147147
148148 # Searches for a constant based on an unqualified name and returns the first possible match regardless of whether
149149 # there are more possible matching entries
150- #: (String name) -> Array[( Entry::Namespace | Entry::ConstantAlias | Entry::UnresolvedConstantAlias | Entry::Constant) ]?
150+ #: (String name) -> Array[Entry::Constant | Entry::ConstantAlias | Entry::Namespace | Entry::UnresolvedConstantAlias ]?
151151 def first_unqualified_const ( name )
152152 # Look for an exact match first
153153 _name , entries = @entries . find do |const_name , _entries |
@@ -161,15 +161,7 @@ def first_unqualified_const(name)
161161 end
162162 end
163163
164- T . cast (
165- entries ,
166- T . nilable ( T ::Array [ T . any (
167- Entry ::Namespace ,
168- Entry ::ConstantAlias ,
169- Entry ::UnresolvedConstantAlias ,
170- Entry ::Constant ,
171- ) ] ) ,
172- )
164+ entries #: as Array[Entry::Constant | Entry::ConstantAlias | Entry::Namespace | Entry::UnresolvedConstantAlias]?
173165 end
174166
175167 # Searches entries in the index based on an exact prefix, intended for providing autocomplete. All possible matches
@@ -272,19 +264,11 @@ def method_completion_candidates(name, receiver_name)
272264 completion_items . values . map! ( &:first )
273265 end
274266
275- #: (String name, Array[String] nesting) -> Array[Array[( Entry::Constant | Entry::ConstantAlias | Entry::Namespace | Entry::UnresolvedConstantAlias) ]]
267+ #: (String name, Array[String] nesting) -> Array[Array[Entry::Constant | Entry::ConstantAlias | Entry::Namespace | Entry::UnresolvedConstantAlias]]
276268 def constant_completion_candidates ( name , nesting )
277269 # If we have a top level reference, then we don't need to include completions inside the current nesting
278270 if name . start_with? ( "::" )
279- return T . cast (
280- @entries_tree . search ( name . delete_prefix ( "::" ) ) ,
281- T ::Array [ T ::Array [ T . any (
282- Entry ::Constant ,
283- Entry ::ConstantAlias ,
284- Entry ::Namespace ,
285- Entry ::UnresolvedConstantAlias ,
286- ) ] ] ,
287- )
271+ return @entries_tree . search ( name . delete_prefix ( "::" ) ) #: as Array[Array[Entry::Constant | Entry::ConstantAlias | Entry::Namespace | Entry::UnresolvedConstantAlias]] # rubocop:disable Layout/LineLength
288272 end
289273
290274 # Otherwise, we have to include every possible constant the user might be referring to. This is essentially the
@@ -310,15 +294,7 @@ def constant_completion_candidates(name, nesting)
310294 # Top level constants
311295 entries . concat ( @entries_tree . search ( name ) )
312296 entries . uniq!
313- T . cast (
314- entries ,
315- T ::Array [ T ::Array [ T . any (
316- Entry ::Constant ,
317- Entry ::ConstantAlias ,
318- Entry ::Namespace ,
319- Entry ::UnresolvedConstantAlias ,
320- ) ] ] ,
321- )
297+ entries #: as Array[Array[Entry::Constant | Entry::ConstantAlias | Entry::Namespace | Entry::UnresolvedConstantAlias]] # rubocop:disable Layout/LineLength
322298 end
323299
324300 # Resolve a constant to its declaration based on its name and the nesting where the reference was found. Parameter
@@ -328,7 +304,7 @@ def constant_completion_candidates(name, nesting)
328304 # nesting: the nesting structure where the reference was found (e.g.: ["Foo", "Bar"])
329305 # seen_names: this parameter should not be used by consumers of the api. It is used to avoid infinite recursion when
330306 # resolving circular references
331- #: (String name, Array[String] nesting, ?Array[String] seen_names) -> Array[( Entry::Namespace | Entry::ConstantAlias | Entry::UnresolvedConstantAlias) ]?
307+ #: (String name, Array[String] nesting, ?Array[String] seen_names) -> Array[Entry::Constant | Entry::ConstantAlias | Entry::Namespace | Entry:: UnresolvedConstantAlias]?
332308 def resolve ( name , nesting , seen_names = [ ] )
333309 # If we have a top level reference, then we just search for it straight away ignoring the nesting
334310 if name . start_with? ( "::" )
@@ -586,7 +562,7 @@ def linearized_ancestors_of(fully_qualified_name)
586562 # and find inherited instance variables as well
587563 #: (String variable_name, String owner_name) -> Array[Entry::InstanceVariable]?
588564 def resolve_instance_variable ( variable_name , owner_name )
589- entries = T . cast ( self [ variable_name ] , T . nilable ( T :: Array [ Entry ::InstanceVariable ] ) )
565+ entries = self [ variable_name ] #: as Array[Entry::InstanceVariable]?
590566 return unless entries
591567
592568 ancestors = linearized_ancestors_of ( owner_name )
@@ -610,7 +586,7 @@ def resolve_class_variable(variable_name, owner_name)
610586 # include the `@` prefix
611587 #: (String name, String owner_name) -> Array[(Entry::InstanceVariable | Entry::ClassVariable)]
612588 def instance_variable_completion_candidates ( name , owner_name )
613- entries = T . cast ( prefix_search ( name ) . flatten , T :: Array [ T . any ( Entry ::InstanceVariable , Entry ::ClassVariable ) ] )
589+ entries = prefix_search ( name ) . flatten #: as Array[Entry::InstanceVariable | Entry::ClassVariable]
614590 # Avoid wasting time linearizing ancestors if we didn't find anything
615591 return entries if entries . empty?
616592
@@ -640,7 +616,7 @@ def instance_variable_completion_candidates(name, owner_name)
640616
641617 #: (String name, String owner_name) -> Array[Entry::ClassVariable]
642618 def class_variable_completion_candidates ( name , owner_name )
643- entries = T . cast ( prefix_search ( name ) . flatten , T :: Array [ Entry ::ClassVariable ] )
619+ entries = prefix_search ( name ) . flatten #: as Array[Entry::ClassVariable]
644620 # Avoid wasting time linearizing ancestors if we didn't find anything
645621 return entries if entries . empty?
646622
@@ -676,15 +652,13 @@ def handle_change(uri, source = nil, &block)
676652 # indirect means like including a module that than includes the ancestor. Trying to figure out exactly which
677653 # ancestors need to be deleted is too expensive. Therefore, if any of the namespace entries has a change to their
678654 # ancestor hash, we clear all ancestors and start linearizing lazily again from scratch
679- original_map = T . cast (
680- original_entries . select { |e | e . is_a? ( Entry ::Namespace ) } ,
681- T ::Array [ Entry ::Namespace ] ,
682- ) . to_h { |e | [ e . name , e . ancestor_hash ] }
655+ original_map = original_entries
656+ . select { |e | e . is_a? ( Entry ::Namespace ) } #: as Array[Entry::Namespace]
657+ . to_h { |e | [ e . name , e . ancestor_hash ] }
683658
684- updated_map = T . cast (
685- updated_entries . select { |e | e . is_a? ( Entry ::Namespace ) } ,
686- T ::Array [ Entry ::Namespace ] ,
687- ) . to_h { |e | [ e . name , e . ancestor_hash ] }
659+ updated_map = updated_entries
660+ . select { |e | e . is_a? ( Entry ::Namespace ) } #: as Array[Entry::Namespace]
661+ . to_h { |e | [ e . name , e . ancestor_hash ] }
688662
689663 @ancestors . clear if original_map . any? { |name , hash | updated_map [ name ] != hash }
690664 end
@@ -713,7 +687,7 @@ def length
713687 def existing_or_new_singleton_class ( name )
714688 *_namespace , unqualified_name = name . split ( "::" )
715689 full_singleton_name = "#{ name } ::<Class:#{ unqualified_name } >"
716- singleton = T . cast ( self [ full_singleton_name ] &.first , T . nilable ( Entry ::SingletonClass ) )
690+ singleton = self [ full_singleton_name ] &.first #: as Entry::SingletonClass?
717691
718692 unless singleton
719693 attached_ancestor = self [ name ] &.first #: as !nil
@@ -841,14 +815,11 @@ def linearize_superclass( # rubocop:disable Metrics/ParameterLists
841815 )
842816 # Find the first class entry that has a parent class. Notice that if the developer makes a mistake and inherits
843817 # from two different classes in different files, we simply ignore it
844- superclass = T . cast (
845- if singleton_levels > 0
846- self [ attached_class_name ] &.find { |n | n . is_a? ( Entry ::Class ) && n . parent_class }
847- else
848- namespace_entries . find { |n | n . is_a? ( Entry ::Class ) && n . parent_class }
849- end ,
850- T . nilable ( Entry ::Class ) ,
851- )
818+ superclass = if singleton_levels > 0
819+ self [ attached_class_name ] &.find { |n | n . is_a? ( Entry ::Class ) && n . parent_class }
820+ else
821+ namespace_entries . find { |n | n . is_a? ( Entry ::Class ) && n . parent_class }
822+ end #: as Entry::Class?
852823
853824 if superclass
854825 # If the user makes a mistake and creates a class that inherits from itself, this method would throw a stack
@@ -882,7 +853,7 @@ def linearize_superclass( # rubocop:disable Metrics/ParameterLists
882853 elsif singleton_levels > 0
883854 # When computing the linearization for a module's singleton class, it inherits from the linearized ancestors of
884855 # the `Module` class
885- mod = T . cast ( self [ attached_class_name ] &.find { |n | n . is_a? ( Entry ::Module ) } , T . nilable ( Entry ::Module ) )
856+ mod = self [ attached_class_name ] &.find { |n | n . is_a? ( Entry ::Module ) } #: as Entry::Module?
886857
887858 if mod
888859 module_class_name_parts = [ "Module" ]
@@ -922,7 +893,7 @@ def resolve_alias(entry, seen_names)
922893 resolved_alias
923894 end
924895
925- #: (String name, Array[String] nesting, Array[String] seen_names) -> Array[( Entry::Namespace | Entry::ConstantAlias | Entry::UnresolvedConstantAlias) ]?
896+ #: (String name, Array[String] nesting, Array[String] seen_names) -> Array[Entry::Constant | Entry::ConstantAlias | Entry::Namespace | Entry:: UnresolvedConstantAlias]?
926897 def lookup_enclosing_scopes ( name , nesting , seen_names )
927898 nesting . length . downto ( 1 ) do |i |
928899 namespace = nesting [ 0 ...i ] #: as !nil
@@ -942,7 +913,7 @@ def lookup_enclosing_scopes(name, nesting, seen_names)
942913 nil
943914 end
944915
945- #: (String name, Array[String] nesting, Array[String] seen_names) -> Array[( Entry::Namespace | Entry::ConstantAlias | Entry::UnresolvedConstantAlias) ]?
916+ #: (String name, Array[String] nesting, Array[String] seen_names) -> Array[Entry::Constant | Entry::ConstantAlias | Entry::Namespace | Entry:: UnresolvedConstantAlias]?
946917 def lookup_ancestor_chain ( name , nesting , seen_names )
947918 *nesting_parts , constant_name = build_non_redundant_full_name ( name , nesting ) . split ( "::" )
948919 return if nesting_parts . empty?
@@ -1027,18 +998,13 @@ def build_non_redundant_full_name(name, nesting)
1027998 name_parts . join ( "::" )
1028999 end
10291000
1030- #: (String full_name, Array[String] seen_names) -> Array[( Entry::Namespace | Entry::ConstantAlias | Entry::UnresolvedConstantAlias) ]?
1001+ #: (String full_name, Array[String] seen_names) -> Array[Entry::Constant | Entry::ConstantAlias | Entry::Namespace | Entry:: UnresolvedConstantAlias]?
10311002 def direct_or_aliased_constant ( full_name , seen_names )
10321003 entries = @entries [ full_name ] || @entries [ follow_aliased_namespace ( full_name ) ]
10331004
1034- T . cast (
1035- entries &.map { |e | e . is_a? ( Entry ::UnresolvedConstantAlias ) ? resolve_alias ( e , seen_names ) : e } ,
1036- T . nilable ( T ::Array [ T . any (
1037- Entry ::Namespace ,
1038- Entry ::ConstantAlias ,
1039- Entry ::UnresolvedConstantAlias ,
1040- ) ] ) ,
1041- )
1005+ entries &.map do |e |
1006+ e . is_a? ( Entry ::UnresolvedConstantAlias ) ? resolve_alias ( e , seen_names ) : e
1007+ end #: as Array[Entry::Constant | Entry::ConstantAlias | Entry::Namespace | Entry::UnresolvedConstantAlias])?
10421008 end
10431009
10441010 # Attempt to resolve a given unresolved method alias. This method returns the resolved alias if we managed to
0 commit comments