Skip to main content

Crate enya_plugin

Crate enya_plugin 

Source
Expand description

Enya Plugin System

This crate provides a neovim-style plugin system for extending editor functionality. It is designed to be decoupled from any specific editor implementation through the PluginHost trait.

§Overview

The plugin system supports three types of plugins:

  • Config plugins (.toml) - Simple plugins defined in TOML
  • Lua plugins (.lua) - Dynamic plugins using Lua scripting
  • Native plugins - Rust plugins implementing the Plugin trait

§Architecture

┌─────────────────────────────────────────────────────────┐
│                     Host Application                     │
│  (implements PluginHost trait)                          │
└─────────────────────────────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────┐
│                     PluginContext                        │
│  (provides host services to plugins)                    │
└─────────────────────────────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────┐
│                    PluginRegistry                        │
│  (manages plugin lifecycle)                             │
└─────────────────────────────────────────────────────────┘
                           │
          ┌────────────────┼────────────────┐
          ▼                ▼                ▼
    ┌──────────┐    ┌──────────┐    ┌──────────┐
    │  Config  │    │   Lua    │    │  Native  │
    │  Plugin  │    │  Plugin  │    │  Plugin  │
    └──────────┘    └──────────┘    └──────────┘

§Example: Implementing PluginHost

use enya_plugin::{
    PluginHost, PluginContext, PluginRegistry, NotificationLevel, LogLevel, Theme, BoxFuture,
};
use std::sync::Arc;

struct MyEditor {
    // ... editor state
}

impl PluginHost for MyEditor {
    fn notify(&self, level: NotificationLevel, message: &str) {
        // Show notification to user
    }

    fn request_repaint(&self) {
        // Request UI refresh
    }

    fn log(&self, level: LogLevel, message: &str) {
        // Log message
    }

    fn version(&self) -> &'static str {
        "1.0.0"
    }

    fn is_wasm(&self) -> bool {
        false
    }

    fn theme(&self) -> Theme {
        Theme::Dark
    }

    fn spawn(&self, future: BoxFuture<()>) {
        // Spawn async task
    }
}

fn setup_plugins(editor: Arc<MyEditor>) {
    let ctx = PluginContext::new(editor);
    let mut registry = PluginRegistry::new();
    registry.init(ctx);

    // Register and activate plugins...
}

Re-exports§

pub use lua::EXAMPLE_LUA_PLUGIN;
pub use lua::LuaPlugin;

Modules§

lua
Lua plugin support using mlua.

Structs§

ChartDataPoint
A single data point in a chart series.
ChartSeries
A single series in a chart (line).
CommandConfig
Configuration for a custom command provided by a plugin.
ConfigCommand
A command defined in a config plugin.
ConfigKeybinding
A keybinding defined in a config plugin.
ConfigPlugin
A plugin loaded from a config file.
CustomChartConfig
Configuration for a custom chart pane type.
CustomChartData
Data to display in a custom chart pane.
CustomTableConfig
Configuration for a custom table pane type.
CustomTableData
Data returned by a custom table pane’s fetch function.
CustomTableRow
A single row of data for a custom table.
FocusedPaneInfo
Information about the currently focused pane. Used for sharing context to external services like Slack/Discord.
GaugePaneConfig
Configuration for a custom gauge pane type.
GaugePaneData
Data to display in a gauge pane.
HeadlessPluginHost
A headless implementation of PluginHost for CLI use.
HttpError
HTTP request error.
HttpResponse
HTTP response returned from http_get/http_post.
KeyCombo
Represents a key combination.
KeyEvent
Represents a keyboard event.
KeybindingConfig
Configuration for a keyboard shortcut provided by a plugin.
PaneConfig
Configuration for a custom pane type provided by a plugin.
PluginCapabilities
Capabilities that a plugin can provide.
PluginContext
Context provided to plugins for interacting with the host.
PluginId
Unique identifier for a registered plugin.
PluginInfo
Information about a registered plugin.
PluginLoader
Plugin loader that discovers and loads plugins from the filesystem.
PluginManifest
Metadata for a loadable plugin.
PluginMeta
Plugin metadata from manifest.
PluginRegistry
Central registry for managing plugins.
StatPaneConfig
Configuration for a custom stat pane type.
StatPaneData
Data to display in a stat pane.
TableColumnConfig
Column configuration for a custom table pane.
ThemeColors
Color palette for a custom theme.
ThemeCustomization
Theme customization provided by a plugin.
ThemeDefinition
A custom theme definition from a plugin.
ThresholdConfig
Threshold configuration for stat/gauge visualizations.

Enums§

CommandHookResult
Result of a command hook execution.
KeyboardHookResult
Result of a keyboard hook execution.
LogLevel
Log level for plugin logging.
NotificationLevel
Notification level for user-facing messages.
PluginError
Errors that can occur during plugin operations.
PluginState
Runtime state of a plugin.
Theme
Application theme.
ThemeBase
Base theme to inherit missing colors from.

Constants§

EXAMPLE_PLUGIN
Example plugin template.

Traits§

CommandHook
Hook for intercepting command execution.
KeyboardHook
Hook for intercepting keyboard events.
LifecycleHook
Hook for intercepting lifecycle events.
PaneHook
Hook for pane-related events.
Plugin
The core plugin trait that all plugins must implement.
PluginHost
Trait for the host application to implement.
ThemeHook
Hook for theme-related events.

Type Aliases§

BoxFuture
A boxed future for async operations.
PluginContextRef
Reference-counted plugin context.
PluginHostRef
Reference-counted plugin host.
PluginResult
Result type for plugin operations.