Class: Rigor::LanguageServer::FoldingRangeProvider
- Inherits:
-
Object
- Object
- Rigor::LanguageServer::FoldingRangeProvider
- Defined in:
- lib/rigor/language_server/folding_range_provider.rb
Overview
Answers ‘textDocument/foldingRange` requests. Walks the Prism AST and emits one `FoldingRange` per foldable construct: `class` / `module` / `def` / `singleton class << self` / block (`do…end` or `…`). Skips single-line constructs (start_line == end_line) since there’s nothing to fold.
Ranges are LSP 0-based. ‘startLine` is the line containing the opening keyword (`class`, `def`); `endLine` is the last line OF the body — one line before the `end` keyword — so collapsed view shows the opener intact and hides the body only.
Instance Method Summary collapse
-
#initialize(buffer_table:, project_context:) ⇒ FoldingRangeProvider
constructor
A new instance of FoldingRangeProvider.
-
#provide(uri) ⇒ Array<Hash>?
LSP ‘FoldingRange[]` for the buffer, or nil when the URI isn’t open / parseable.
Constructor Details
#initialize(buffer_table:, project_context:) ⇒ FoldingRangeProvider
Returns a new instance of FoldingRangeProvider.
21 22 23 24 |
# File 'lib/rigor/language_server/folding_range_provider.rb', line 21 def initialize(buffer_table:, project_context:) @buffer_table = buffer_table @project_context = project_context end |
Instance Method Details
#provide(uri) ⇒ Array<Hash>?
Returns LSP ‘FoldingRange[]` for the buffer, or nil when the URI isn’t open / parseable.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rigor/language_server/folding_range_provider.rb', line 28 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 — fold whatever AST Prism # produced. Editors prefer a stale outline / fold map # over none. ranges = [] walk(parse_result.value, ranges) ranges end |