ass_editor/extensions/builtin/syntax_highlight/
extension.rs1use super::HighlightToken;
4use crate::extensions::{ExtensionCapability, ExtensionInfo, ExtensionState};
5
6#[cfg(not(feature = "std"))]
7use alloc::{
8 collections::BTreeMap as HashMap,
9 string::{String, ToString},
10 vec::Vec,
11};
12#[cfg(feature = "std")]
13use std::collections::HashMap;
14
15pub struct SyntaxHighlightExtension {
17 pub(super) info: ExtensionInfo,
18 pub(super) state: ExtensionState,
19 pub(super) token_cache: HashMap<String, Vec<HighlightToken>>,
21 pub(super) config: SyntaxHighlightConfig,
23}
24
25#[derive(Debug, Clone)]
27pub struct SyntaxHighlightConfig {
28 pub semantic_highlighting: bool,
30 pub highlight_tags: bool,
32 pub highlight_errors: bool,
34 pub max_tokens: usize,
36}
37
38impl Default for SyntaxHighlightConfig {
39 fn default() -> Self {
40 Self {
41 semantic_highlighting: true,
42 highlight_tags: true,
43 highlight_errors: true,
44 max_tokens: 10000,
45 }
46 }
47}
48
49impl SyntaxHighlightExtension {
50 pub fn new() -> Self {
52 let info = ExtensionInfo::new(
53 "syntax-highlight".to_string(),
54 "1.0.0".to_string(),
55 "ASS-RS Team".to_string(),
56 "Built-in syntax highlighting for ASS/SSA files".to_string(),
57 )
58 .with_capability(ExtensionCapability::SyntaxHighlighting)
59 .with_license("MIT".to_string());
60
61 Self {
62 info,
63 state: ExtensionState::Uninitialized,
64 token_cache: HashMap::new(),
65 config: SyntaxHighlightConfig::default(),
66 }
67 }
68
69 pub fn clear_cache(&mut self) {
71 self.token_cache.clear();
72 }
73
74 pub fn invalidate_document(&mut self, doc_id: &str) {
76 self.token_cache.remove(doc_id);
77 }
78}
79
80impl Default for SyntaxHighlightExtension {
81 fn default() -> Self {
82 Self::new()
83 }
84}