Sha256: 48632fe5b102768c9ac7764a60cb2c4adb80de7becf3d5c1341326a0123a2be7

Contents?: true

Size: 1.32 KB

Versions: 40

Compression:

Stored size: 1.32 KB

Contents

# typed: strict
# frozen_string_literal: true

module RubyLsp
  module ResponseBuilders
    class DocumentSymbol < ResponseBuilder
      ResponseType = type_member { { fixed: T::Array[Interface::DocumentSymbol] } }

      class SymbolHierarchyRoot
        extend T::Sig

        sig { returns(T::Array[Interface::DocumentSymbol]) }
        attr_reader :children

        sig { void }
        def initialize
          @children = T.let([], T::Array[Interface::DocumentSymbol])
        end
      end

      extend T::Sig

      sig { void }
      def initialize
        super
        @stack = T.let(
          [SymbolHierarchyRoot.new],
          T::Array[T.any(SymbolHierarchyRoot, Interface::DocumentSymbol)],
        )
      end

      sig { params(symbol: Interface::DocumentSymbol).void }
      def push(symbol)
        @stack << symbol
      end

      alias_method(:<<, :push)

      sig { returns(T.nilable(Interface::DocumentSymbol)) }
      def pop
        if @stack.size > 1
          T.cast(@stack.pop, Interface::DocumentSymbol)
        end
      end

      sig { returns(T.any(SymbolHierarchyRoot, Interface::DocumentSymbol)) }
      def last
        T.must(@stack.last)
      end

      sig { override.returns(T::Array[Interface::DocumentSymbol]) }
      def response
        T.must(@stack.first).children
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
ruby-lsp-0.19.1 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.19.0 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.18.4 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.18.3 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.18.2 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.18.1 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.18.0 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.17.17 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.17.16 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.17.15 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.17.14 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.17.13 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.17.12 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.17.11 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.17.10 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.17.9 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.17.8 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.17.7 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.17.6 lib/ruby_lsp/response_builders/document_symbol.rb
ruby-lsp-0.17.5 lib/ruby_lsp/response_builders/document_symbol.rb