Files
openidea/src/editor/core/codeVision.ts
T
Bert Verhelstandbertyhell 2f68c83bcd feat(editor): a Code Vision switch, toggle action and hint menu (#3815)
Code Vision could only be turned off one kind at a time. A master setting, editor.inlay.codeVision (Editor › Inlay Hints › Code Vision › Show Code Vision, on by default), hides usages, author and language-server lenses while keeping the per-kind choices; a Code Vision toggle action (editor.toggleCodeVision, no default shortcut) flips it; and a right-click on a hint offers Hide Usages / Hide Code Author for that hint, Hide Code Vision and Code Vision Settings…. Code Vision is kept untranslated as a product name in the catalog checks.

Closes #3785

Co-authored-by: bertyhell <1710840+bertyhell@users.noreply.github.com>
2026-11-17 02:36:56 +08:00

45 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** Code Vision switches (Settings › Editor › Inlay Hints › Code Vision) shared by its action and its rows' menu. */
import { executeAction } from "@/platform/actions";
import { editorPrefs } from "@/platform/editorSettings";
import { call, commands } from "@/platform/ipc";
import { useProject } from "@/platform/project";
import { notifications } from "@/workbench/contributions";
import type { MenuItem } from "@/ui";
type CodeVisionKey = "codeVision" | "codeVisionUsages" | "codeVisionAuthor";
export async function setCodeVisionSetting(key: CodeVisionKey, on: boolean): Promise<void> {
try {
useProject.setState({
settings: await call(commands.settingsSet("global", `editor.inlay.${key}`, JSON.stringify(on))),
});
} catch (e) {
notifications().notify({
level: "error",
title: "Cannot change the setting",
body: e instanceof Error ? e.message : String(e),
});
}
}
export const codeVisionShown = (): boolean => editorPrefs().inlay.codeVision;
/** Shows or hides every Code Vision row and hint at once, keeping the per-kind choices. */
export const toggleCodeVision = (): Promise<void> => setCodeVisionSetting("codeVision", !codeVisionShown());
/** Right-click on a Code Vision hint (IDEA's code vision context menu). `kind` is the clicked hint's `CodeLens.kind`. */
export function codeVisionMenuItems(kind: string | undefined): MenuItem[] {
const own: MenuItem[] =
kind === "usages"
? [{ label: "Hide Usages", run: () => void setCodeVisionSetting("codeVisionUsages", false) }]
: kind === "author"
? [{ label: "Hide Code Author", run: () => void setCodeVisionSetting("codeVisionAuthor", false) }]
: [];
return [
...own,
{ label: "Hide Code Vision", run: () => void setCodeVisionSetting("codeVision", false) },
{ kind: "separator" },
{ label: "Code Vision Settings…", run: () => void executeAction("file.settings", "editor.inlayHints") },
];
}