Файли
openidea/src/features/plugins/settingsPages.ts
T
l0ng-ai e3f9049e26 feat(plugins): Run Anything entries and terminals in a project directory (API 1.18) (#6197)
[[contributes.runAnything]] declares a command word (task, just...). While Run Anything's text starts with it, the IDE asks the plugin's new optional run-anything-provider export for entries; the answer arrives asynchronously, the popup re-renders when it does and drops answers for older text (300 ms budget, 100 entries). Lines starting with the word run through the plugin in the invoking window. A line the plugin claims never falls back to the shell, also when the call fails; a line it leaves goes on to the other providers and the shell.

views.open-terminal-session-in opens a keyed terminal in a directory of the project, given relative to its root. The directory must exist and stay inside the project once symlinks are resolved; trust and the approved program remain the project's.

Fixes #4758
Fixes #4754
2026-11-26 21:50:47 +08:00

129 рядки
4.3 KiB
TypeScript
Неформатований Анотація Історія

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
/**
* 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, setActivePluginTheme, SETTINGS_PAGE_ID } 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"],
["overlays", "Overlays"],
["dialogs", "Dialogs"],
["runAnything", "Run Anything"],
["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":
setActivePluginTheme(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());
}