Folding ranges
textDocument/foldingRange for Pine blocks, type/enum/function bodies, and //#region comments.
This page
Abstract
textDocument/foldingRange folds indented Pine blocks so editors can collapse if / for / while / switch / once, FunctionDef / TypeDef / EnumDef, and //#region … //#endregion pairs. Empty or unparsed documents return [].
Conceptual model
Rendering…
Control blocks are expressions (If, ForTo, ForIn, While, Switch, Once) and often sit under Expr. The walker visits the inner node. Parser end_lineno can land on the next statement, so the handler prefers the indented body when source lines are available (else at the header indent continues an if). Single-line constructs are skipped.
Interface surface
- Method:
textDocument/foldingRange - Capability:
folding_range_provider=True - Handler:
features/folding.py→handle_folding_range(receives version-matchedtree=doc.valid_ast)
Each range uses 0-based start_line / end_line. Region comment pairs set kind: "region".
| Construct | Folded |
|---|---|
if / else if / else | keyword line through the last indented body line |
for … to / for … in | same |
while / switch / once | same |
FunctionDef / TypeDef / EnumDef | declaration through last body line |
//#region … //#endregion | start through end marker (# region / # endregion too) |
Returns [] for empty source, parse failure, or tree=None.
Internals
| Path | Role |
|---|---|
src/pynescript/langserver/features/folding.py | AST walk + indent clamp + region scan |
src/pynescript/langserver/config.py | folding_range_provider=True |
src/pynescript/langserver/server.py | TEXT_DOCUMENT_FOLDING_RANGE handler |
Tests: tests/test_lsp_features.py.
See also
- Architecture — declared capabilities
- Selection ranges — expand selection over the same blocks
- Navigation — outline symbols share AST line spans