Skip to main content

OptionRegistry

Struct OptionRegistry 

Source
pub struct OptionRegistry { /* private fields */ }
Expand description

Thread-safe registry for all editor options.

This is the MECHANISM for option storage. POLICY (which options to register) is in modules.

§Storage Model

OptionRegistry
├── specs: HashMap<String, OptionSpec>              # Option definitions
├── aliases: HashMap<String, String>                # Short -> Full name
├── global_values: HashMap<String, OptionValue>     # Global overrides
├── buffer_values: HashMap<(BufferId, String), OptionValue>   # Per-buffer
└── window_values: HashMap<(WindowId, String), OptionValue>   # Per-window

§Thread Safety

All operations use RwLock for thread-safe access. Multiple readers allowed, single writer for mutations.

Implementations§

Source§

impl OptionRegistry

Source

pub fn new() -> Self

Create a new empty option registry.

Source

pub fn register(&self, spec: OptionSpec) -> Result<(), OptionError>

Register an option specification.

§Errors

Returns error if:

  • Option with same name already exists
  • Short alias conflicts with existing name or alias
Source

pub fn unregister_by_module(&self, module_id: &ModuleId)

Unregister all options owned by a module.

Removes all option specs with matching owner, their aliases, and any stored values (global, buffer-local, window-local).

Source

pub fn list_by_module(&self, module_id: &ModuleId) -> Vec<OptionSpec>

List all options owned by a module.

Source

pub fn resolve_name(&self, name: &str) -> Option<String>

Resolve a name (which may be an alias) to the full option name.

Source

pub fn get_spec(&self, name: &str) -> Option<OptionSpec>

Get an option specification by name (supports aliases).

Source

pub fn contains(&self, name: &str) -> bool

Check if an option exists.

Source

pub fn get(&self, name: &str, scope: OptionScopeId) -> Option<OptionValue>

Get the effective value of an option for a given scope.

Resolution order (most specific wins):

  1. Window-local value (if scope is Window)
  2. Buffer-local value (if scope is Buffer or has buffer context)
  3. Global value (if set)
  4. Default value from spec
Source

pub fn get_global(&self, name: &str) -> Option<OptionValue>

Get global value (ignoring scope context).

Source

pub fn get_for_buffer( &self, name: &str, buffer_id: BufferId, ) -> Option<OptionValue>

Get buffer-local value.

Source

pub fn get_for_window( &self, name: &str, window_id: WindowId, ) -> Option<OptionValue>

Get window-local value.

Source

pub fn set( &self, name: &str, value: OptionValue, scope: OptionScopeId, ) -> Result<SetResult, OptionError>

Set an option value at a specific scope.

§Errors

Returns error if:

  • Option not found
  • Value fails validation
  • Scope mismatch
Source

pub fn set_global( &self, name: &str, value: OptionValue, ) -> Result<SetResult, OptionError>

Set global value.

§Errors

Returns error if option not found or validation fails.

Source

pub fn set_for_buffer( &self, name: &str, value: OptionValue, buffer_id: BufferId, ) -> Result<SetResult, OptionError>

Set buffer-local value.

§Errors

Returns error if option not found, validation fails, or scope mismatch.

Source

pub fn set_for_window( &self, name: &str, value: OptionValue, window_id: WindowId, ) -> Result<SetResult, OptionError>

Set window-local value.

§Errors

Returns error if option not found, validation fails, or scope mismatch.

Source

pub fn reset( &self, name: &str, scope: OptionScopeId, ) -> Result<Option<OptionValue>, OptionError>

Reset an option to its default value at a specific scope.

§Errors

Returns error if option not found.

Source

pub fn clear_buffer(&self, buffer_id: BufferId)

Reset all buffer-local values for a buffer (called when buffer closes).

Source

pub fn clear_window(&self, window_id: WindowId)

Reset all window-local values for a window (called when window closes).

Source

pub fn toggle( &self, name: &str, scope: OptionScopeId, ) -> Result<bool, OptionError>

Toggle a boolean option.

§Errors

Returns error if option not found or is not boolean.

Source

pub fn list_all(&self) -> Vec<String>

List all registered option names.

Source

pub fn list_matching(&self, prefix: &str) -> Vec<OptionSpec>

List options matching a prefix (for tab completion).

Source

pub fn list_by_scope(&self, scope: OptionScope) -> Vec<OptionSpec>

List options by scope.

Source

pub fn len(&self) -> usize

Get the number of registered options.

Source

pub fn is_empty(&self) -> bool

Check if the registry is empty.

Trait Implementations§

Source§

impl Debug for OptionRegistry

Source§

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

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

impl Default for OptionRegistry

Source§

fn default() -> OptionRegistry

Returns the “default value” for a type. 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, 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, 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.