Mountain/ApplicationState/State/FeatureState/State.rs
1//! # State Module (FeatureState)
2//!
3//! ## RESPONSIBILITIES
4//! Combines all feature-related state components into a single state struct.
5//!
6//! ## ARCHITECTURAL ROLE
7//! State is the main composite struct that combines all FeatureState
8//! components:
9//! - Diagnostics: Diagnostic errors state
10//! - Documents: Open documents state
11//! - Terminals: Terminal instances state
12//! - Webviews: Webview panels state
13//! - TreeViews: Tree view providers state
14//! - OutputChannels: Output channel state
15//! - Markers: Marker-related state
16//!
17//! ## KEY COMPONENTS
18//! - State: Main struct combining all feature state
19//! - Default: Initialization implementation
20//!
21//! ## ERROR HANDLING
22//! - Thread-safe access via `Arc<Mutex<...>>`
23//! - Proper lock error handling with `MapLockError` helpers
24//!
25//! ## LOGGING
26//! State changes are logged at appropriate levels (debug, info, warn, error).
27//!
28//! ## PERFORMANCE CONSIDERATIONS
29//! - Lock mutexes briefly and release immediately
30//! - Avoid nested locks to prevent deadlocks
31//! - Use Arc for shared ownership across threads
32//!
33//! ## TODO
34//! - [ ] Add feature state validation invariants
35//! - [ ] Implement feature lifecycle events
36//! - [ ] Add feature state metrics collection
37
38use log::debug;
39
40use super::{
41 Diagnostics::DiagnosticsState::DiagnosticsState,
42 Documents::DocumentState::DocumentState,
43 Markers::MarkerState::MarkerState,
44 OutputChannels::OutputChannelState::OutputChannelState,
45 Terminals::TerminalState::TerminalState,
46 TreeViews::TreeViewState::TreeViewState,
47 Webviews::WebviewState::WebviewState,
48};
49
50/// Feature state combining all feature-related components.
51#[derive(Clone)]
52pub struct State {
53 /// Diagnostic errors state.
54 pub Diagnostics:DiagnosticsState,
55
56 /// Open documents state.
57 pub Documents:DocumentState,
58
59 /// Terminal instances state.
60 pub Terminals:TerminalState,
61
62 /// Webview panels state.
63 pub Webviews:WebviewState,
64
65 /// Tree view providers state.
66 pub TreeViews:TreeViewState,
67
68 /// Output channel state.
69 pub OutputChannels:OutputChannelState,
70
71 /// Marker-related state.
72 pub Markers:MarkerState,
73}
74
75impl Default for State {
76 fn default() -> Self {
77 debug!("[FeatureState::State] Initializing default feature state...");
78
79 Self {
80 Diagnostics:Default::default(),
81 Documents:Default::default(),
82 Terminals:Default::default(),
83 Webviews:Default::default(),
84 TreeViews:Default::default(),
85 OutputChannels:Default::default(),
86 Markers:Default::default(),
87 }
88 }
89}
90
91impl State {
92 /// Gets the next available unique identifier for a terminal instance.
93 pub fn GetNextTerminalIdentifier(&self) -> u64 { self.Terminals.GetNextTerminalIdentifier() }
94
95 /// Gets the next available unique identifier for an SCM provider.
96 pub fn GetNextSourceControlManagementProviderHandle(&self) -> u32 {
97 self.Markers.GetNextSourceControlManagementProviderHandle()
98 }
99}