дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
Native auxiliary windows (settings, comparison, diff, deployment) all booted src/main.tsx, which statically imported the Workbench and every workbench feature (CodeMirror, xterm, editor extensions) even when the Settings window rendered none of them. main.tsx is now a small window-kind router with one boot module per window kind, and the settings pages, core plugin points and plugin theme runtime are registered from editor-free modules, so the Settings window loads no Workbench, @codemirror, @xterm or @/editor modules (about 57% less JS and a third less heap per Settings window). A static test keeps the Settings boot isolated. Part of #3942 Co-authored-by: dengliu <[email protected]>
126 рядки
4.2 KiB
TypeScript
126 рядки
4.2 KiB
TypeScript
/**
|
||
* Settings › Plugins for the standalone Settings window: registers the Plugins
|
||
* page, projects plugin commands/keymaps/settings/themes, and follows plugin
|
||
* updates without pulling in CodeMirror editor extensions.
|
||
*/
|
||
import { isMacHost, registerExtensionBindings } from "@/platform/keymap";
|
||
import { languageListChanged } from "@/platform/languageList";
|
||
import { lazyComponent, lazyWhen } from "@/ui";
|
||
import { registerOverlay, registerSettingsPage } from "@/workbench/contributions";
|
||
import { pluginsBackend } from "./backend";
|
||
import { ConsentDialogHost, provideConsentDialog } from "./consent";
|
||
import { defineCoreUiPoints, pluginActionId } from "./corePoints";
|
||
import { trackIconTheme } from "./iconThemes";
|
||
import { useIntellijThemesDialog } from "./intellijThemesDialogStore";
|
||
import { defineUiPoint } from "./projection";
|
||
import { refreshRunTargets, startRunTargets } from "./runTargets";
|
||
import { projectSettings, type SettingsDecl } from "./settings";
|
||
import { refreshPlugins, SETTINGS_PAGE_ID, usePlugins } from "./store";
|
||
import { syncPluginProjection, trackPluginTheme } from "./themeRuntime";
|
||
|
||
export function registerPluginsPage(): () => void {
|
||
return registerSettingsPage({
|
||
id: SETTINGS_PAGE_ID,
|
||
title: "Plugins",
|
||
// After Editor, as in IntelliJ IDEA.
|
||
order: 250,
|
||
bleed: true,
|
||
keywords: ["plugin", "extension", "wasm", "install", "theme", "marketplace"],
|
||
component: lazyComponent(() => import("./PluginsPage").then((m) => m.PluginsPage)),
|
||
});
|
||
}
|
||
|
||
const useIntellijThemesOpen = () => useIntellijThemesDialog((s) => s.open);
|
||
export const IntellijThemesDialogHost = lazyWhen(useIntellijThemesOpen, () =>
|
||
import("./IntellijThemesDialog").then((m) => m.IntellijThemesDialogHost),
|
||
);
|
||
|
||
interface KeymapDecl {
|
||
command: string;
|
||
key: string;
|
||
mac?: string | null;
|
||
when?: string | null;
|
||
}
|
||
|
||
const VIEW_ONLY_POINTS: ReadonlyArray<[string, string]> = [
|
||
["menus", "Menus"],
|
||
["statusBar", "Status Bar Items"],
|
||
["views", "Tool Windows"],
|
||
["customEditors", "Editors"],
|
||
["editorPanels", "Editor Panels"],
|
||
["markerIcons", "Marker Icons"],
|
||
["fileIcons", "File Icons"],
|
||
["commitChecks", "Commit Checks"],
|
||
["snippets", "Snippets"],
|
||
["fileTemplates", "File Templates"],
|
||
];
|
||
|
||
function defineSettingsUiPoints(): () => void {
|
||
const disposers = [
|
||
defineCoreUiPoints(),
|
||
defineUiPoint<KeymapDecl>("keymaps", {
|
||
title: "Shortcuts",
|
||
project: ({ pluginId, decl }) =>
|
||
decl.key === "Escape" && decl.when
|
||
? undefined
|
||
: registerExtensionBindings(pluginActionId(pluginId, decl.command), [
|
||
isMacHost() ? (decl.mac ?? decl.key) : decl.key,
|
||
]),
|
||
}),
|
||
defineUiPoint<SettingsDecl>("settings", {
|
||
title: "Settings",
|
||
project: ({ pluginId, decl }) => projectSettings(pluginId, decl),
|
||
}),
|
||
...VIEW_ONLY_POINTS.map(([point, title]) => defineUiPoint(point, { title })),
|
||
];
|
||
return () => disposers.reverse().forEach((d) => d());
|
||
}
|
||
|
||
function followSettingsPluginChanges(): () => void {
|
||
let refreshTimer: ReturnType<typeof setTimeout> | null = null;
|
||
const off = pluginsBackend().onEvent((e) => {
|
||
switch (e.type) {
|
||
case "runTargetsChanged":
|
||
void refreshRunTargets(false).catch(() => {});
|
||
break;
|
||
case "commandsChanged":
|
||
if (!refreshTimer) {
|
||
refreshTimer = setTimeout(() => {
|
||
refreshTimer = null;
|
||
void refreshPlugins();
|
||
}, 30);
|
||
}
|
||
break;
|
||
case "themeChanged":
|
||
usePlugins.setState({ activeTheme: e.theme });
|
||
break;
|
||
case "languagesChanged":
|
||
languageListChanged();
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
});
|
||
return () => {
|
||
if (refreshTimer) clearTimeout(refreshTimer);
|
||
off();
|
||
};
|
||
}
|
||
|
||
export function activateSettingsPages(): () => void {
|
||
const disposers = [
|
||
registerPluginsPage(),
|
||
registerOverlay({ id: "plugins.consent", component: ConsentDialogHost }),
|
||
registerOverlay({ id: "plugins.intellijThemes", component: IntellijThemesDialogHost }),
|
||
provideConsentDialog(),
|
||
defineSettingsUiPoints(),
|
||
followSettingsPluginChanges(),
|
||
startRunTargets(false),
|
||
syncPluginProjection(),
|
||
trackPluginTheme(),
|
||
trackIconTheme(),
|
||
];
|
||
void refreshPlugins();
|
||
return () => disposers.reverse().forEach((d) => d());
|
||
}
|