Skip to main content

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 super::{
39	Debug::DebugState::DebugState,
40	Decorations::DecorationsState::DecorationsState,
41	Diagnostics::DiagnosticsState::DiagnosticsState,
42	Documents::DocumentState::DocumentState,
43	Keybindings::KeybindingState::KeybindingState,
44	LifecyclePhase::LifecyclePhaseState::LifecyclePhaseState,
45	Markers::MarkerState::MarkerState,
46	NavigationHistory::NavigationHistoryState::NavigationHistoryState,
47	OutputChannels::OutputChannelState::OutputChannelState,
48	Terminals::TerminalState::TerminalState,
49	TreeViews::TreeViewState::TreeViewState,
50	Webviews::WebviewState::WebviewState,
51	WorkingCopy::WorkingCopyState::WorkingCopyState,
52};
53use crate::dev_log;
54
55/// Feature state combining all feature-related components.
56#[derive(Clone)]
57pub struct State {
58	/// Debug provider state.
59	pub Debug:DebugState,
60
61	/// File/folder decoration state (git badges, error squiggles, custom
62	/// badges).
63	pub Decorations:DecorationsState,
64
65	/// Diagnostic errors state.
66	pub Diagnostics:DiagnosticsState,
67
68	/// Open documents state.
69	pub Documents:DocumentState,
70
71	/// Dynamic keybinding registry.
72	pub Keybindings:KeybindingState,
73
74	/// Application lifecycle phase state.
75	pub Lifecycle:LifecyclePhaseState,
76
77	/// Editor navigation history (back/forward stack).
78	pub NavigationHistory:NavigationHistoryState,
79
80	/// Marker-related state.
81	pub Markers:MarkerState,
82
83	/// Output channel state.
84	pub OutputChannels:OutputChannelState,
85
86	/// Terminal instances state.
87	pub Terminals:TerminalState,
88
89	/// Tree view providers state.
90	pub TreeViews:TreeViewState,
91
92	/// Webview panels state.
93	pub Webviews:WebviewState,
94
95	/// Working-copy (dirty) state - drives the dirty dot in editor tabs.
96	pub WorkingCopy:WorkingCopyState,
97}
98
99impl Default for State {
100	fn default() -> Self {
101		dev_log!("lifecycle", "[FeatureState::State] Initializing default feature state...");
102
103		Self {
104			Debug:Default::default(),
105			Decorations:Default::default(),
106			Diagnostics:Default::default(),
107			Documents:Default::default(),
108			Keybindings:Default::default(),
109			Lifecycle:Default::default(),
110			Markers:Default::default(),
111			NavigationHistory:Default::default(),
112			OutputChannels:Default::default(),
113			Terminals:Default::default(),
114			TreeViews:Default::default(),
115			Webviews:Default::default(),
116			WorkingCopy:Default::default(),
117		}
118	}
119}
120
121impl State {
122	/// Gets the next available unique identifier for a terminal instance.
123	pub fn GetNextTerminalIdentifier(&self) -> u64 { self.Terminals.GetNextTerminalIdentifier() }
124
125	/// Gets the next available unique identifier for an SCM provider.
126	pub fn GetNextSourceControlManagementProviderHandle(&self) -> u32 {
127		self.Markers.GetNextSourceControlManagementProviderHandle()
128	}
129}