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
impl OptionRegistry
Sourcepub fn register(&self, spec: OptionSpec) -> Result<(), OptionError>
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
Sourcepub fn unregister_by_module(&self, module_id: &ModuleId)
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).
Sourcepub fn list_by_module(&self, module_id: &ModuleId) -> Vec<OptionSpec>
pub fn list_by_module(&self, module_id: &ModuleId) -> Vec<OptionSpec>
List all options owned by a module.
Sourcepub fn resolve_name(&self, name: &str) -> Option<String>
pub fn resolve_name(&self, name: &str) -> Option<String>
Resolve a name (which may be an alias) to the full option name.
Sourcepub fn get_spec(&self, name: &str) -> Option<OptionSpec>
pub fn get_spec(&self, name: &str) -> Option<OptionSpec>
Get an option specification by name (supports aliases).
Sourcepub fn get(&self, name: &str, scope: OptionScopeId) -> Option<OptionValue>
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):
- Window-local value (if
scopeisWindow) - Buffer-local value (if
scopeisBufferor has buffer context) - Global value (if set)
- Default value from spec
Sourcepub fn get_global(&self, name: &str) -> Option<OptionValue>
pub fn get_global(&self, name: &str) -> Option<OptionValue>
Get global value (ignoring scope context).
Sourcepub fn get_for_buffer(
&self,
name: &str,
buffer_id: BufferId,
) -> Option<OptionValue>
pub fn get_for_buffer( &self, name: &str, buffer_id: BufferId, ) -> Option<OptionValue>
Get buffer-local value.
Sourcepub fn get_for_window(
&self,
name: &str,
window_id: WindowId,
) -> Option<OptionValue>
pub fn get_for_window( &self, name: &str, window_id: WindowId, ) -> Option<OptionValue>
Get window-local value.
Sourcepub fn set(
&self,
name: &str,
value: OptionValue,
scope: OptionScopeId,
) -> Result<SetResult, OptionError>
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
Sourcepub fn set_global(
&self,
name: &str,
value: OptionValue,
) -> Result<SetResult, OptionError>
pub fn set_global( &self, name: &str, value: OptionValue, ) -> Result<SetResult, OptionError>
Sourcepub fn set_for_buffer(
&self,
name: &str,
value: OptionValue,
buffer_id: BufferId,
) -> Result<SetResult, OptionError>
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.
Sourcepub fn set_for_window(
&self,
name: &str,
value: OptionValue,
window_id: WindowId,
) -> Result<SetResult, OptionError>
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.
Sourcepub fn reset(
&self,
name: &str,
scope: OptionScopeId,
) -> Result<Option<OptionValue>, OptionError>
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.
Sourcepub fn clear_buffer(&self, buffer_id: BufferId)
pub fn clear_buffer(&self, buffer_id: BufferId)
Reset all buffer-local values for a buffer (called when buffer closes).
Sourcepub fn clear_window(&self, window_id: WindowId)
pub fn clear_window(&self, window_id: WindowId)
Reset all window-local values for a window (called when window closes).
Sourcepub fn toggle(
&self,
name: &str,
scope: OptionScopeId,
) -> Result<bool, OptionError>
pub fn toggle( &self, name: &str, scope: OptionScopeId, ) -> Result<bool, OptionError>
Sourcepub fn list_matching(&self, prefix: &str) -> Vec<OptionSpec>
pub fn list_matching(&self, prefix: &str) -> Vec<OptionSpec>
List options matching a prefix (for tab completion).
Sourcepub fn list_by_scope(&self, scope: OptionScope) -> Vec<OptionSpec>
pub fn list_by_scope(&self, scope: OptionScope) -> Vec<OptionSpec>
List options by scope.