Skip to content

Commit

Permalink
TMP
Browse files Browse the repository at this point in the history
  • Loading branch information
Morriar committed Jun 12, 2024
1 parent 07bc37f commit 63e8856
Showing 1 changed file with 47 additions and 17 deletions.
64 changes: 47 additions & 17 deletions lib/ruby_lsp/requests/type_hierarchy_supertypes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,58 @@ def initialize(index, item)
sig { override.returns(T.nilable(T::Array[Interface::TypeHierarchyItem])) }
def perform
name = @item[:name]
super_types = @index.linearized_ancestors_of(name)
entries = @index[name]

super_types.filter_map do |super_type_name|
next if super_type_name == name
parents = T.let([], T::Array[RubyIndexer::Entry::Namespace])
return [] unless entries&.any?

entries = @index[super_type_name]
next unless entries
entries.each do |entry|
next unless entry.is_a?(RubyIndexer::Entry::Namespace)

entries.map do |entry|
range = range_from_location(entry.location)
if entry.is_a?(RubyIndexer::Entry::Class)
parent_class_name = entry.parent_class
if parent_class_name
resolved_parent_entries = @index.resolve(parent_class_name, entry.nesting)
resolved_parent_entries&.each do |entry|
next unless entry.is_a?(RubyIndexer::Entry::Class)

Interface::TypeHierarchyItem.new(
name: entry.name,
kind: kind_for_entry(entry),
uri: URI::Generic.from_path(path: entry.file_path).to_s,
range: range,
selection_range: range,
)
parents << entry
end
end
end
end.flatten
rescue RubyIndexer::Index::NonExistingNamespaceError
nil

entry.mixin_operations.each do |mixin_operation|
next if mixin_operation.is_a?(RubyIndexer::Entry::Extend)

mixin_name = mixin_operation.module_name
resolved_mixin_entries = @index.resolve(mixin_name, entry.nesting)
next unless resolved_mixin_entries

resolved_mixin_entries.each do |mixin_entry|
next unless mixin_entry.is_a?(RubyIndexer::Entry::Module)

parents << mixin_entry
end
end
end

parents.uniq.map { |entry| hierarchy_item(entry) }
end

private

sig { params(entry: RubyIndexer::Entry).returns(Interface::TypeHierarchyItem) }
def hierarchy_item(entry)
range = range_from_location(entry.location)

Interface::TypeHierarchyItem.new(
name: entry.name,
kind: kind_for_entry(entry),
uri: URI::Generic.from_path(path: entry.file_path).to_s,
range: range,
selection_range: range,
detail: entry.file_name,
)
end
end
end
Expand Down

0 comments on commit 63e8856

Please sign in to comment.