Файли
openidea/src/features/plugins/views/logActions.ts
T
Deng Liuтаdengliu fbf57bed23 feat(plugins): generic streaming log editor tab for plugin web views (#2043)
A plugin web view can open a read-only editor tab that streams a process's output, with plugin-defined toggles, Find, wrap, zoom and Clear. The process is authorised in the backend against the exact granted `process:<program>` and its pinned executable, output is bounded, and the stream survives tab switches but ends when the tab closes, the plugin is disabled or the window closes. Adds a web-log test fixture and docs. Verified on macOS; Windows/Linux not run.

Co-authored-by: dengliu <[email protected]>
2026-11-08 04:06:04 +08:00

54 рядки
1.6 KiB
TypeScript

import { registerActions } from "@/platform/actions";
import { editorService } from "@/workbench/contributions";
export interface LogControls {
key: string;
find(): void;
clear(): void;
wrap(): void;
toggle(id: string, checked: boolean): void;
}
const controls = new Map<string, LogControls>();
export function bindLogControls(id: string, value: LogControls): () => void {
controls.set(id, value);
return () => {
controls.delete(id);
};
}
/** Toolbar actions address their own tab; user keybindings address the active input. */
export function registerLogActions(): () => void {
const target = (arg: unknown) => {
if (typeof arg === "string") return controls.get(arg);
const input = editorService().activeInput?.();
return input?.kind === "pluginLog" ? [...controls.values()].find((c) => c.key === input.key) : undefined;
};
return registerActions([
...(
[
["find", "Find in Logs"],
["clear", "Clear"],
["wrap", "Soft-wrap"],
] as const
).map(([operation, title]) => ({
id: `plugins.log.${operation}`,
title,
category: "Plugins",
hidden: true,
run: ({ arg }: { arg?: unknown }) => target(arg)?.[operation](),
})),
{
id: "plugins.log.toggleArgument",
title: "Toggle Log Option",
category: "Plugins",
hidden: true,
run: ({ arg }) => {
const m = arg as { target?: string; id?: string; checked?: boolean } | undefined;
if (m && typeof m.id === "string" && typeof m.checked === "boolean") target(m.target)?.toggle(m.id, m.checked);
},
},
]);
}