use std::{ops::Range, sync::Arc};
use crate::{
edit::SyntaxEdit,
factory::SyntaxDriverFactory,
fold::FoldRange,
highlight::{Annotation, SyntaxContext},
injection::Injection,
scope::ContextHierarchy,
textobject::{TextObjectKind, TextObjectRange, TextObjectScope},
};
pub trait SyntaxDriver: Send + Sync {
fn language(&self) -> &str;
fn parse(&mut self, content: &str);
fn update(&mut self, content: &str, edit: &SyntaxEdit);
fn highlights(&self, byte_range: Range<usize>) -> Vec<Annotation>;
fn injections(&self) -> Vec<Injection> {
Vec::new()
}
fn decorations(&self, _byte_range: Range<usize>) -> Vec<Annotation> {
Vec::new()
}
fn folds(&self) -> Vec<FoldRange> {
Vec::new()
}
fn indent_for(&self, _line: usize) -> Option<usize> {
None
}
fn set_injection_factory(&mut self, _factory: Arc<dyn SyntaxDriverFactory>) {}
fn set_injection_depth(&mut self, _depth: u8) {}
fn set_default_injection_language(&mut self, _language: &str) {}
fn scopes(&self, _line: u32, _col: u32) -> ContextHierarchy {
ContextHierarchy::empty()
}
#[cfg_attr(coverage_nightly, coverage(off))]
fn context_at_byte(&self, _byte_offset: usize) -> SyntaxContext {
SyntaxContext::Code
}
#[cfg_attr(coverage_nightly, coverage(off))]
fn textobject_range(
&self,
_kind: TextObjectKind,
_scope: TextObjectScope,
_line: u32,
_col: u32,
) -> Option<TextObjectRange> {
None
}
fn is_parsed(&self) -> bool;
}
#[cfg(test)]
#[path = "driver_tests.rs"]
mod tests;