дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-08 19:02:17 +02:00
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]>
95 рядки
3.4 KiB
TypeScript
95 рядки
3.4 KiB
TypeScript
/**
|
||
* Theme / color scheme / keymap / view mode switches shared by the main
|
||
* toolbar's gear menu and View › Quick Switch Scheme… (⌃`).
|
||
*/
|
||
import { call, commands, isTauri } from "@/platform/ipc";
|
||
import { listSchemes } from "@/platform/colorScheme";
|
||
import { editorPrefs } from "@/platform/editorSettings";
|
||
import { PRESET_TITLES, useKeymap } from "@/platform/keymap";
|
||
import { useProject } from "@/platform/project";
|
||
import type { MenuItem } from "@/ui";
|
||
import { themeChoices } from "@/platform/themes";
|
||
import { currentThemeChoice, setTheme } from "./theme";
|
||
|
||
async function setGlobal(key: string, value: unknown, what: string) {
|
||
if (!isTauri()) return;
|
||
try {
|
||
useProject.setState({ settings: await call(commands.settingsSet("global", key, JSON.stringify(value))) });
|
||
} catch (e) {
|
||
console.warn(`cannot switch ${what}`, e);
|
||
}
|
||
}
|
||
|
||
export const selectKeymap = (id: string) => setGlobal("keymap", id, "keymap");
|
||
|
||
export function themeItems(themeId: string = currentThemeChoice()): MenuItem[] {
|
||
return themeChoices().map<MenuItem>((c) => ({
|
||
id: `theme.${c.id}`,
|
||
label: c.label,
|
||
// Plugin themes keep their own names.
|
||
verbatim: !!c.origin,
|
||
checked: c.id === themeId,
|
||
run: () => void setTheme(c.id),
|
||
}));
|
||
}
|
||
|
||
export function keymapItems(keymapId: string, customKeymaps: string[]): MenuItem[] {
|
||
return [...Object.keys(PRESET_TITLES), ...customKeymaps].map<MenuItem>((id) => ({
|
||
id: `keymap.${id}`,
|
||
label: PRESET_TITLES[id] ?? id,
|
||
verbatim: !PRESET_TITLES[id],
|
||
checked: id === keymapId,
|
||
run: () => void selectKeymap(id),
|
||
}));
|
||
}
|
||
|
||
export function colorSchemeItems(current: string | undefined): MenuItem[] {
|
||
const schemes = listSchemes(editorPrefs().customSchemes);
|
||
const value = current && schemes.some((s) => s.id === current) ? current : "theme-default";
|
||
return [
|
||
{
|
||
id: "scheme.theme-default",
|
||
label: "Theme default",
|
||
checked: value === "theme-default",
|
||
run: () => void setGlobal("editor.colorScheme", "theme-default", "color scheme"),
|
||
},
|
||
...schemes.map<MenuItem>((s) => ({
|
||
id: `scheme.${s.id}`,
|
||
label: s.name,
|
||
checked: s.id === value,
|
||
run: () => void setGlobal("editor.colorScheme", s.id, "color scheme"),
|
||
})),
|
||
];
|
||
}
|
||
|
||
/** The existing view modes: Distraction Free Mode and Full Screen. */
|
||
export const VIEW_MODE_ITEMS: MenuItem[] = [
|
||
{ kind: "action", action: "editor.toggleZen" },
|
||
{ kind: "action", action: "window.toggleFullScreen" },
|
||
];
|
||
|
||
/** The keymap in effect and the user's custom keymaps. */
|
||
export function keymapState(): { keymapId: string; customs: string[] } {
|
||
const settings = useProject.getState().settings;
|
||
const customs = settings?.customKeymaps;
|
||
return {
|
||
keymapId: typeof settings?.keymap === "string" ? settings.keymap : useKeymap.getState().preset,
|
||
customs: customs && typeof customs === "object" ? Object.keys(customs) : [],
|
||
};
|
||
}
|
||
|
||
/** View › Quick Switch Scheme…: IDEA's popup of the switchable schemes. */
|
||
export function quickSwitchItems(): MenuItem[] {
|
||
const { keymapId, customs } = keymapState();
|
||
return [
|
||
{
|
||
id: "qs.scheme",
|
||
label: "Editor Color Scheme",
|
||
submenu: colorSchemeItems(useProject.getState().settings?.editor?.colorScheme),
|
||
},
|
||
{ id: "qs.keymap", label: "Keymap", submenu: keymapItems(keymapId, customs) },
|
||
{ id: "qs.viewMode", label: "View Mode", submenu: VIEW_MODE_ITEMS },
|
||
{ id: "qs.theme", label: "Theme", submenu: themeItems() },
|
||
];
|
||
}
|