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/// Host configuration
41#[derive(Debug, Clone)]
42pub struct HostConfig {
43	/// Maximum number of concurrent extensions
44	pub max_extensions:usize,
45	/// Enable lazy activation
46	pub lazy_activation:bool,
47	/// Enable hot reloading
48	pub hot_reload:bool,
49	/// Extension discovery paths
50	pub discovery_paths:Vec<String>,
51	/// Enable API logging
52	pub api_logging:bool,
53	/// Activation timeout in milliseconds
54	pub activation_timeout_ms:u64,
55}
56
57impl Default for HostConfig {
58	fn default() -> Self {
59		Self {
60			max_extensions:100,
61			lazy_activation:true,
62			hot_reload:false,
63			discovery_paths:vec!["~/.vscode/extensions".to_string(), "~/.grove/extensions".to_string()],
64			api_logging:false,
65			activation_timeout_ms:30000,
66		}
67	}
68}
69
70impl HostConfig {
71	/// Create a new host configuration
72	pub fn new() -> Self { Self::default() }
73
74	/// Set maximum number of extensions
75	pub fn with_max_extensions(mut self, max:usize) -> Self {
76		self.max_extensions = max;
77		self
78	}
79
80	/// Enable or disable lazy activation
81	pub fn with_lazy_activation(mut self, enabled:bool) -> Self {
82		self.lazy_activation = enabled;
83		self
84	}
85
86	/// Enable or disable hot reloading
87	pub fn with_hot_reload(mut self, enabled:bool) -> Self {
88		self.hot_reload = enabled;
89		self
90	}
91
92	/// Set activation timeout
93	pub fn with_activation_timeout(mut self, timeout_ms:u64) -> Self {
94		self.activation_timeout_ms = timeout_ms;
95		self
96	}
97
98	/// Add a discovery path
99	pub fn add_discovery_path(mut self, path:String) -> Self {
100		self.discovery_paths.push(path);
101		self
102	}
103}
104
105/// Extension activation result
106#[derive(Debug, Clone)]
107pub struct ActivationResult {
108	/// Extension ID
109	pub extension_id:String,
110	/// Activation success
111	pub success:bool,
112	/// Activation time in milliseconds
113	pub time_ms:u64,
114	/// Error message if failed
115	pub error:Option<String>,
116	/// Contributed items
117	pub contributes:Vec<String>,
118}
119
120#[cfg(test)]
121mod tests {
122	use super::*;
123
124	#[test]
125	fn test_host_config_default() {
126		let config = HostConfig::default();
127		assert_eq!(config.max_extensions, 100);
128		assert_eq!(config.lazy_activation, true);
129	}
130
131	#[test]
132	fn test_host_config_builder() {
133		let config = HostConfig::default()
134			.with_max_extensions(50)
135			.with_lazy_activation(false)
136			.with_activation_timeout(60000);
137
138		assert_eq!(config.max_extensions, 50);
139		assert_eq!(config.lazy_activation, false);
140		assert_eq!(config.activation_timeout_ms, 60000);
141	}
142
143	#[test]
144	fn test_activation_result() {
145		let result = ActivationResult {
146			extension_id:"test.ext".to_string(),
147			success:true,
148			time_ms:100,
149			error:None,
150			contributes:vec!["command.test".to_string()],
151		};
152
153		assert_eq!(result.extension_id, "test.ext");
154		assert!(result.success);
155		assert_eq!(result.contributes.len(), 1);
156	}
157}