feat(dart): show closing labels at the end of the line (#5766)

Dart files show closing labels after a widget's or call's closing bracket at the end of the line (`), // Column`), from the Dart server's dart/textDocument/publishClosingLabels, now requested at initialization. They are inlay hints of a new closingLabel kind, kept per document and server instance, dropped on the next edit until the server publishes again; several labels closing on one line share one hint. Editor › Inlay Hints › Closing labels (on by default) turns them off. Right-click Disable now writes the kind's own setting (it wrote inlay.type instead of inlay.types for type hints).

Part of #4096

Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
LU XIANGRUIтаwildcatDownstairs authored and GitHub committed 2026-11-25 13:59:24 +08:00
1 джерело 6355534ed5
коміт 2544db3025
15 files changed
+272 -8

No files matched your search

+31
Переглянути файл
@@ -12,6 +12,7 @@ vi.mock("@/workbench/contributions", async (orig) => {
});
const ipc = vi.hoisted(() => ({
lspInlayHints: vi.fn(),
settingsSet: vi.fn(),
}));
vi.mock("@/platform/ipc", async (orig) => {
const real = await orig<typeof import("@/platform/ipc")>();
@@ -24,6 +25,7 @@ const { usePlatform } = await import("@/platform/platformInfo");
const { resetNavigationModifier } = await import("@/platform/navigationModifier");
const { useContextMenuStore } = await import("@/ui");
const { emitLocalIdeEvent } = await import("@/platform/ipc");
const { useProject } = await import("@/platform/project");
const hint: InlayHint = {
position: { line: 0, col: 5 },
@@ -125,6 +127,25 @@ describe("background inlay hints", () => {
expect(shown(view)).toBe(0);
});
it("shows closing labels at the end of the line unless they are turned off", async () => {
const closing: InlayHint = {
...hint,
kind: "closingLabel",
label: "// foo",
position: { line: 0, col: 14 },
parts: [],
};
ipc.lspInlayHints.mockResolvedValue(ok([hint, closing]));
const view = editor();
await afterPass();
expect(view.dom.querySelector(".cm-lsp-inlay-closingLabel")?.textContent).toBe("// foo");
useProject.setState({ settings: { editor: { inlay: { closingLabels: false } } } as never });
await afterPass();
expect(shown(view)).toBe(1);
expect(view.dom.querySelector(".cm-lsp-inlay-closingLabel")).toBeNull();
useProject.setState({ settings: null });
});
it("clears the hints of a server that is down and not coming back", async () => {
ipc.lspInlayHints.mockResolvedValue(ok([hint]));
const view = editor();
@@ -178,6 +199,16 @@ describe("inlay hints", () => {
expect((inlayMenuItems("parameter")[0] as { label: string }).label).toBe("Disable Parameter name hints");
});
it.each([
["type", "types"],
["closingLabel", "closingLabels"],
] as const)("turns %s hints off with the editor.inlay.%s setting", async (kind, key) => {
ipc.settingsSet.mockResolvedValue(ok({}));
const disable = inlayMenuItems(kind)[0] as { run: () => void };
disable.run();
await vi.waitFor(() => expect(ipc.settingsSet).toHaveBeenCalledWith("global", `editor.inlay.${key}`, "false"));
});
it("uses type declaration navigation for a plain type hint after an identifier", () => {
usePlatform.setState({ os: "macos" });
const view = editorWith([{ ...hint, label: ": Foo", parts: [] }]);
+15 -6
Переглянути файл
@@ -23,8 +23,17 @@ const KIND_LABEL: Record<InlayHint["kind"], string> = {
type: "Type hints",
parameter: "Parameter name hints",
other: "Other hints",
closingLabel: "Closing labels",
};
/** The `editor.inlay.*` switch for each kind. */
const KIND_SETTING = {
type: "types",
parameter: "parameters",
other: "other",
closingLabel: "closingLabels",
} as const satisfies Record<InlayHint["kind"], string>;
async function setEditorSetting(key: string, value: unknown) {
if (!isTauri()) return;
useProject.setState({ settings: await call(commands.settingsSet("global", `editor.${key}`, JSON.stringify(value))) });
@@ -42,7 +51,10 @@ function typeHintOffset(view: EditorView, at: number): number | null {
/** Right-click on a hint: turn its kind off (IDEA's "Disable '…' hints"), or open the settings. */
export function inlayMenuItems(kind: InlayHint["kind"]): MenuItem[] {
return [
{ label: tx`Disable ${txPart(KIND_LABEL[kind])}`, run: () => void setEditorSetting(`inlay.${kind}`, false) },
{
label: tx`Disable ${txPart(KIND_LABEL[kind])}`,
run: () => void setEditorSetting(`inlay.${KIND_SETTING[kind]}`, false),
},
{ kind: "separator" },
{ label: "Inlay Hints Settings…", run: () => void executeAction("file.settings", "editor.inlayHints") },
];
@@ -147,11 +159,8 @@ const enabled = (language: string) =>
useProject.getState().settings?.editor?.inlayHints !== false &&
!editorPrefs().inlay.disabledLanguages.includes(language);
/** Inlay Hints settings: per kind (types / parameters / other). */
function shownKind(kind: InlayHint["kind"]): boolean {
const p = editorPrefs().inlay;
return kind === "type" ? p.types : kind === "parameter" ? p.parameters : p.other;
}
/** Inlay Hints settings: per kind (types / parameters / other / closing labels). */
const shownKind = (kind: InlayHint["kind"]): boolean => editorPrefs().inlay[KIND_SETTING[kind]];
const inlayPlugin = ViewPlugin.fromClass(
class {