feat(plugins): plugin system with extension points, consent, Wasm runtime and plugin API 1.0 (#971)

A plugin system built on WebAssembly components (wasmtime, WASI p2), with a
typed WIT API (`openidea:[email protected]`) and a Rust SDK, shipped as a preview.

- Extension points declared in `plugin.toml` (commands, languages, themes,
  icon themes, menus, key bindings, status items, settings, views, custom
  editors, file icons and templates, run detectors, editor providers),
  validated before anything takes effect and projected onto the workbench's
  own registries: plugin themes and file icon themes are chosen in
  Settings › Appearance and Quick Switch, plugin shortcuts are edited in
  Settings › Keymap, plugin problems are grouped in Settings › Inspections.
- Capabilities with risk levels and consent at install, pinned `process:`
  programs, secrets in the OS keychain.
- Runtime: one thread per active plugin, fuel/time/memory budgets, soft and
  hard deadlines on the editing path, cancellation, crash backoff, idle
  reclaim, a precompiled-component cache; remote projects run code plugins on
  `openidea-server`.
- Web views and custom editors with a sandboxed page, a document bridge
  joined to the text editor's undo history, and split or preview layouts.
- Distribution: signed `.oiplugin` packages, a static marketplace index with
  revocation, versioned installs with rollback, install from a `.zip` or a
  folder. The release workflow signs and publishes the official plugins and
  their index, which released builds use as the default marketplace.
- Official plugins: String Tools, Key Promoter, Git Toolbox, AI Completion,
  Checkstyle, MyBatis Navigator, CSV Editor, Solidity, Material Icons, Harbor
  Night, Excalidraw, Graphviz, Regex Tester, License Header.

Closes #732

Co-authored-by: Deng Liu <[email protected]>
Co-authored-by: florentvdry <[email protected]>
Цей коміт міститься в:
authored and GitHub committed 2026-11-04 02:54:31 +08:00
1 джерело cfdbd3872a
коміт 1c5a92f952
450 files changed
+47018 -3058

No files matched your search

+11
Переглянути файл
@@ -21,8 +21,10 @@ import { _languageMode } from "@/editor/api";
let infos: Map<string, LanguageInfo> | null = null;
let infosPromise: Promise<Map<string, LanguageInfo>> | null = null;
let infosBackend: DocBackend | null = null;
export function loadLanguageInfos(backend: DocBackend): Promise<Map<string, LanguageInfo>> {
infosBackend = backend;
return (infosPromise ??= backend
.languages()
.then((list) => (infos = new Map(list.map((l) => [l.id, l]))))
@@ -37,6 +39,15 @@ export function languageInfo(id: string): LanguageInfo | undefined {
return infos?.get(id);
}
/**
* The language list changed (a plugin added or removed languages): fetch it
* again. Open documents follow through their `docLanguage` events.
*/
export function refreshLanguageInfos(): Promise<unknown> {
infosPromise = null;
return infosBackend ? loadLanguageInfos(infosBackend) : Promise.resolve();
}
/** Test hook. */
export function _resetLanguages() {
infos = null;
+57
Переглянути файл
@@ -110,4 +110,61 @@ describe("attached document views (editable diff side)", () => {
att.release();
tab.dispose();
});
it("undoes backend edits in the document's history: the text tab's when one is open (custom editors)", async () => {
const { backend, manager, frame } = setup({ "/p/c.csv": "a,b\n" });
const att = await attachDocument(manager, "/p/c.csv");
const view = new EditorView({ doc: att.text(), extensions: [att.extension, history()] });
const model = manager.get("/p/c.csv")!;
expect(att.doc).toBe(model.doc);
// No tab: the attachment holds the history.
backend.patch(model.doc, [{ from: 0, to: 1, insert: "X" }]);
expect(att.undo()).toBe(true);
expect(view.state.doc.toString()).toBe("a,b\n");
expect(att.redo()).toBe(true);
expect(view.state.doc.toString()).toBe("X,b\n");
await frame();
await att.synced();
expect(backend.docs.get(model.doc)?.text).toBe("X,b\n");
// With a text tab, backend edits are recorded there: undo from the custom editor reaches it.
const tab = new EditorSlot(model, "t1", host);
backend.patch(model.doc, [{ from: 2, to: 3, insert: "Y" }]);
expect(tab.currentState().doc.toString()).toBe("X,Y\n");
expect(att.undo()).toBe(true);
expect(tab.currentState().doc.toString()).toBe("X,b\n");
expect(view.state.doc.toString()).toBe("X,b\n");
view.destroy();
att.release();
tab.dispose();
});
it("records an attachment's own edits in the document's history: the text tab's when one is open", async () => {
const { manager } = setup({ "/p/d.excalidraw": "{}" });
const att = await attachDocument(manager, "/p/d.excalidraw");
const view = new EditorView({ doc: att.text(), extensions: [att.extension, history()] });
const model = manager.get("/p/d.excalidraw")!;
// No tab: the view's own history.
att.edit({ from: 1, insert: "a" });
expect(view.state.doc.toString()).toBe("{a}");
expect(att.undo()).toBe(true);
expect(view.state.doc.toString()).toBe("{}");
// With a text tab: the edit is the tab's, so Undo there reverts it, and the view follows.
const tab = new EditorSlot(model, "t1", host);
att.edit({ from: 1, insert: "b" }, "input.plugin");
expect(tab.currentState().doc.toString()).toBe("{b}");
expect(view.state.doc.toString()).toBe("{b}");
// `undo` runs where the history is: the tab's (what ⌘Z in the text editor runs).
expect(att.undo()).toBe(true);
expect(tab.currentState().doc.toString()).toBe("{}");
expect(view.state.doc.toString()).toBe("{}");
// The view's own history never had it.
expect(undo(view)).toBe(false);
view.destroy();
att.release();
tab.dispose();
});
});
+28 -1
Переглянути файл
@@ -3,7 +3,8 @@
* diff): local edits flow view → model → backend and other editors; edits
* from elsewhere are mirrored into the view. See `attachDocument` in editor/api.
*/
import { Transaction, type Annotation, type ChangeSet } from "@codemirror/state";
import { redo, undo } from "@codemirror/commands";
import { Transaction, type Annotation, type ChangeSet, type StateCommand } from "@codemirror/state";
import { EditorView, ViewPlugin } from "@codemirror/view";
import {
_addEditor,
@@ -65,8 +66,24 @@ export async function attachDocument(manager: DocumentManager, path: string): Pr
};
});
/** Runs a history command where the document's history is (see `DocumentAttachment.undo`). */
const historyCommand = (command: StateCommand): boolean => {
const slot = model.primarySlot();
if (slot?.view) return command(slot.view);
if (slot)
return command({
state: slot.state,
dispatch: (tr) => {
slot.state = tr.state;
if (tr.docChanged) model.onLocal(tr.changes, slot);
},
});
return target.view ? command(target.view) : false;
};
return {
path,
doc: model.doc,
text: () => model.sync.localText.toString(),
readOnly: model.getMeta().readOnly || model.virtual,
extension: [
@@ -81,6 +98,16 @@ export async function attachDocument(manager: DocumentManager, path: string): Pr
}),
],
save: (options) => model.save(options?.exact ? "exact" : "explicit"),
synced: () => model.sync.whenIdle(),
dirty: () => model.getMeta().dirty,
undo: () => historyCommand(undo),
redo: () => historyCommand(redo),
edit: (changes, userEvent = "input") => {
// Into the document's history, like a typed edit: the text tab's when there is one.
const slot = model.primarySlot();
if (slot) slot.dispatchLocal({ changes, userEvent });
else target.view?.dispatch({ changes, userEvent });
},
release: () => {
if (released) return;
released = true;