Expand description
Plugin API: Safe interface for plugins to interact with the editor
This module provides a safe, controlled API for plugins (Lua, WASM, etc.) to interact with the editor without direct access to internal state.
§Type Safety Architecture
Rust structs in this module serve as the single source of truth for the TypeScript plugin API. The type safety system works as follows:
Rust struct Generated TypeScript
─────────── ────────────────────
#[derive(TS, Deserialize)] type ActionPopupOptions = {
#[serde(deny_unknown_fields)] id: string;
struct ActionPopupOptions { title: string;
id: String, message: string;
title: String, actions: TsActionPopupAction[];
... };
}§Key Patterns
#[derive(TS)]- Generates TypeScript type definitions via ts-rs#[serde(deny_unknown_fields)]- Rejects typos/unknown fields at runtimeimpl FromJs- Bridges rquickjs values to typed Rust structs
§Validation Layers
| Layer | What it catches |
|---|---|
| TypeScript compile | Wrong field names, missing required fields |
| Rust runtime (serde) | Typos like popup_id instead of id |
| Rust compile | Type mismatches in method signatures |
§Limitations & Tradeoffs
- Manual parsing for complex types: Some methods (e.g.,
submitViewTransform) still use manual object parsing due to enum serialization complexity - Two-step deserialization: Complex nested structs may need
rquickjs::Value → serde_json::Value → typed structdue to rquickjs_serde limits - Duplicate attributes: Both
#[serde(...)]and#[ts(...)]needed since they control different things (runtime serialization vs compile-time codegen)
Structs§
- Action
Popup Action - Action button for action popups
- Action
Popup Options - Options for showActionPopup
- Action
Spec - Specification for an action to execute, with optional repeat count
- Background
Process Result - Result from spawning a background process
- Buffer
Info - Information about a buffer
- Buffer
Saved Diff - Diff between current buffer content and last saved snapshot
- Command
Registry - Minimal command registry for PluginApi. This is a stub that provides basic command storage for plugin use. The editor’s full CommandRegistry lives in fresh-editor.
- Composite
Hunk - Diff hunk for composite buffer alignment
- Composite
Layout Config - Layout configuration for composite buffers
- Composite
Pane Style - Style configuration for a composite pane
- Composite
Source Config - Source pane configuration for composite buffers
- Create
Composite Buffer Options - Options for creating a composite buffer (used by plugin API)
- Create
Terminal Options - Options for createTerminal
- Create
Virtual Buffer InExisting Split Options - Options for createVirtualBufferInExistingSplit
- Create
Virtual Buffer InSplit Options - Options for createVirtualBufferInSplit
- Create
Virtual Buffer Options - Options for createVirtualBuffer
- Cursor
Info - Information about a cursor in the editor
- DirEntry
- Directory entry returned by readDir
- Editor
State Snapshot - Snapshot of editor state for plugin queries This is updated by the editor on each loop iteration
- Formatter
Pack Config - Formatter configuration for language packs
- Grammar
Info Snapshot - Grammar info exposed to plugins, mirroring the editor’s grammar provenance tracking.
- Grep
Match - A single match from project-wide grep
- JsCallback
Id - A callback ID for JavaScript promises in the plugin runtime.
- JsDiagnostic
- Diagnostic from LSP
- JsPosition
- Position in a document (line and character)
- JsRange
- Range in a document (start and end positions)
- JsText
Property Entry - Entry for virtual buffer content with optional text properties (JS API version)
- Language
Pack Config - Language configuration for language packs
- Layout
Hints - Layout hints supplied by plugins (e.g., Compose mode)
- LspServer
Pack Config - LSP server configuration for language packs
- Overlay
Options - Options for adding an overlay with theme support.
- Plugin
Api - Plugin API context - provides safe access to editor functionality
- Process
Limits Pack Config - Process resource limits for LSP servers
- Replace
Result - Result from replacing matches in a buffer
- Review
Hunk - A high-level hunk directive for the Review Diff tool
- Spawn
Result - Result from spawning a process with spawnProcess
- Terminal
Result - Result of creating a terminal
- Text
Properties AtCursor - Result of getTextPropertiesAtCursor - array of property objects
- TsCompletion
Candidate - A completion candidate produced by a TypeScript plugin provider.
- TsCompletion
Context - Context sent to a TypeScript plugin’s
provideCompletionshandler. - TsCompletion
Provider Registration - Registration payload sent by a plugin to register a completion provider.
- TsHighlight
Span - Syntax highlight span for a buffer range
- View
Token Style - Styling for view tokens (used for injected annotations)
- View
Token Wire - Wire-format view token with optional source mapping and styling
- View
Transform Payload - Transformed view stream payload (plugin-provided)
- Viewport
Info - Information about the viewport
- Virtual
Buffer Result - Result of creating a virtual buffer
Enums§
- Hunk
Status - Hunk status for Review Diff
- Menu
Position - Position for inserting menu items or menus
- Overlay
Color Spec - Color specification that can be either RGB values or a theme key.
- Plugin
Async Message - Messages sent from async plugin tasks to the synchronous main loop
- Plugin
Command - Plugin command - allows plugins to send commands to the editor
- Plugin
Response - Response from the editor for async plugin operations
- View
Token Wire Kind - Wire-format view token kind (serialized for plugin transforms)