Class: RubyLsp::Requests::PrepareTypeHierarchy
- Includes:
- Support::Common
- Defined in:
- lib/ruby_lsp/requests/prepare_type_hierarchy.rb
Overview
The [prepare type hierarchy request](microsoft.github.io/language-server-protocol/specification#textDocument_prepareTypeHierarchy) displays the list of ancestors (supertypes) and descendants (subtypes) for the selected type.
Currently only supports supertypes due to a limitation of the index.
Class Method Summary collapse
-
.provider ⇒ Object
: -> Interface::TypeHierarchyOptions.
Instance Method Summary collapse
-
#initialize(document, index, position) ⇒ PrepareTypeHierarchy
constructor
: ((RubyDocument | ERBDocument) document, RubyIndexer::Index index, Hash[Symbol, untyped] position) -> void.
-
#perform ⇒ Object
: -> Array?.
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?
Constructor Details
#initialize(document, index, position) ⇒ PrepareTypeHierarchy
: ((RubyDocument | ERBDocument) document, RubyIndexer::Index index, Hash[Symbol, untyped] position) -> void
22 23 24 25 26 27 28 |
# File 'lib/ruby_lsp/requests/prepare_type_hierarchy.rb', line 22 def initialize(document, index, position) super() @document = document @index = index @position = position end |
Class Method Details
.provider ⇒ Object
: -> Interface::TypeHierarchyOptions
16 17 18 |
# File 'lib/ruby_lsp/requests/prepare_type_hierarchy.rb', line 16 def provider Interface::TypeHierarchyOptions.new end |
Instance Method Details
#perform ⇒ Object
: -> Array?
32 33 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 |
# File 'lib/ruby_lsp/requests/prepare_type_hierarchy.rb', line 32 def perform context = @document.locate_node( @position, node_types: [ Prism::ConstantReadNode, Prism::ConstantWriteNode, Prism::ConstantPathNode, ], ) node = context.node parent = context.parent return unless node && parent target = determine_target(node, parent, @position) entries = @index.resolve(target.slice, context.nesting) return unless entries # While the spec allows for multiple entries, VSCode seems to only support one # We'll just return the first one for now first_entry = entries.first #: as !nil range = range_from_location(first_entry.location) [ Interface::TypeHierarchyItem.new( name: first_entry.name, kind: kind_for_entry(first_entry), uri: first_entry.uri.to_s, range: range, selection_range: range, ), ] end |