pub struct SyntaxSessionState { /* private fields */ }Expand description
Per-session syntax state stored in ExtensionMap.
Maps buffer IDs to their syntax drivers. Each buffer can have at most one syntax driver (language-specific highlighting).
§Design Rationale
Originally the plan called for storing syntax drivers in the kernel’s
Buffer struct. However, the kernel has a strict rule that it “depends
only on arch”. Storing drivers here in the session layer:
- Preserves kernel purity (no syntax dependency in kernel)
- Maintains per-buffer semantics (each buffer has its own driver)
- Uses existing
ExtensionMappattern (consistent withVimSessionState)
§Thread Safety
Access should be synchronized at the session level via with_state_mut().
Implementations§
Source§impl SyntaxSessionState
impl SyntaxSessionState
Sourcepub fn new() -> SyntaxSessionState
pub fn new() -> SyntaxSessionState
Create a new empty syntax state.
Sourcepub fn set_factory(&mut self, factory: Arc<dyn SyntaxDriverFactory>)
pub fn set_factory(&mut self, factory: Arc<dyn SyntaxDriverFactory>)
Set the factory used to create new syntax drivers.
Accepts Arc for shared ownership (populated from SyntaxFactoryStore).
Sourcepub fn factory(&self) -> Option<&dyn SyntaxDriverFactory>
pub fn factory(&self) -> Option<&dyn SyntaxDriverFactory>
Get the factory (if set).
Sourcepub fn set_registry(&mut self, registry: Arc<dyn LanguageRegistry>)
pub fn set_registry(&mut self, registry: Arc<dyn LanguageRegistry>)
Set the language registry used for language detection.
Sourcepub fn registry(&self) -> Option<&dyn LanguageRegistry>
pub fn registry(&self) -> Option<&dyn LanguageRegistry>
Get the language registry (if set).
Sourcepub fn detect_language(&self, path: &str) -> Option<String>
pub fn detect_language(&self, path: &str) -> Option<String>
Detect language from a file path using the registry.
Returns None if no registry is set or the language is not recognized.
Sourcepub fn ensure_driver_from_path(
&mut self,
buffer_id: BufferId,
path: &str,
content: &str,
) -> bool
pub fn ensure_driver_from_path( &mut self, buffer_id: BufferId, path: &str, content: &str, ) -> bool
Ensure a driver exists for a buffer by detecting language from file path.
Combines language detection (via registry) and driver creation (via factory).
Returns true if a driver exists after the call.
Sourcepub fn get(&self, buffer_id: BufferId) -> Option<&dyn SyntaxDriver>
pub fn get(&self, buffer_id: BufferId) -> Option<&dyn SyntaxDriver>
Get a reference to the driver for a buffer.
Sourcepub fn get_mut(&mut self, buffer_id: BufferId) -> Option<&mut dyn SyntaxDriver>
pub fn get_mut(&mut self, buffer_id: BufferId) -> Option<&mut dyn SyntaxDriver>
Get a mutable reference to the driver for a buffer.
Sourcepub fn set(&mut self, buffer_id: BufferId, driver: Box<dyn SyntaxDriver>)
pub fn set(&mut self, buffer_id: BufferId, driver: Box<dyn SyntaxDriver>)
Set the driver for a buffer.
Replaces any existing driver for this buffer.
Sourcepub fn remove(&mut self, buffer_id: BufferId) -> Option<Box<dyn SyntaxDriver>>
pub fn remove(&mut self, buffer_id: BufferId) -> Option<Box<dyn SyntaxDriver>>
Remove the driver for a buffer.
Call this when a buffer is closed to clean up resources.
Sourcepub fn has_driver(&self, buffer_id: BufferId) -> bool
pub fn has_driver(&self, buffer_id: BufferId) -> bool
Check if a buffer has a syntax driver.
Sourcepub fn ensure_driver(
&mut self,
buffer_id: BufferId,
language_id: &str,
content: &str,
) -> bool
pub fn ensure_driver( &mut self, buffer_id: BufferId, language_id: &str, content: &str, ) -> bool
Get or create a driver for a buffer.
If no driver exists and a factory is set, attempts to create one
for the given language. Returns false if:
- No driver exists AND no factory is set
- No driver exists AND factory doesn’t support the language
After calling this, use get_mut() to access the driver.
Trait Implementations§
Source§impl Debug for SyntaxSessionState
impl Debug for SyntaxSessionState
Source§impl Default for SyntaxSessionState
impl Default for SyntaxSessionState
Source§fn default() -> SyntaxSessionState
fn default() -> SyntaxSessionState
Source§impl SessionExtension for SyntaxSessionState
impl SessionExtension for SyntaxSessionState
Source§fn create() -> SyntaxSessionState
fn create() -> SyntaxSessionState
Source§fn as_text_input_sink(&mut self) -> Option<&mut dyn TextInputSink>
fn as_text_input_sink(&mut self) -> Option<&mut dyn TextInputSink>
TextInputSink if this extension accepts text input. Read moreAuto Trait Implementations§
impl Freeze for SyntaxSessionState
impl !RefUnwindSafe for SyntaxSessionState
impl Send for SyntaxSessionState
impl Sync for SyntaxSessionState
impl Unpin for SyntaxSessionState
impl UnsafeUnpin for SyntaxSessionState
impl !UnwindSafe for SyntaxSessionState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> SessionExtensionDyn for Twhere
T: SessionExtension,
impl<T> SessionExtensionDyn for Twhere
T: SessionExtension,
Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut dyn Any for mutable downcasting.Source§fn as_text_input_sink(&mut self) -> Option<&mut dyn TextInputSink>
fn as_text_input_sink(&mut self) -> Option<&mut dyn TextInputSink>
TextInputSink if this extension accepts text input.