mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
Javadoc, KDoc, JSDoc, rustdoc and other /** and /// comments can be drawn in place as formatted documentation and switched back to source: globally (Settings › Editor › General › Appearance › Render documentation comments, off by default), per file (View › Active Editor › Render Documentation Comments, gutter menu, editor.toggleRenderedDocs) and per comment (gutter icon on hover, editor.toggleRenderedView at the caret). Comments are rescanned only once typing pauses and the Markdown renderer loads on first use. Co-authored-by: Clarence404 <36807519+Clarence404@users.noreply.github.com>
53 lines
2.6 KiB
TypeScript
53 lines
2.6 KiB
TypeScript
/** The line-number gutter's context menu, IDEA's EditorGutterPopupMenu. */
|
|
import { executeAction } from "@/platform/actions";
|
|
import { editorPrefs } from "@/platform/editorSettings";
|
|
import { call, commands } from "@/platform/ipc";
|
|
import { useProject } from "@/platform/project";
|
|
import { menuGroupItems } from "@/workbench/contributions";
|
|
import type { MenuItem } from "@/ui";
|
|
import type { EditorSlot } from "./model/slot";
|
|
|
|
/** Whether a right-click on `target` belongs to the gutter menu (contributed gutters with their own menu handle theirs). */
|
|
export function inGutterMenuArea(target: EventTarget | null): boolean {
|
|
const t = target as HTMLElement | null;
|
|
return !!t?.closest?.(".cm-gutters") && !t.closest(".cm-vcs-blame");
|
|
}
|
|
|
|
async function setEditorSetting(key: string, value: unknown) {
|
|
useProject.setState({ settings: await call(commands.settingsSet("global", `editor.${key}`, JSON.stringify(value))) });
|
|
}
|
|
|
|
function toggle(label: string, key: string, on: boolean): MenuItem {
|
|
return { label, checked: on, run: () => void setEditorSetting(key, !on) };
|
|
}
|
|
|
|
function appearanceItems(): MenuItem[] {
|
|
const p = editorPrefs();
|
|
const whitespace = !!useProject.getState().settings?.editor?.showWhitespace;
|
|
return [
|
|
toggle("Show Line Numbers", "appearance.lineNumbers", p.appearance.lineNumbers),
|
|
toggle("Show Gutter Icons", "showGutterIcons", p.showGutterIcons),
|
|
toggle("Show Folding Outline", "folding.showOutline", p.folding.showOutline),
|
|
toggle("Show Indent Guides", "appearance.indentGuides", p.appearance.indentGuides),
|
|
toggle("Show Whitespaces", "showWhitespace", whitespace),
|
|
toggle("Show Method Separators", "appearance.methodSeparators", p.appearance.methodSeparators),
|
|
toggle("Show Breadcrumbs", "breadcrumbs.show", p.breadcrumbs.show),
|
|
];
|
|
}
|
|
|
|
const openSettings = (page: string) => () => void executeAction("file.settings", page);
|
|
|
|
export function gutterMenuItems(slot: EditorSlot, line: number): MenuItem[] {
|
|
const model = slot.model;
|
|
return [
|
|
// Contributed groups (Annotate with Git Blame, bookmarks), each followed by a separator.
|
|
...menuGroupItems("editorGutter", { paths: [model.path], text: slot.currentState().doc.toString(), line }),
|
|
{ label: "Soft-Wrap", checked: model.softWrapOn(), run: () => model.toggleSoftWrap() },
|
|
{ label: "Configure Soft Wraps…", run: openSettings("editor.general") },
|
|
{ label: "Render Documentation Comments", checked: model.renderedDocsOn(), run: () => model.toggleRenderedDocs() },
|
|
{ kind: "separator" },
|
|
{ label: "Appearance", submenu: appearanceItems() },
|
|
{ label: "Configure Gutter Icons…", run: openSettings("editor.general.gutterIcons") },
|
|
];
|
|
}
|