enya_plugin/lib.rs
1//! Enya Plugin System
2//!
3//! This crate provides a neovim-style plugin system for extending editor functionality.
4//! It is designed to be decoupled from any specific editor implementation through
5//! the `PluginHost` trait.
6//!
7//! # Overview
8//!
9//! The plugin system supports three types of plugins:
10//!
11//! - **Config plugins** (`.toml`) - Simple plugins defined in TOML
12//! - **Lua plugins** (`.lua`) - Dynamic plugins using Lua scripting
13//! - **Native plugins** - Rust plugins implementing the `Plugin` trait
14//!
15//! # Architecture
16//!
17//! ```text
18//! ┌─────────────────────────────────────────────────────────┐
19//! │ Host Application │
20//! │ (implements PluginHost trait) │
21//! └─────────────────────────────────────────────────────────┘
22//! │
23//! ▼
24//! ┌─────────────────────────────────────────────────────────┐
25//! │ PluginContext │
26//! │ (provides host services to plugins) │
27//! └─────────────────────────────────────────────────────────┘
28//! │
29//! ▼
30//! ┌─────────────────────────────────────────────────────────┐
31//! │ PluginRegistry │
32//! │ (manages plugin lifecycle) │
33//! └─────────────────────────────────────────────────────────┘
34//! │
35//! ┌────────────────┼────────────────┐
36//! ▼ ▼ ▼
37//! ┌──────────┐ ┌──────────┐ ┌──────────┐
38//! │ Config │ │ Lua │ │ Native │
39//! │ Plugin │ │ Plugin │ │ Plugin │
40//! └──────────┘ └──────────┘ └──────────┘
41//! ```
42//!
43//! # Example: Implementing PluginHost
44//!
45//! ```ignore
46//! use enya_plugin::{
47//! PluginHost, PluginContext, PluginRegistry, NotificationLevel, LogLevel, Theme, BoxFuture,
48//! };
49//! use std::sync::Arc;
50//!
51//! struct MyEditor {
52//! // ... editor state
53//! }
54//!
55//! impl PluginHost for MyEditor {
56//! fn notify(&self, level: NotificationLevel, message: &str) {
57//! // Show notification to user
58//! }
59//!
60//! fn request_repaint(&self) {
61//! // Request UI refresh
62//! }
63//!
64//! fn log(&self, level: LogLevel, message: &str) {
65//! // Log message
66//! }
67//!
68//! fn version(&self) -> &'static str {
69//! "1.0.0"
70//! }
71//!
72//! fn is_wasm(&self) -> bool {
73//! false
74//! }
75//!
76//! fn theme(&self) -> Theme {
77//! Theme::Dark
78//! }
79//!
80//! fn spawn(&self, future: BoxFuture<()>) {
81//! // Spawn async task
82//! }
83//! }
84//!
85//! fn setup_plugins(editor: Arc<MyEditor>) {
86//! let ctx = PluginContext::new(editor);
87//! let mut registry = PluginRegistry::new();
88//! registry.init(ctx);
89//!
90//! // Register and activate plugins...
91//! }
92//! ```
93
94mod hooks;
95mod registry;
96mod theme;
97mod traits;
98mod types;
99
100// Loader, Lua, and headless support only available on native platforms
101#[cfg(not(target_arch = "wasm32"))]
102mod headless;
103#[cfg(not(target_arch = "wasm32"))]
104mod loader;
105#[cfg(not(target_arch = "wasm32"))]
106pub mod lua;
107
108// Re-export core types
109pub use types::{
110 BoxFuture, ChartDataPoint, ChartSeries, CustomChartConfig, CustomChartData, CustomTableConfig,
111 CustomTableData, CustomTableRow, FocusedPaneInfo, GaugePaneConfig, GaugePaneData, HttpError,
112 HttpResponse, LogLevel, NotificationLevel, PluginContext, PluginContextRef, PluginHost,
113 PluginHostRef, StatPaneConfig, StatPaneData, TableColumnConfig, Theme, ThresholdConfig,
114};
115
116// Re-export theme types
117pub use theme::{ThemeBase, ThemeColors, ThemeDefinition};
118
119// Re-export plugin traits and types
120pub use traits::{
121 CommandConfig, KeybindingConfig, PaneConfig, Plugin, PluginCapabilities, PluginError,
122 PluginResult,
123};
124
125// Re-export hooks
126pub use hooks::{
127 CommandHook, CommandHookResult, KeyCombo, KeyEvent, KeyboardHook, KeyboardHookResult,
128 LifecycleHook, PaneHook, ThemeCustomization, ThemeHook,
129};
130
131// Re-export registry
132pub use registry::{PluginId, PluginInfo, PluginRegistry, PluginState};
133
134// Re-export headless host (native only)
135#[cfg(not(target_arch = "wasm32"))]
136pub use headless::HeadlessPluginHost;
137
138// Re-export loader (native only)
139#[cfg(not(target_arch = "wasm32"))]
140pub use loader::{
141 ConfigCommand, ConfigKeybinding, ConfigPlugin, EXAMPLE_PLUGIN, PluginLoader, PluginManifest,
142 PluginMeta,
143};
144
145// Re-export Lua plugin support (native only)
146#[cfg(not(target_arch = "wasm32"))]
147pub use lua::{EXAMPLE_LUA_PLUGIN, LuaPlugin};