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)
Modules§
- completion_
items_ serde - Custom deserializer module that accepts either a
Vec<String>(legacy bare-string completions) or aVec<CompletionItem>(new typed shape). Lets plugins callsetCompletions(key, ["a", "b"])andsetCompletions(key, [{ value: "a", kind: "history" }])interchangeably.
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
- Animation
Rect - A rectangular region, in cells. Used by the animation plugin API so callers can target arbitrary screen regions without going through a virtual buffer.
- Background
Process Result - Result from spawning a background process
- Buffer
Group Result - Result of creating a buffer group
- 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.
- Completion
Item - One candidate row in a Text widget’s completion popup.
valueis what gets sent back to the plugin as thecompletion_acceptpayload when the user picks the row.kindis an optional presentation hint the renderer reads to style certain rows differently from the rest — e.g."history"rows render with a leading marker glyph + italic so the user can tell at-a-glance that the entry came from their submission history rather than from the live completion source.Noneis the default “regular” candidate. - 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
- Create
Window With Terminal Options - Options for
createWindowWithTerminal— the atomic “spawn a new editor session that hosts an agent terminal” entry point used by Orchestrator. Bundles window creation, dive, and terminal spawn so the new window is born with the terminal as its seed buffer (no transient[No Name]tab, no race between create-window and create-terminal completing). - 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
- Hint
Entry - One entry in a
HintBar— a key chord plus its label. Renders as<keys> <label>with the key portion styled by theui.help_key_fgtheme key. - 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)
- KeyEvent
Payload - Payload delivered to a plugin’s
editor.getNextKey()Promise when the next keypress arrives in the editor’s input dispatch. - Language
Pack Config - Language configuration for language packs
- Layout
Hints - Layout hints supplied by plugins (e.g., Compose mode)
- LspMenu
Item - Plugin-contributed row in the LSP-Servers popup.
See
PluginCommand::SetLspMenuContributions. - 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
- Screen
Size - Total terminal size in cells. Returned by
editor.getScreenSize(). - Search
Handle State - A search handle’s shared state plus its cancellation flag. Owned by an
Arcso producers (host searcher tasks) and consumers (the JS plugin via the registry) can both reference it. - Search
State - Inner state of a streaming search, written by the host’s parallel
searchers and drained by the plugin via
SearchHandle.take(). The plugin observes deltas (mem::takeonpending) at its own cadence; producers write at full speed without per-chunk dispatches. - Search
Take Result - Per-call result from
SearchHandle.take()— the matches accumulated since the previous call plus terminal-state flags. - Session
With Terminal Result - Result of
createWindowWithTerminal— the ids of the new window plus the terminal seeded into its split layout. - Spawn
Result - Result from spawning a process with spawnProcess
- Split
Snapshot - Per-split state surfaced to plugins via
editor.listSplits(). - Styled
Text - A run of text with optional styling.
stylereusesOverlayOptions— the same primitive plugins use for virtual text — so a hint is just{ text: "Alt+P cycle", style: { fg: "ui.help_key_fg" } }.Nonestyle means “no styling override”; each consumer applies its own default (e.g. the floating-prompt title usesprompt_fg+ bold). - Terminal
Result - Result of creating a terminal
- Text
Properties AtCursor - Result of getTextPropertiesAtCursor - array of property objects
- Tree
Node - One node in a
Treewidget’s flat-list spec. The plugin walks its hierarchy depth-first and emits oneTreeNodeper node;depthcontrols indent,has_childrencontrols whether the disclosure glyph (and its hit area) is rendered. The host filters the visible window — descendants of collapsed nodes are skipped. - 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
- Virtual
Line Text Overlay - Modifier-only overlay applied to a byte range within a virtual line’s text. Used by plugins (live-diff) to bold + underline removed words on a deletion virtual line without varying the line’s overall fg/bg.
- Window
Info - Information about an editor session (plugin-visible). Returned
by
editor.listWindows()and carried in the snapshot. Mirrors the editor-sideSessionstruct — seecrates/fresh-editor/src/app/session.rsanddocs/internal/orchestrator-sessions-design.md.
Enums§
- Button
Kind - Visual role for a
Button. Maps to theme keys at render time — plugins describe intent, not colors. See §7 of the design doc. - 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
Animation Edge - Edge a slide-in effect enters from.
- Plugin
Animation Kind - Plugin-facing animation description. Tagged by
kind. Additional variants can be added later; plugins must handle thekindthey send. - 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
- Token
Color - Color carried by a
ViewTokenStyle. Untagged so JSON plugins can keep passing[r, g, b]arrays, while richer themes can use named ANSI colors ("Red","LightGreen","Default") or theme keys ("editor.diff_remove_bg"). The renderer resolves named/theme strings against the active theme at draw time; unknown strings fall through to the terminal’s default color. - View
Token Wire Kind - Wire-format view token kind (serialized for plugin transforms)
- Widget
Action - Action a plugin can request the widget runtime to perform on a
mounted panel. Bundled into a single
WidgetCommandPluginCommand so the plugin’s TypeScript layer exposes one routing method (editor.widgetCommand(panel_id, action)) rather than a fanout of per-key IPC. - Widget
Mutation - Targeted in-place mutation of a mounted widget panel — the IPC fast path. Plugins use these when the model change touches one widget; the host applies the mutation directly to the panel’s spec / instance state and re-renders without re-transmitting the full spec.
- Widget
Spec - Declarative widget tree. Each variant is one node; nested
composition is via
Row { children }/Col { children }.
Type Aliases§
- Search
Handle Registry - Registry mapping a handle ID to its shared
SearchHandleState. Shared between the JS thread (whereJsEditorApiregisters handles and servestake()/cancel()) and the editor thread (where the host’s searcher tasks write into the same state).