Class: RubyLsp::Requests::TypeHierarchySupertypes
- Extended by:
- T::Sig
- Includes:
- Support::Common
- Defined in:
- lib/ruby_lsp/requests/type_hierarchy_supertypes.rb
Overview

The [type hierarchy supertypes request](microsoft.github.io/language-server-protocol/specification#typeHierarchy_supertypes) displays the list of ancestors (supertypes) for the selected type.
# Example
“‘ruby class Foo; end class Bar < Foo; end
puts Bar # <– right click on ‘Bar` and select “Show Type Hierarchy” “`
Instance Method Summary collapse
-
#initialize(index, item) ⇒ TypeHierarchySupertypes
constructor
A new instance of TypeHierarchySupertypes.
- #perform ⇒ Object
Methods included from Support::Common
#categorized_markdown_from_index_entries, #constant_name, #create_code_lens, #each_constant_path_part, #kind_for_entry, #markdown_from_index_entries, #namespace_constant_name, #not_in_dependencies?, #range_from_location, #range_from_node, #self_receiver?, #sorbet_level_true_or_higher?, #visible?
Constructor Details
#initialize(index, item) ⇒ TypeHierarchySupertypes
Returns a new instance of TypeHierarchySupertypes.
26 27 28 29 30 31 |
# File 'lib/ruby_lsp/requests/type_hierarchy_supertypes.rb', line 26 def initialize(index, item) super() @index = index @item = item end |
Instance Method Details
#perform ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ruby_lsp/requests/type_hierarchy_supertypes.rb', line 34 def perform name = @item[:name] entries = @index[name] parents = T.let(Set.new, T::Set[RubyIndexer::Entry::Namespace]) return unless entries&.any? entries.each do |entry| next unless entry.is_a?(RubyIndexer::Entry::Namespace) 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) parents << entry end end end entry.mixin_operations.each do |mixin_operation| 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.map { |entry| hierarchy_item(entry) } end |