Файли
openidea/wit/exports.wit
T
l0ng-ai dfea6d2c1e feat(plugins): explain capabilities and open a plugin's own settings (API 1.19) (#6830)
[capabilities.reasons] lets a plugin say in one sentence why it asks for a declared capability. The permission dialog and the plugin's details in Settings › Plugins show it below the IDE's own description, marked as the plugin's words and never instead of it; it is translated through the plugin's locales/<tag>.json. Keys must be capabilities under required or optional; reasons are 1-500 characters.

settings.open(page) opens Settings at the plugin's node or one of its declared pages, and settings.open-permissions at its permissions in Settings › Plugins (plugins#permissions:<id>, so it also reaches a separate Settings window), letting a notice take the user straight there. Both work only from a command or event of a window; an undeclared page is not-found.

Plugin API 1.19.0: WIT package, engine, SDK wrappers and mock, rebuilt components; 1.18 is recorded as shipped with 0.1.54. The settings-pages fixture exercises both additions.

Refs #6745
2026-11-29 18:24:29 +08:00

146 рядки
6.6 KiB
Plaintext

package openidea:[email protected];
interface lifecycle {
use types.{context, error};
/// Called once after the instance is created: subscribe to events and
/// restore state from `storage`. Contributions (commands, languages,
/// themes, …) are declared in plugin.toml, not registered here.
/// An error fails the activation (shown on the plugin's page).
activate: func(ctx: context) -> result<_, error>;
/// Called before the instance is dropped (disable, uninstall, idle reclaim).
deactivate: func();
}
interface commands {
use types.{error};
use invocation.{invocation};
/// Runs one of the plugin's commands. Returns an optional message.
/// `cancelled` (the user gave up) and `denied` (a capability is missing)
/// are not counted as the plugin failing.
run: func(id: string, ctx: borrow<invocation>, arg: option<string>) -> result<option<string>, error>;
}
interface event-handler {
use events.{event};
use invocation.{invocation};
/// A batch of subscribed events, oldest first, from one window (`ctx`).
handle: func(events: list<event>, ctx: borrow<invocation>);
}
/// Optional export (world `plugin-syntax`): syntax of the plugin's own
/// languages, for languages the IDE has no grammar for. The IDE calls it
/// with the whole document; results are flat. Offsets are UTF-8 byte offsets
/// into `text` (the IDE converts them); lines are 0-based.
interface syntax-provider {
/// One highlighted range. `kind` is a highlight category: keyword, string,
/// string-special, escape, regexp, atom, number, constant, comment,
/// doc-comment, function, function-call, builtin, type, namespace,
/// variable, self-variable, property, attribute, macro, label, tag,
/// operator, punctuation. Unknown kinds are ignored; ranges must be
/// sorted and not overlap.
record token {
start: u32,
end: u32,
kind: string,
}
/// A symbol of the structure view. `parent` is the index of the enclosing
/// symbol in the same list (which must come first).
record symbol {
name: string,
detail: option<string>,
/// class, interface, struct, enum, function, method, constructor,
/// field, property, variable, constant, module, namespace, event, …
kind: string,
start: u32,
end: u32,
name-start: u32,
name-end: u32,
parent: option<u32>,
}
/// A foldable line range. `kind`: region, comment or imports.
record fold {
start-line: u32,
end-line: u32,
kind: string,
}
highlights: func(language: string, text: string) -> list<token>;
outline: func(language: string, text: string) -> list<symbol>;
folding: func(language: string, text: string) -> list<fold>;
}
/// Optional Run Anything (Ctrl Ctrl) entries and command lines for the prefixes
/// the plugin declares under `[[contributes.runAnything]]` (API 1.18).
interface run-anything-provider {
record run-anything-item {
/// What the list shows, such as `task build`.
label: string,
/// Grey text after the label.
detail: option<string>,
/// The line Tab completes in the field and Enter runs (default: `label`).
line: option<string>,
}
/// Entries for `text`, the field's text, which starts with the declared `prefix`
/// (or is the start of it). Answer from what the plugin already knows: the IDE
/// asks while the user types, keeps the first 100 entries, and drops an answer
/// that comes after the text changed or takes longer than 300 ms.
suggest: func(project: string, prefix: string, text: string) -> list<run-anything-item>;
/// Runs `line`, whose first word is `prefix`, from the invoking window: the
/// plugin starts it through its own host calls (`run.start`, terminals), with
/// their trust and grant checks. True claims the line; false leaves it to the
/// IDE's other entries and finally the shell. A failed call claims the line
/// too, so it never runs in the shell instead.
run: func(project: string, prefix: string, line: string) -> bool;
}
/// Optional completion in the fields of this plugin's own run configurations, in
/// the Run/Debug Configurations dialog (API 1.18).
interface run-configuration-completion {
record completion-item {
/// What the list shows, such as `build`.
label: string,
/// Grey text after the label, such as the file the entry comes from.
detail: option<string>,
/// The text that replaces `[replace-start, replace-end)` (default: `label`).
insert: option<string>,
/// UTF-16 offsets into `text`; the caret ends after the inserted text.
replace-start: u32,
replace-end: u32,
}
/// Completions for `field` of the configuration `config` (its id as this plugin
/// reported it) in `project`. `field` is `arguments` today: the field splits like a
/// shell command line (whitespace separates arguments, `'` and `"` quote). Later
/// IDEs may ask for other fields, so answer none for a field you don't know.
/// `text` is the field as typed and `caret` a UTF-16 offset into it. Replace only
/// the token being completed, so the other options, quoted values and arguments
/// after `--` stay as they are. Answer from what the plugin already knows (no
/// process per keystroke): the IDE asks while the user types, keeps the first 200
/// items, drops an item whose range is outside `text`, and drops an answer that
/// comes after the text changed or takes longer than 300 ms.
complete: func(project: string, config: string, field: string, text: string, caret: u32) -> list<completion-item>;
}
/// Optional pre-launch gate for targets owned by this plugin (API 1.5).
interface run-target-validation {
enum operation { run, test }
record launch-info {
operation: operation,
/// Bare program name before wrapping; no arguments or environment.
program: string,
/// Absolute working directory on the machine hosting the plugin.
cwd: string,
}
/// Called after trust, ownership, process grants and executable pin checks.
/// An error refuses the launch without changing the selected target. The
/// host prefixes and bounds the message. Missing exports allow the launch.
/// Calls wake reclaimed instances, use the host call timeout (5s by default),
/// and are cancelled with the launch. Traps/timeouts refuse the launch.
/// For remote projects this runs on the server, where the plugin lives.
validate: func(project: string, target-id: string, launch: launch-info) -> result<_, string>;
}