Mountain/ApplicationState/State/ExtensionState/State.rs
1//! # State Module (ExtensionState)
2//!
3//! ## RESPONSIBILITIES
4//! Combines all extension-related state components into a single state struct.
5//!
6//! ## ARCHITECTURAL ROLE
7//! State is the main composite struct that combines all ExtensionState
8//! components:
9//! - ExtensionRegistry: Command registry and provider handle management
10//! - ProviderRegistration: Language providers registration
11//! - ScannedExtensions: Discovered extensions metadata
12//!
13//! ## KEY COMPONENTS
14//! - State: Main struct combining all extension state
15//! - Default: Initialization implementation
16//!
17//! ## ERROR HANDLING
18//! - Thread-safe access via `Arc<Mutex<...>>`
19//! - Proper lock error handling with `MapLockError` helpers
20//!
21//! ## LOGGING
22//! State changes are logged at appropriate levels (debug, info, warn, error).
23//!
24//! ## PERFORMANCE CONSIDERATIONS
25//! - Lock mutexes briefly and release immediately
26//! - Avoid nested locks to prevent deadlocks
27//! - Use Arc for shared ownership across threads
28//!
29//! ## TODO
30//! - [ ] Add extension state validation invariants
31//! - [ ] Implement extension lifecycle events
32//! - [ ] Add extension state metrics collection
33
34use log::debug;
35
36use super::{ExtensionRegistry::Registry, ProviderRegistration::Registration, ScannedExtensions::Extensions};
37
38/// Extension state combining all extension-related components.
39#[derive(Clone)]
40pub struct State {
41 /// Extension registry containing command registry and provider state.
42 pub Registry:Registry,
43
44 /// Language provider registration state.
45 pub ProviderRegistration:Registration,
46
47 /// Scanned extensions containing discovered extensions.
48 pub ScannedExtensions:Extensions,
49}
50
51impl Default for State {
52 fn default() -> Self {
53 debug!("[ExtensionState::State] Initializing default extension state...");
54
55 Self {
56 Registry:Default::default(),
57 ProviderRegistration:Default::default(),
58 ScannedExtensions:Default::default(),
59 }
60 }
61}
62
63impl State {
64 /// Gets the next available unique identifier for a provider registration.
65 pub fn GetNextProviderHandle(&self) -> u32 { self.Registry.GetNextProviderHandle() }
66}