Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin {
    // Required methods
    fn metadata(&self) -> &PluginMetadata;
    fn init(&mut self, context: &PluginContext) -> PluginResult<()>;
    fn execute_hook(
        &mut self,
        hook: &PluginHook,
        data: &Value,
    ) -> PluginResult<Value>;

    // Provided methods
    fn supports_hook(&self, hook: &PluginHook) -> bool { ... }
    fn on_event(&mut self, event: &Value) -> PluginResult<Option<Value>> { ... }
    fn highlight(
        &mut self,
        request: &HighlightRequest,
    ) -> PluginResult<Option<HighlightResponse>> { ... }
}
Expand description

Core plugin trait

Note: Plugins are single-threaded by design for simplicity and safety. The ProGit TUI loads and executes plugins on the main thread only.

Required Methods§

Source

fn metadata(&self) -> &PluginMetadata

Get plugin metadata

Source

fn init(&mut self, context: &PluginContext) -> PluginResult<()>

Initialize the plugin with context

Source

fn execute_hook( &mut self, hook: &PluginHook, data: &Value, ) -> PluginResult<Value>

Execute a hook

Provided Methods§

Source

fn supports_hook(&self, hook: &PluginHook) -> bool

Check if plugin supports a specific hook

Source

fn on_event(&mut self, event: &Value) -> PluginResult<Option<Value>>

Handle a plugin event (new event system)

This method supports the event-based plugin API where plugins receive structured events and return optional responses. This is newer than the hook-based system and is used for query-style interactions like CI/CD status queries.

Returns Ok(None) if the plugin doesn’t handle this event type. Returns Ok(Some(response)) with the response data.

Source

fn highlight( &mut self, request: &HighlightRequest, ) -> PluginResult<Option<HighlightResponse>>

Render-time hook: provide syntax-highlighted spans for a chunk of text.

Called from the host’s frame-render path (e.g. the diff renderer). The host caches results aggressively, but on a cache miss the plugin must respond fast — keep the implementation linear in content length and avoid I/O.

Returning Ok(None) means “not a highlight provider for this language” — the host tries the next plugin, or falls through to plain text. Plugins that are highlight providers but cannot handle a specific language should also return None, not an error.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§