Class: Rigor::LanguageServer::DocumentSymbolProvider

Inherits:
Object
  • Object
show all
Includes:
BufferResolution
Defined in:
lib/rigor/language_server/document_symbol_provider.rb

Overview

Answers textDocument/documentSymbol requests by walking the Prism AST and emitting one LSP DocumentSymbol per ClassNode / ModuleNode / DefNode. Nested classes / modules / methods nest in the children array so the editor's outline tree mirrors the source structure.

SymbolKind mapping (LSP § "SymbolKind"):

  • Class (5) — class Foo
  • Module (2) — module Foo
  • Method (6) — def m inside a class / module
  • Function (12) — def m at top-level (no enclosing class)

Constant Summary collapse

KIND_MODULE =
2
KIND_CLASS =
5
KIND_METHOD =
6
KIND_FUNCTION =
12

Instance Method Summary collapse

Constructor Details

#initialize(buffer_table:, project_context:) ⇒ DocumentSymbolProvider

Returns a new instance of DocumentSymbolProvider.



27
28
29
30
# File 'lib/rigor/language_server/document_symbol_provider.rb', line 27

def initialize(buffer_table:, project_context:)
  @buffer_table = buffer_table
  @project_context = project_context
end

Instance Method Details

#provide(uri) ⇒ Array<Hash>?

Returns LSP DocumentSymbol[] for the buffer at uri. Returns nil when the URI isn't open or doesn't parse cleanly enough to surface symbols — LSP clients fall back to no-outline in that case.

Returns:

  • (Array<Hash>, nil)

    LSP DocumentSymbol[] for the buffer at uri. Returns nil when the URI isn't open or doesn't parse cleanly enough to surface symbols — LSP clients fall back to no-outline in that case.



36
37
38
39
40
41
42
43
44
45
# File 'lib/rigor/language_server/document_symbol_provider.rb', line 36

def provide(uri)
  path, entry = buffer_for(uri)
  return nil if entry.nil?

  parse_result = Prism.parse(entry.bytes, filepath: path,
                                          version: @project_context.configuration.target_ruby)
  # Tolerate partial parse errors: walk what Prism gave us anyway. Editors prefer a stale outline over
  # no outline.
  walk_top_level(parse_result.value)
end