дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-30 06:12:33 +02:00
[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
232 рядки
10 KiB
Plaintext
232 рядки
10 KiB
Plaintext
package openidea:[email protected];
|
||
|
||
/// Declarative views: tool windows declared
|
||
/// under `[[contributes.views]]` and custom editors under
|
||
/// `[[contributes.customEditors]]`. The plugin describes what to show; the
|
||
/// IDE renders it with its own components (theme, keyboard, accessibility)
|
||
/// and sends the user's actions back as `view-event`s. Nothing of the plugin
|
||
/// runs in the WebView, except a `html` body, which is shown in a sandboxed
|
||
/// frame that can only exchange messages with the plugin.
|
||
interface view-types {
|
||
use types.{extension};
|
||
|
||
record button {
|
||
id: string,
|
||
label: string,
|
||
/// An IDE icon name (`refresh`, `add`, `remove`, `run`, …).
|
||
icon: option<string>,
|
||
enabled: bool,
|
||
}
|
||
|
||
/// A tree node; `parent` is the key of an earlier item (none: a root).
|
||
record tree-item {
|
||
key: string,
|
||
parent: option<string>,
|
||
label: string,
|
||
icon: option<string>,
|
||
/// Grey text after the label.
|
||
detail: option<string>,
|
||
/// Shows an expander even before its children are known
|
||
/// (`expand` asks for them).
|
||
expandable: bool,
|
||
expanded: bool,
|
||
}
|
||
|
||
record list-item {
|
||
key: string,
|
||
label: string,
|
||
icon: option<string>,
|
||
detail: option<string>,
|
||
}
|
||
|
||
variant field-value {
|
||
text(string),
|
||
multiline(string),
|
||
checkbox(bool),
|
||
/// The options and the chosen one.
|
||
choice(tuple<list<string>, string>),
|
||
/// A field type added after 1.0 (an IDE that doesn't know it leaves it out).
|
||
other(extension),
|
||
}
|
||
|
||
record field {
|
||
key: string,
|
||
label: string,
|
||
value: field-value,
|
||
}
|
||
|
||
/// Rows `first-row`..`first-row + len(rows)` of `total-rows`: the IDE
|
||
/// asks for the rows it shows (`viewport`), so large tables stay cheap.
|
||
record table {
|
||
columns: list<string>,
|
||
total-rows: u32,
|
||
first-row: u32,
|
||
rows: list<list<string>>,
|
||
editable: bool,
|
||
}
|
||
|
||
variant body {
|
||
/// A centred message (empty state, errors).
|
||
message(string),
|
||
tree(list<tree-item>),
|
||
%list(list<list-item>),
|
||
form(list<field>),
|
||
table(table),
|
||
/// HTML shown in a sandboxed frame: no scripts from elsewhere, no
|
||
/// network, no IDE API. Its script talks to the plugin with
|
||
/// `openidea.postMessage(text)` / `openidea.onMessage(fn)`.
|
||
html(string),
|
||
/// A body added after 1.0; an IDE that doesn't know it says it needs updating.
|
||
other(extension),
|
||
}
|
||
|
||
record view {
|
||
toolbar: list<button>,
|
||
body: body,
|
||
/// A line below the body (counts, last refresh…).
|
||
status: option<string>,
|
||
}
|
||
|
||
/// The table rows the IDE shows.
|
||
record viewport {
|
||
first-row: u32,
|
||
rows: u32,
|
||
}
|
||
|
||
record cell-edit {
|
||
row: u32,
|
||
column: u32,
|
||
value: string,
|
||
}
|
||
|
||
variant view-event {
|
||
/// A toolbar button.
|
||
button(string),
|
||
/// Double click / Enter on a tree or list item.
|
||
activate(string),
|
||
select(string),
|
||
expand(string),
|
||
collapse(string),
|
||
/// A form field changed: key and new value (`true`/`false` for checkboxes).
|
||
field(tuple<string, string>),
|
||
cell(cell-edit),
|
||
/// Insert an empty row before this one (the row count: append).
|
||
insert-row(u32),
|
||
delete-rows(list<u32>),
|
||
/// From the `html` body's script.
|
||
message(string),
|
||
/// An event added after 1.0, from a body or field added after 1.0.
|
||
other(extension),
|
||
}
|
||
}
|
||
|
||
/// What a plugin's code can ask of its views.
|
||
interface views {
|
||
use types.{error};
|
||
use detail-types.{process-log};
|
||
use process.{command};
|
||
|
||
/// An editor toolbar action; at most one action is the Save handler.
|
||
record content-action { id: string, label: string, icon: option<string>, primary: bool, save: bool }
|
||
/// A plugin-owned content editor, scoped by key to the invoking window.
|
||
record content-tab {
|
||
key: string, title: string, file-name: option<string>, language: option<string>,
|
||
content: string, read-only: bool, actions: list<content-action>,
|
||
}
|
||
/// A comparison opened by a content action reply.
|
||
record content-diff { left: string, right: string, left-label: option<string>, right-label: option<string>, title: option<string> }
|
||
/// A file's before and after for `open-file-diff` (API 1.10): none is a side
|
||
/// where the file doesn't exist (an added file has no left side, a deleted
|
||
/// one no right side).
|
||
record file-diff { left: option<string>, right: option<string>, left-label: option<string>, right-label: option<string>, title: option<string> }
|
||
/// Optional updates to an outstanding action or Save request.
|
||
record content-tab-reply {
|
||
content: option<string>, saved: option<bool>, read-only: option<bool>,
|
||
status: option<string>, error: option<string>, diff: option<content-diff>,
|
||
}
|
||
/// Opens or focuses a running session with this key; env is append-only.
|
||
/// Only from a window command/event; the id receives one terminal-exited.
|
||
open-terminal-session: func(key: string, title: string, cmd: command) -> result<string, error>;
|
||
/// `open-terminal-session` started in `cwd` (API 1.18): a directory of the invoking
|
||
/// window's project, relative to its root (`""` is the root). It must exist and stay
|
||
/// inside the project once symlinks are resolved; `invalid` otherwise. Trust and the
|
||
/// approved program are the project's, whatever the directory. A running session with
|
||
/// this key is focused as it is, without moving it.
|
||
open-terminal-session-in: func(key: string, title: string, cmd: command, cwd: string) -> result<string, error>;
|
||
/// Writes to this plugin's running keyed terminal in the invoking window.
|
||
write-terminal: func(key: string, text: string) -> result<_, error>;
|
||
/// Opens the existing content editor protocol without a web view.
|
||
open-content-tab: func(tab: content-tab) -> result<_, error>;
|
||
/// Answers content-tab-action in its originating window.
|
||
reply-content-tab: func(request-id: string, reply: content-tab-reply) -> result<_, error>;
|
||
/// Opens two texts in the diff viewer of the window the call came from
|
||
/// (API 1.7): a review's file before and after, say. `file-name` (a name or
|
||
/// relative path, at most 256 characters) picks the syntax highlighting and
|
||
/// names the tab when `diff.title` is absent. Only from a command or event
|
||
/// of a window. Each side at most 8 MiB (earlier hosts: 1 MiB); a larger
|
||
/// side fails with `invalid("diff too large: …")`.
|
||
open-diff: func(diff: content-diff, file-name: option<string>) -> result<_, error>;
|
||
/// `open-diff` for a file that may not exist on one side (API 1.10): the
|
||
/// diff viewer shows the existing side alone, as for the IDE's own added
|
||
/// and deleted files, instead of next to an empty text. Both sides none is
|
||
/// `invalid`.
|
||
open-file-diff: func(diff: file-diff, file-name: option<string>) -> result<_, error>;
|
||
|
||
/// The view (or every custom editor of that id) shows outdated content:
|
||
/// the IDE renders it again.
|
||
refresh: func(view: string);
|
||
/// Brings one of the plugin's own views to the front in the window the
|
||
/// current command or event came from; `invalid` outside one.
|
||
reveal: func(view: string) -> result<_, error>;
|
||
/// Sends a message to the script of a view's `html` body.
|
||
post-message: func(view: string, message: string) -> result<_, error>;
|
||
/// Opens a terminal tab in the window the call came from, running
|
||
/// `program` (pinned by a `process:<program>` grant) with `args` in the
|
||
/// project root: long-running output (logs) and interactive sessions.
|
||
open-terminal: func(title: string, program: string, args: list<string>) -> result<_, error>;
|
||
/// Opens a read-only log tab in the editor area of the window the call
|
||
/// came from, following `log`'s program (pinned by a `process:<program>`
|
||
/// grant) in the project root, its toggles above the output: the tab a
|
||
/// web view opens with `open-log-tab`. Reopening `key` focuses that tab.
|
||
/// Only from a command or event of a window; `title` at most 256
|
||
/// characters, `key` 128, at most 32 toggles.
|
||
open-log-tab: func(key: string, title: string, log: process-log) -> result<_, error>;
|
||
/// Opens `path` (project-relative or absolute, inside the project) in an
|
||
/// editor of the window the call came from, the caret at `line` and
|
||
/// `column` (0-based; UTF-16 column): a view's links to code.
|
||
/// An absolute path inside the plugin's own fs.plugin-dir or its install
|
||
/// directory also works, without project.read or an open project, from a
|
||
/// command or event.
|
||
open-location: func(path: string, line: u32, column: u32) -> result<_, error>;
|
||
}
|
||
|
||
/// The plugin's own settings (`[contributes.settings]`), as the user set them
|
||
/// (project over global) or the schema's default.
|
||
interface settings {
|
||
use types.{error};
|
||
|
||
/// The value of `key` as JSON (`true`, `3`, `"text"`), none if unknown.
|
||
get: func(key: string) -> option<string>;
|
||
/// Opens Settings at one of the plugin's own pages in the window the
|
||
/// current command or event came from (API 1.19): `page` is the `id` of a
|
||
/// `[[contributes.settings.pages]]` entry, none for the plugin's settings
|
||
/// node itself. `invalid` outside a window's command or event, `not-found`
|
||
/// for a page the plugin does not declare (or without `[contributes.settings]`).
|
||
open: func(page: option<string>) -> result<_, error>;
|
||
/// Opens Settings › Plugins at this plugin's permissions, where the user
|
||
/// grants an optional capability it lacks (API 1.19). `invalid` outside a
|
||
/// window's command or event.
|
||
open-permissions: func() -> result<_, error>;
|
||
}
|
||
|
||
/// Optional export (world `plugin-views`): content of declared views and
|
||
/// custom editors. For a custom editor, `ctx.editor()` is its document.
|
||
interface view-provider {
|
||
use view-types.{view, viewport, view-event};
|
||
use invocation.{invocation};
|
||
use types.{error};
|
||
|
||
render: func(view: string, viewport: option<viewport>, ctx: borrow<invocation>) -> result<view, error>;
|
||
handle: func(view: string, event: view-event, ctx: borrow<invocation>) -> result<_, error>;
|
||
}
|