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 std::sync::Arc;
35
36use tokio::sync::Notify;
37
38use super::{ExtensionRegistry, ProviderRegistration, ScannedExtensions};
39use crate::dev_log;
40
41/// Extension state combining all extension-related components.
42#[derive(Clone)]
43pub struct State {
44 /// Extension registry containing command registry and provider state.
45 pub Registry:ExtensionRegistry::ExtensionRegistry::Registry,
46
47 /// Language provider registration state.
48 pub ProviderRegistration:ProviderRegistration::ProviderRegistration::Registration,
49
50 /// Scanned extensions containing discovered extensions.
51 pub ScannedExtensions:ScannedExtensions::ScannedExtensions::ScannedExtensionCollection,
52
53 /// Fires once when the initial extension scan has written at least one
54 /// extension into `ScannedExtensions`. Callers that need extensions
55 /// on the first request (e.g. `extensions:getInstalled` during boot)
56 /// can `await` this instead of polling.
57 pub ScanReady:Arc<Notify>,
58}
59
60impl Default for State {
61 fn default() -> Self {
62 dev_log!("extensions", "[ExtensionState::State] Initializing default extension state...");
63
64 Self {
65 Registry:ExtensionRegistry::ExtensionRegistry::Registry::default(),
66
67 ProviderRegistration:ProviderRegistration::ProviderRegistration::Registration::default(),
68
69 ScannedExtensions:ScannedExtensions::ScannedExtensions::ScannedExtensionCollection::default(),
70
71 ScanReady:Arc::new(Notify::new()),
72 }
73 }
74}
75
76impl State {
77 /// Gets the next available unique identifier for a provider registration.
78 pub fn GetNextProviderHandle(&self) -> u32 { self.Registry.GetNextProviderHandle() }
79}