Class: Rigor::LanguageServer::FoldingRangeProvider
- Inherits:
-
Object
- Object
- Rigor::LanguageServer::FoldingRangeProvider
- Includes:
- BufferResolution
- 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.
20 21 22 23 |
# File 'lib/rigor/language_server/folding_range_provider.rb', line 20 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.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rigor/language_server/folding_range_provider.rb', line 27 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 — fold whatever AST Prism produced. Editors prefer a stale outline / # fold map over none. ranges = [] walk(parse_result.value, ranges) ranges end |