Sha256: 33e0877921de5d7cf7e76bc5daddee385409329e2b5d4821756f034c53064ff1

Contents?: true

Size: 1.8 KB

Versions: 7

Compression:

Stored size: 1.8 KB

Contents

# typed: strict
# frozen_string_literal: true

require "ruby_lsp/listeners/document_symbol"

module RubyLsp
  module Requests
    # ![Document symbol demo](../../document_symbol.gif)
    #
    # The [document
    # symbol](https://microsoft.github.io/language-server-protocol/specification#textDocument_documentSymbol) request
    # informs the editor of all the important symbols, such as classes, variables, and methods, defined in a file. With
    # this information, the editor can populate breadcrumbs, file outline and allow for fuzzy symbol searches.
    #
    # In VS Code, fuzzy symbol search can be accessed by opening the command palette and inserting an `@` symbol.
    #
    # # Example
    #
    # ```ruby
    # class Person # --> document symbol: class
    #   attr_reader :age # --> document symbol: field
    #
    #   def initialize
    #     @age = 0 # --> document symbol: variable
    #   end
    #
    #   def age # --> document symbol: method
    #   end
    # end
    # ```
    class DocumentSymbol < Request
      extend T::Sig

      class << self
        extend T::Sig

        sig { returns(Interface::DocumentSymbolOptions) }
        def provider
          Interface::DocumentSymbolOptions.new
        end
      end

      sig { params(uri: URI::Generic, dispatcher: Prism::Dispatcher).void }
      def initialize(uri, dispatcher)
        super()
        @response_builder = T.let(ResponseBuilders::DocumentSymbol.new, ResponseBuilders::DocumentSymbol)
        Listeners::DocumentSymbol.new(@response_builder, uri, dispatcher)

        Addon.addons.each do |addon|
          addon.create_document_symbol_listener(@response_builder, dispatcher)
        end
      end

      sig { override.returns(T::Array[Interface::DocumentSymbol]) }
      def perform
        @response_builder.response
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ruby-lsp-0.17.17 lib/ruby_lsp/requests/document_symbol.rb
ruby-lsp-0.17.16 lib/ruby_lsp/requests/document_symbol.rb
ruby-lsp-0.17.15 lib/ruby_lsp/requests/document_symbol.rb
ruby-lsp-0.17.14 lib/ruby_lsp/requests/document_symbol.rb
ruby-lsp-0.17.13 lib/ruby_lsp/requests/document_symbol.rb
ruby-lsp-0.17.12 lib/ruby_lsp/requests/document_symbol.rb
ruby-lsp-0.17.11 lib/ruby_lsp/requests/document_symbol.rb