Skip to main content

SyntaxSessionState

Struct SyntaxSessionState 

Source
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 ExtensionMap pattern (consistent with VimSessionState)

§Thread Safety

Access should be synchronized at the session level via with_state_mut().

Implementations§

Source§

impl SyntaxSessionState

Source

pub fn new() -> Self

Create a new empty syntax state.

Source

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).

Source

pub fn factory(&self) -> Option<&dyn SyntaxDriverFactory>

Get the factory (if set).

Source

pub fn set_registry(&mut self, registry: Arc<dyn LanguageRegistry>)

Set the language registry used for language detection.

Source

pub fn registry(&self) -> Option<&dyn LanguageRegistry>

Get the language registry (if set).

Source

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.

Source

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.

Source

pub fn get(&self, buffer_id: BufferId) -> Option<&dyn SyntaxDriver>

Get a reference to the driver for a buffer.

Source

pub fn get_mut(&mut self, buffer_id: BufferId) -> Option<&mut dyn SyntaxDriver>

Get a mutable reference to the driver for a buffer.

Source

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.

Source

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.

Source

pub fn has_driver(&self, buffer_id: BufferId) -> bool

Check if a buffer has a syntax driver.

Source

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.

Source

pub fn len(&self) -> usize

Get the number of buffers with syntax drivers.

Source

pub fn is_empty(&self) -> bool

Check if no buffers have syntax drivers.

Source

pub fn clear(&mut self)

Clear all syntax drivers.

Trait Implementations§

Source§

impl Debug for SyntaxSessionState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SyntaxSessionState

Source§

fn default() -> SyntaxSessionState

Returns the “default value” for a type. Read more
Source§

impl SessionExtension for SyntaxSessionState

Source§

fn create() -> Self

Create default state for a new session. Read more
Source§

fn as_text_input_sink(&mut self) -> Option<&mut dyn TextInputSink>

Return self as a TextInputSink if this extension accepts text input. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> SessionExtensionDyn for T

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Get as &dyn Any for downcasting.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Get as &mut dyn Any for mutable downcasting.
Source§

fn as_text_input_sink(&mut self) -> Option<&mut dyn TextInputSink>

Get as TextInputSink if this extension accepts text input.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more