Oak Code Folding
A lightweight and efficient code folding engine for the Oak ecosystem, designed to provide accurate folding ranges based on AST analysis.
🎯 Overview
Oak Code Folding is a specialized library for calculating folding ranges in source code. It leverages oak-core's red-green tree structure to identify logical blocks that can be collapsed in an editor, such as function bodies, class definitions, large comments, and import blocks.
✨ Features
- AST-Based Folding: Precise folding ranges derived from the syntax tree rather than indentation.
- Folding Kinds: Support for different types of folding ranges (Comments, Imports, Regions).
- Language Agnostic: Extensible trait-based system that works with any language implemented in Oak.
- Zero-Cost Abstractions: Minimal overhead for range calculations.
- LSP Compatible: Designed to integrate seamlessly with the Language Server Protocol.
🚀 Quick Start
Basic example of implementing a folding provider:
use ;
use ;
;
📋 Examples
Implementing Folding for a Language
use ;
use RedNode;
use MyLanguage;
;
🏗️ Supported Folding Kinds
The engine supports several standard folding kinds:
FoldingRangeKind::Comment: For multi-line comment blocks.FoldingRangeKind::Imports: For grouped import/include statements.FoldingRangeKind::Region: For custom user-defined regions (e.g.,#regionin C#).
📊 Performance
- Fast Traversal: Optimized tree traversal using
oak-corevisitors. - Minimal Allocations: Uses efficient collection handling for range results.
- Incremental Updates: Designed to work with Oak's incremental parsing system.
🔗 Integration
Oak Code Folding is a core component used by:
- Oak LSP: Provides
textDocument/foldingRangesupport. - Oak IDE Plugins: Powers code folding in various editors.
🤝 Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
Oak Code Folding - Accurate code folding for every language 🚀