Skip to main content

Grove/Host/
mod.rs

1//! Host Module
2//!
3//! Provides the core extension hosting functionality for Grove.
4//! Manages extension lifecycle, activation, and API bridging.
5//!
6//! # Architecture
7//!
8//! ```text
9//! +++++++++++++++++++++++++++++++++++++++++++
10//! +         Extension Host                 +
11//! +++++++++++++++++++++++++++++++++++++++++++
12//! +  ExtensionHost  →  Main host controller+
13//! +  ExtensionMgr   →  Extension discovery  +
14//! +  Activation     →  Event handling       +
15//! +  Lifecycle      →  Lifecycle management +
16//! +  APIBridge      →  VS Code API proxy    +
17//! +++++++++++++++++++++++++++++++++++++++++++
18//!           +                    +
19//!           ▼                    ▼
20//! ++++++++++++++++++++  ++++++++++++++++++++
21//! +  WASM Runtime    +  +  Transport       +
22//! +  (Executes)      +  +  (Communicates)  +
23//! ++++++++++++++++++++  ++++++++++++++++++++
24//! ```
25//!
26//! # Key Components
27//!
28//! - [`ExtensionHost`] - Main extension host controller
29//! - [`ExtensionManager`] - Extension discovery and loading
30//! - [`Activation`] - Extension activation event handling
31//! - [`Lifecycle`] - Extension lifecycle management
32//! - [`APIBridge`] - VS Code API implementation bridge
33
34pub mod Activation;
35pub mod APIBridge;
36pub mod ExtensionHost;
37pub mod ExtensionManager;
38pub mod Lifecycle;
39
40// Re-exports for convenience - use module prefix to avoid E0255 conflicts
41pub use Activation::{ActivationEngine, ActivationEvent};
42pub use Lifecycle::{LifecycleEvent, LifecycleManager};
43// Note: ExtensionHost, ExtensionManager, APIBridge must be accessed via module prefix
44
45/// Host configuration
46#[derive(Debug, Clone)]
47pub struct HostConfig {
48	/// Maximum number of concurrent extensions
49	pub max_extensions:usize,
50	/// Enable lazy activation
51	pub lazy_activation:bool,
52	/// Enable hot reloading
53	pub hot_reload:bool,
54	/// Extension discovery paths
55	pub discovery_paths:Vec<String>,
56	/// Enable API logging
57	pub api_logging:bool,
58	/// Activation timeout in milliseconds
59	pub activation_timeout_ms:u64,
60}
61
62impl Default for HostConfig {
63	fn default() -> Self {
64		Self {
65			max_extensions:100,
66			lazy_activation:true,
67			hot_reload:false,
68			discovery_paths:vec!["~/.vscode/extensions".to_string(), "~/.grove/extensions".to_string()],
69			api_logging:false,
70			activation_timeout_ms:30000,
71		}
72	}
73}
74
75impl HostConfig {
76	/// Create a new host configuration
77	pub fn new() -> Self { Self::default() }
78
79	/// Set maximum number of extensions
80	pub fn with_max_extensions(mut self, max:usize) -> Self {
81		self.max_extensions = max;
82		self
83	}
84
85	/// Enable or disable lazy activation
86	pub fn with_lazy_activation(mut self, enabled:bool) -> Self {
87		self.lazy_activation = enabled;
88		self
89	}
90
91	/// Enable or disable hot reloading
92	pub fn with_hot_reload(mut self, enabled:bool) -> Self {
93		self.hot_reload = enabled;
94		self
95	}
96
97	/// Set activation timeout
98	pub fn with_activation_timeout(mut self, timeout_ms:u64) -> Self {
99		self.activation_timeout_ms = timeout_ms;
100		self
101	}
102
103	/// Add a discovery path
104	pub fn add_discovery_path(mut self, path:String) -> Self {
105		self.discovery_paths.push(path);
106		self
107	}
108}
109
110/// Extension activation result
111#[derive(Debug, Clone)]
112pub struct ActivationResult {
113	/// Extension ID
114	pub extension_id:String,
115	/// Activation success
116	pub success:bool,
117	/// Activation time in milliseconds
118	pub time_ms:u64,
119	/// Error message if failed
120	pub error:Option<String>,
121	/// Contributed items
122	pub contributes:Vec<String>,
123}
124
125#[cfg(test)]
126mod tests {
127	use super::*;
128
129	#[test]
130	fn test_host_config_default() {
131		let config = HostConfig::default();
132		assert_eq!(config.max_extensions, 100);
133		assert_eq!(config.lazy_activation, true);
134	}
135
136	#[test]
137	fn test_host_config_builder() {
138		let config = HostConfig::default()
139			.with_max_extensions(50)
140			.with_lazy_activation(false)
141			.with_activation_timeout(60000);
142
143		assert_eq!(config.max_extensions, 50);
144		assert_eq!(config.lazy_activation, false);
145		assert_eq!(config.activation_timeout_ms, 60000);
146	}
147
148	#[test]
149	fn test_activation_result() {
150		let result = ActivationResult {
151			extension_id:"test.ext".to_string(),
152			success:true,
153			time_ms:100,
154			error:None,
155			contributes:vec!["command.test".to_string()],
156		};
157
158		assert_eq!(result.extension_id, "test.ext");
159		assert!(result.success);
160		assert_eq!(result.contributes.len(), 1);
161	}
162}