Expand description
Syntax highlighting driver for reovim.
IMPORTANT: This crate defines ONLY the trait interface for syntax
highlighting. It does NOT depend on tree-sitter or any parsing library.
Those are implementation details of language modules (server/modules/treesitter-*/).
§Design Philosophy
This crate follows the Linux kernel “mechanism vs policy” principle:
- Driver provides MECHANISM: The
HighlightCategorytype andAnnotationstruct define HOW highlights are represented (open, string-based categories). - Modules provide POLICY: Language modules decide WHAT categories to emit.
§Architecture
server/lib/drivers/syntax/ <-- HighlightCategory, Annotation, SyntaxDriver
^
| implements
|
server/lib/drivers/syntax-treesitter/ <-- Tree-sitter based implementations§Components
SyntaxDriver- Main parsing and highlighting interfaceSyntaxDriverFactory- Creates drivers for languagesLanguageRegistry- Language detection and metadataSyntaxCache- Highlight result cachingHighlightCategory- Open string-based highlight categoriesAnnotation- A highlighted byte range with category and kindSyntaxEdit- Edit description for incremental parsingFoldRange,FoldKind- Foldable code regionsInjection- Embedded language regionsLanguageInfo,CommentTokens- Language metadata
§Example
ⓘ
use reovim_driver_syntax::*;
// Factory creates drivers for supported languages
let factory: Box<dyn SyntaxDriverFactory> = get_factory();
// Create driver for Rust
let mut driver = factory.create("rust").unwrap();
// Parse content
driver.parse("fn main() { println!(\"Hello\"); }");
// Get highlights for rendering
let highlights = driver.highlights(0..100);
for ann in highlights {
println!("{:?}: {}", ann.byte_range(), ann.category.as_str());
}§NO tree-sitter dependency!
This crate must NOT depend on tree-sitter or any parsing library. Tree-sitter is an implementation detail of language modules.
Re-exports§
pub use bracket::BracketConfig;pub use bracket::BracketConfigStore;pub use bracket::BracketPair;pub use decoration::DecorationCapture;pub use decoration::DecorationRule;pub use decoration::apply_rules;pub use indent::IndentConfig;pub use indent::IndentConfigStore;pub use textobject::TextObjectKind;pub use textobject::TextObjectRange;pub use textobject::TextObjectScope;pub use state::SyntaxSessionState;
Modules§
- bracket
- Bracket configuration types and store for language-aware bracket pairing.
- decoration
- Decoration types for the syntax driver layer.
- indent
- Indent configuration types and store for language-aware indent guides.
- state
- Per-session syntax driver storage.
- textobject
- Semantic text object types for treesitter-based code navigation.
Structs§
- Annotation
- A single annotation on a buffer range.
- Comment
Tokens - Comment syntax for a language.
- Composite
Factory - A factory that aggregates multiple
SyntaxDriverFactoryinstances. - Context
Hierarchy - Hierarchy of enclosing scopes at a cursor position.
- Default
Language Registry - Concrete implementation of
LanguageRegistrybuilt fromLanguageInfoentries. - Fold
Range - A foldable range in the buffer.
- Highlight
Category - Interned string-based highlight category.
- Injection
- An injection point for embedded languages.
- Language
Info - Information about a supported language.
- Language
Info Store - Store for language info registered by modules during init.
- Scope
Range - A scope boundary range in the buffer.
- Syntax
Edit - Edit information for incremental parsing.
- Syntax
Factory Store - Store for syntax driver factories registered by modules during init.
Enums§
- Fold
Kind - Kind of fold (what construct it represents).
- Module
Error - Errors that can occur during module operations.
- Scope
Kind - Kind of scope (what construct it represents).
- Syntax
Context - Syntax context at a byte position.
Traits§
- Language
Registry - Registry for language metadata and detection.
- Syntax
Cache - Cache for annotation results.
- Syntax
Driver - Main parsing interface for syntax highlighting.
- Syntax
Driver Factory - Factory for creating syntax drivers.
Functions§
- language_
id_ from_ path - Detect language ID from a file path’s extension.