Файли
openidea/wit/events.wit
T
l0ng-ai 3f74972f11 feat(plugins): one-shot timers a plugin sets for itself (API 1.21) (#8239)
events.schedule(id, after-ms) wakes the plugin once with a timer event in the window of the call that set it; the same id replaces it, so retries and backoff stay the plugin's own, and events.cancel-schedule drops it. 250 ms to 24 h, at most 16 pending, no capability. Timers activate an idle plugin, survive idle reclaim and end with the window, its project or the plugin. SDK: host::schedule, host::cancel_schedule, Event::Timer, MockHost timers. Components rebuilt.

Closes #8195
2026-12-05 22:31:19 +08:00

121 рядки
7.1 KiB
Plaintext

package openidea:[email protected];
/// Workbench events, delivered in batches to `event-handler.handle`.
interface events {
use types.{error, extension};
record action-performed {
/// Action id (`editor.duplicate-line`).
action: string,
title: string,
/// How the user started it: `keyboard`, `menu`, `toolbar`,
/// `context-menu`, `search` or `other` (more may be added).
source: string,
/// Its keyboard shortcut, when it has one (`Ctrl+D`).
shortcut: option<string>,
}
variant event {
file-opened(string),
file-saved(string),
editor-focused(option<string>),
action-performed(action-performed),
vcs-changed(string),
scheduled,
/// A kind added after 1.0 (subscribed to by its name).
other(extension),
}
/// Delivers `kind` events from now on, for the rest of the session (also
/// across idle reclaim: an event activates the plugin again). Declare
/// `activation = ["on-event:<kind>"]` to get them before first use.
/// API 1.4 also delivers `file-closed` (JSON path string), `settings-changed`
/// (JSON array of the plugin's changed setting keys), and `input-mode-changed`
/// (JSON {path, mode, sub}) through `other`. The last needs `events.input`.
/// API 1.5 also delivers `extensions-changed` (JSON array of the extension
/// points this plugin declares whose contributions changed) through `other`,
/// to the declaring plugin only and without a capability.
/// API 1.15 also delivers `caret-moved` (JSON {path, line, col, settled},
/// 0-based UTF-16 positions, when the caret moves in the focused editor;
/// `settled` is true for the final position once the caret rests, so costly
/// work waits for it; it requires `events`) through `other`.
/// API 1.18 also delivers `project-closed` (JSON project root string) and
/// `watched-files-changed` (see `watch-paths`) through `other`.
/// API 1.21 also delivers `run-started` (JSON {id, config, debug}) through `other`
/// whenever one of this plugin's configurations starts (whether launched by the plugin
/// or by the user), `run-exited` for user-launched plugin configurations, and `run-output`
/// (JSON {runId, configId, stream, text}) when subscribing with `run.output` in a trusted project.
/// Kinds: `file-opened`, `file-saved`, `document-changed` (versioned UTF-16
/// replacements from explicit path subscriptions), `websocket-ready`
/// (a host-owned connection has messages to drain), `caret-moved`, `files-changed` (batched disk changes
/// as `other`, with created/modified/removed path lists in JSON), `editor-focused` (the focused editor
/// changed), `vcs-changed` (a repository's state changed: commit,
/// checkout, fetch…), `action-performed` (an IDE action ran),
/// `project-closed` (a project closed), `run-started`, `run-exited`, and
/// `scheduled` (the `on-schedule` period elapsed); later IDEs add more,
/// and an IDE that doesn't know one fails with `invalid`.
/// Requires `events` (`events.input` for `action-performed`).
subscribe: func(kind: string) -> result<_, error>;
/// Options for file path subscriptions (API 1.18).
record subscription-options {
globs: list<string>,
/// Debounce quiet window in milliseconds before delivering changes (API 1.18).
/// When omitted, changes are delivered immediately without debounce.
debounce-ms: option<u32>,
}
/// Replaces this kind's subscription with project-relative globs (OR).
/// Empty globs pause delivery; `subscribe` restores unfiltered delivery.
/// Kinds: file-opened, file-saved, document-changed, files-changed. Requires `events`.
subscribe-paths: func(kind: string, globs: list<string>) -> result<_, error>;
/// Replaces this kind's subscription with project-relative globs and options (API 1.18).
/// Kinds: file-opened, file-saved, document-changed, files-changed. Requires `events`.
subscribe-paths-with-options: func(kind: string, options: subscription-options) -> result<_, error>;
/// Watches files and directories outside the invoking window's project (API 1.18),
/// replacing what this plugin watched for that project; an empty list stops.
/// Each path is absolute (or `~/…`), exists, and is readable through an
/// `fs.read:<path>` grant, checked where it really is: a link out of the grant
/// is `denied` (naming the capability). Paths inside the project are `invalid`
/// (they come with `files-changed`); at most 32. A file is watched where it is,
/// across atomic saves, removal and re-creation; a directory for its own entries,
/// not recursively. Changes arrive as `watched-files-changed` events through
/// `other`: JSON {project, created, modified, removed} like `files-changed`,
/// debounced and coalesced, so read the files again rather than replaying
/// steps; a rename is the old path removed and the new one created. A removed
/// watched directory is reported once and no longer watched: call again once
/// it exists. Watches end when the project or its window closes, or the plugin
/// stops (disabled, updated, or a grant revoked); idle reclaim keeps them, and
/// an event activates the plugin again. Nothing is watched over the network:
/// remote files need the plugin's own refresh. Requires `events` and a call
/// that serves a window's project (a command or event).
watch-paths: func(paths: list<string>) -> result<_, error>;
unsubscribe: func(kind: string);
/// Wakes this plugin once, `after-ms` milliseconds from now (API 1.21), for retries,
/// backoff and polling the plugin paces itself: a `timer` event (JSON string: `id`)
/// arrives through `other`, in the window of the call that scheduled it. Scheduling an
/// `id` again replaces it, so the next delay is the plugin's own choice. An idle plugin
/// is activated for it. `after-ms` is 250 ms to 24 h; `id` is 1-128 bytes; at most 16
/// timers are pending per plugin. They end when they fire, on `cancel-schedule`, when
/// the window closes, or when the plugin stops (disabled, updated, uninstalled); idle
/// reclaim keeps them. No capability: a plugin only wakes itself.
schedule: func(id: string, after-ms: u32) -> result<_, error>;
/// Cancels the pending `schedule` with this `id` (API 1.21); an unknown id does nothing.
cancel-schedule: func(id: string);
}
/// Long-running work with a progress indicator. While a task is open, the
/// call that began it may run for the background budget (60 s) instead of 5 s,
/// and each `report` or `is-cancelled` renews that budget: work that keeps
/// saying it is alive is not cut off, while work that goes quiet is.
interface tasks {
resource task {
/// `done` of `total` units (`none`: indeterminate), with a short status.
report: func(done: u32, total: option<u32>, message: option<string>);
/// The user cancelled it: stop soon and return.
is-cancelled: func() -> bool;
}
/// Starts a task shown in the status bar; dropping it ends it.
begin: func(title: string, cancellable: bool) -> task;
}