Class: RubyLsp::Requests::DocumentSymbol

Inherits:
Request
  • Object
show all
Extended by:
T::Generic, T::Sig
Defined in:
lib/ruby_lsp/requests/document_symbol.rb

Overview

![Document symbol demo](../../document_symbol.gif)

The [document symbol](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 “‘

Constant Summary collapse

ResponseType =
type_member { { fixed: T::Array[Interface::DocumentSymbol] } }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dispatcher) ⇒ DocumentSymbol



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ruby_lsp/requests/document_symbol.rb', line 52

def initialize(dispatcher)
  super()
  @listeners = T.let(
    [Listeners::DocumentSymbol.new(dispatcher)],
    T::Array[Listener[ResponseType]],
  )

  Addon.addons.each do |addon|
    addon_listener = addon.create_document_symbol_listener(dispatcher)
    @listeners << addon_listener if addon_listener
  end
end

Class Method Details

.providerObject



39
40
41
42
43
44
45
46
# File 'lib/ruby_lsp/requests/document_symbol.rb', line 39

def provider
  Interface::DocumentSymbolClientCapabilities.new(
    hierarchical_document_symbol_support: true,
    symbol_kind: {
      value_set: (Constant::SymbolKind::FILE..Constant::SymbolKind::TYPE_PARAMETER).to_a,
    },
  )
end

Instance Method Details

#performObject



66
67
68
# File 'lib/ruby_lsp/requests/document_symbol.rb', line 66

def perform
  @listeners.flat_map(&:response).compact
end