reovim_driver_syntax/lib.rs
1#![cfg_attr(coverage_nightly, allow(unused_features))]
2#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
3//! Syntax highlighting driver for reovim.
4//!
5//! **IMPORTANT:** This crate defines ONLY the trait interface for syntax
6//! highlighting. It does NOT depend on tree-sitter or any parsing library.
7//! Those are implementation details of language modules (`server/modules/treesitter-*/`).
8//!
9//! # Design Philosophy
10//!
11//! This crate follows the Linux kernel "mechanism vs policy" principle:
12//!
13//! - **Driver provides MECHANISM**: The [`HighlightCategory`] type and [`Annotation`] struct
14//! define HOW highlights are represented (open, string-based categories).
15//! - **Modules provide POLICY**: Language modules decide WHAT categories to emit.
16//!
17//! # Architecture
18//!
19//! ```text
20//! server/lib/drivers/syntax/ <-- HighlightCategory, Annotation, SyntaxDriver
21//! ^
22//! | implements
23//! |
24//! server/lib/drivers/syntax-treesitter/ <-- Tree-sitter based implementations
25//! ```
26//!
27//! # Components
28//!
29//! - [`SyntaxDriver`] - Main parsing and highlighting interface
30//! - [`SyntaxDriverFactory`] - Creates drivers for languages
31//! - [`LanguageRegistry`] - Language detection and metadata
32//! - [`SyntaxCache`] - Highlight result caching
33//! - [`HighlightCategory`] - Open string-based highlight categories
34//! - [`Annotation`] - A highlighted byte range with category and kind
35//! - [`SyntaxEdit`] - Edit description for incremental parsing
36//! - [`FoldRange`], [`FoldKind`] - Foldable code regions
37//! - [`Injection`] - Embedded language regions
38//! - [`LanguageInfo`], [`CommentTokens`] - Language metadata
39//!
40//! # Example
41//!
42//! ```ignore
43//! use reovim_driver_syntax::*;
44//!
45//! // Factory creates drivers for supported languages
46//! let factory: Box<dyn SyntaxDriverFactory> = get_factory();
47//!
48//! // Create driver for Rust
49//! let mut driver = factory.create("rust").unwrap();
50//!
51//! // Parse content
52//! driver.parse("fn main() { println!(\"Hello\"); }");
53//!
54//! // Get highlights for rendering
55//! let highlights = driver.highlights(0..100);
56//! for ann in highlights {
57//! println!("{:?}: {}", ann.byte_range(), ann.category.as_str());
58//! }
59//! ```
60//!
61//! # NO tree-sitter dependency!
62//!
63//! This crate must NOT depend on tree-sitter or any parsing library.
64//! Tree-sitter is an implementation detail of language modules.
65
66// ============================================================================
67// Modules
68// ============================================================================
69
70pub mod bracket;
71mod cache;
72mod composite;
73pub mod decoration;
74mod detect;
75mod driver;
76mod edit;
77mod error;
78mod factory;
79mod fold;
80mod highlight;
81pub mod indent;
82mod injection;
83mod lang_store;
84mod registry;
85mod scope;
86pub mod state;
87mod store;
88pub mod textobject;
89
90// ============================================================================
91// Re-exports
92// ============================================================================
93
94// Core traits
95pub use {
96 cache::SyntaxCache, composite::CompositeFactory, detect::language_id_from_path,
97 driver::SyntaxDriver, factory::SyntaxDriverFactory, registry::LanguageRegistry,
98 store::SyntaxFactoryStore,
99};
100
101// Types
102pub use {
103 bracket::{BracketConfig, BracketConfigStore, BracketPair},
104 decoration::{DecorationCapture, DecorationRule, apply_rules},
105 edit::SyntaxEdit,
106 fold::{FoldKind, FoldRange},
107 highlight::{Annotation, HighlightCategory, SyntaxContext},
108 indent::{IndentConfig, IndentConfigStore},
109 injection::Injection,
110 lang_store::LanguageInfoStore,
111 registry::{CommentTokens, DefaultLanguageRegistry, LanguageInfo},
112 scope::{ContextHierarchy, ScopeKind, ScopeRange},
113 textobject::{TextObjectKind, TextObjectRange, TextObjectScope},
114};
115
116// Error types
117pub use error::ModuleError;
118
119// Per-session syntax driver storage
120pub use state::SyntaxSessionState;