1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Syntax cache trait.
//!
//! This module defines the [`SyntaxCache`] trait for caching highlight results.
use std::ops::Range;
use crate::highlight::Annotation;
/// Cache for annotation results.
///
/// Implementations can provide various caching strategies for
/// annotation data to improve performance.
///
/// # Thread Safety
///
/// Implementations must be `Send + Sync` to allow use across threads.
///
/// # Example
///
/// ```ignore
/// // Insert annotations for a range
/// cache.insert(0..100, annotations);
///
/// // Later, retrieve cached annotations
/// if let Some(cached) = cache.get(0..100) {
/// // Use cached annotations
/// }
///
/// // After an edit, invalidate affected ranges
/// cache.invalidate_range(50..75);
/// ```
pub trait SyntaxCache: Send + Sync {
/// Get cached annotations for a byte range.
///
/// Returns `None` if the range is not cached or cache is stale.
///
/// # Arguments
///
/// * `byte_range` - The byte range to look up
fn get(&self, byte_range: Range<usize>) -> Option<Vec<Annotation>>;
/// Insert annotations into the cache.
///
/// # Arguments
///
/// * `byte_range` - The byte range these annotations cover
/// * `highlights` - The annotations to cache
fn insert(&mut self, byte_range: Range<usize>, highlights: Vec<Annotation>);
/// Invalidate cache entries that overlap with a range.
///
/// Called after edits to mark affected regions as stale.
///
/// # Arguments
///
/// * `byte_range` - The byte range that was modified
fn invalidate_range(&mut self, byte_range: Range<usize>);
/// Clear all cached data.
fn clear(&mut self);
/// Check if the cache is empty.
fn is_empty(&self) -> bool;
}
#[cfg(test)]
#[path = "cache_tests.rs"]
mod tests;