Skip to main content

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 super::{ExtensionRegistry, ProviderRegistration, ScannedExtensions};
35use crate::dev_log;
36
37/// Extension state combining all extension-related components.
38#[derive(Clone)]
39pub struct State {
40	/// Extension registry containing command registry and provider state.
41	pub Registry:ExtensionRegistry::Registry,
42
43	/// Language provider registration state.
44	pub ProviderRegistration:ProviderRegistration::Registration,
45
46	/// Scanned extensions containing discovered extensions.
47	pub ScannedExtensions:ScannedExtensions::ScannedExtensionCollection,
48}
49
50impl Default for State {
51	fn default() -> Self {
52		dev_log!("extensions", "[ExtensionState::State] Initializing default extension state...");
53
54		Self {
55			Registry:ExtensionRegistry::Registry::default(),
56			ProviderRegistration:ProviderRegistration::Registration::default(),
57			ScannedExtensions:ScannedExtensions::ScannedExtensionCollection::default(),
58		}
59	}
60}
61
62impl State {
63	/// Gets the next available unique identifier for a provider registration.
64	pub fn GetNextProviderHandle(&self) -> u32 { self.Registry.GetNextProviderHandle() }
65}