Class: Rigor::LanguageServer::DocumentSymbolProvider
- Inherits:
-
Object
- Object
- Rigor::LanguageServer::DocumentSymbolProvider
- 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
-
#initialize(buffer_table:, project_context:) ⇒ DocumentSymbolProvider
constructor
A new instance of DocumentSymbolProvider.
-
#provide(uri) ⇒ Array<Hash>?
LSP ‘DocumentSymbol[]` for the buffer at `uri`.
Constructor Details
#initialize(buffer_table:, project_context:) ⇒ DocumentSymbolProvider
Returns a new instance of DocumentSymbolProvider.
26 27 28 29 |
# File 'lib/rigor/language_server/document_symbol_provider.rb', line 26 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.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rigor/language_server/document_symbol_provider.rb', line 35 def provide(uri) path = Uri.to_path(uri) return nil if path.nil? entry = @buffer_table[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 |