You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add code folding support via Tree-sitter queries
Implement code folding across the editor with per-language fold detection
using Tree-sitter syntax queries. Users can collapse and expand foldable
regions (functions, classes, blocks, etc.) by clicking toggle buttons in
a new gutter column.
Core changes:
- Add FoldRange type and getFoldRanges() to Code, computing foldable
regions from Tree-sitter captures on every reparse
- Add foldsQuery to the Lang interface so each language declares its own
foldable node types
- Add foldsQuery definitions for all 18 supported languages (TypeScript,
JavaScript, Rust, Python, Go, C, C++, C#, Java, Kotlin, Lua, Bash,
CSS, HTML, JSON, TOML, YAML, Zig)
- Track collapsed fold state (collapsedFoldStarts) in AnycodeEditor and
pass it through EditorState to the renderer
- Integrate fold visibility into the VisualRow pipeline — folded lines
are excluded from visual rows, interacting correctly with focused diff
separators
- Add a new .folds gutter column with expand/collapse toggle buttons,
including CSS hover/opacity animations
- Extend LineRenderer.createLineElements to produce fold indicator cells
- Extend DiffRenderer to handle the fold column (ghost lines, gap rows,
separator logic aware of folded regions)
- Refactor mouse.ts to handle clicks on the new fold column via a
unified .closest('.bt, .ln, .fd') lookup
- Adjust selection rendering to clamp offsets that fall within fold gaps
Performance:
- Pre-build a Set<number> of all hidden line indices in
updateCollapsedMap for O(1) isHiddenByFold lookups instead of
iterating over collapsed intervals per line
Cleanup:
- Remove Lua-specific hack from foldRangeFromNode; use function_body
instead of function_statement in Lua foldsQuery for correct ranges
- Fix Lua comment prefix from '#' to '--'
- Add yaml/yml extension mappings
Tests:
- Add folding.test.ts with coverage for 10 languages
- Add DiffRenderer test cases for fold-aware separator insertion
0 commit comments