diff --git a/src/features/plugins/__tests__/plugins.test.tsx b/src/features/plugins/__tests__/plugins.test.tsx index c880f4969..f8ecfbeaf 100644 --- a/src/features/plugins/__tests__/plugins.test.tsx +++ b/src/features/plugins/__tests__/plugins.test.tsx @@ -1039,6 +1039,31 @@ describe("secrets", () => { }); describe("plugin line markers", () => { + it("groups related destinations on one line without hiding targets or run actions", () => { + const doc = EditorState.create({ doc: "class Post extends Model {}" }).doc; + const location = (path: string) => ({ path, range: { start: { line: 0, col: 0 }, end: { line: 0, col: 4 } } }); + const marker = (path: string, icon: string | null = "navigate", pluginId = "laravel") => ({ + pluginId, + line: 0, + icon, + tooltip: path, + target: location(path), + }); + const placed = placeMarkers(doc, [ + marker("/project/create_posts.php"), + marker("/project/PostFactory.php"), + marker("/project/PostFactory.php", null, "another-plugin"), + marker("/project/PostPolicy.php"), + marker("/project/run.php", "run"), + ]); + expect(placed).toHaveLength(2); + expect(placed[0]!.markers.map((entry) => entry.target?.path)).toEqual([ + "/project/create_posts.php", + "/project/PostFactory.php", + "/project/PostPolicy.php", + ]); + expect(placed[1]!.icon).toBe("gutter-run"); + }); it("places markers on existing lines and maps their icons", () => { const doc = EditorState.create({ doc: "a\nbb\nccc" }).doc; const marker = (line: number, icon: string | null) => ({ pluginId: "m", line, icon, tooltip: "t", target: null }); @@ -1046,8 +1071,8 @@ describe("plugin line markers", () => { expect(markerIcon("database")).toBe("database"); expect(markerIcon("run")).toBe("gutter-run"); expect(markerIcon("implemented")).toBe("gutter-implemented"); - expect(markerIcon(null)).toBe("gutter-implementing"); - expect(markerIcon("unknown")).toBe("gutter-implementing"); + expect(markerIcon(null)).toBe("gutter-navigate"); + expect(markerIcon("unknown")).toBe("gutter-navigate"); }); }); diff --git a/src/features/plugins/lineMarkerGutter.ts b/src/features/plugins/lineMarkerGutter.ts index 0ff26e462..5f204fbb5 100644 --- a/src/features/plugins/lineMarkerGutter.ts +++ b/src/features/plugins/lineMarkerGutter.ts @@ -8,6 +8,7 @@ import { Compartment, RangeSet, StateEffect, StateField, type Extension, type Te import { EditorView, GutterMarker, ViewPlugin, gutter, type ViewUpdate } from "@codemirror/view"; import { shownAgain, type EditorDocContext } from "@/editor/api"; import { navigationButton } from "./navigationButton"; +import { tx } from "@/platform/i18n"; import { pluginsBackend } from "./backend"; import { commands, type LineMarkerInfo } from "@/platform/ipc"; import { gutterIconMarkup, isIconName } from "@/ui/icons"; @@ -22,7 +23,7 @@ const ICONS: Record = { overridden: "gutter-overridden", overriding: "gutter-overriding", run: "gutter-run", - navigate: "gutter-implementing", + navigate: "gutter-navigate", }; /** Legacy aliases and ordinary registered icon names; navigate when unknown. */ @@ -32,10 +33,30 @@ export function markerIcon(icon: string | null): string { } interface Placed { - marker: LineMarkerInfo; + markers: LineMarkerInfo[]; + icon: string; pos: number; } +function targetKey(marker: LineMarkerInfo): string { + const target = marker.target; + return target + ? JSON.stringify([ + target.path, + target.range.start.line, + target.range.start.col, + target.range.end.line, + target.range.end.col, + ]) + : JSON.stringify([marker.pluginId, marker.tooltip]); +} + +function markerTooltip(markers: readonly LineMarkerInfo[]): string { + const descriptions = [...new Set(markers.map((marker) => marker.tooltip).filter(Boolean))]; + if (markers.length === 1) return descriptions[0] ?? ""; + return [`${tx("Related targets")} (${markers.length})`, ...descriptions.slice(0, 5)].join("\n"); +} + const setMarkers = StateEffect.define(); const markersField = StateField.define({ @@ -47,31 +68,50 @@ const markersField = StateField.define({ }, }); -/** Markers on existing lines, at their line starts. */ +/** One marker per line and resolved icon, retaining all distinct destinations. */ export function placeMarkers(doc: Text, markers: readonly LineMarkerInfo[]): Placed[] { - return markers.filter((m) => m.line < doc.lines).map((marker) => ({ marker, pos: doc.line(marker.line + 1).from })); + const groups = new Map }>(); + for (const marker of markers) { + if (!Number.isInteger(marker.line) || marker.line < 0 || marker.line >= doc.lines) continue; + const icon = markerIcon(marker.icon); + const key = `${marker.line}:${icon}`; + let group = groups.get(key); + if (!group) { + group = { placed: { markers: [], icon, pos: doc.line(marker.line + 1).from }, seen: new Set() }; + groups.set(key, group); + } + const target = targetKey(marker); + if (!group.seen.has(target)) { + group.seen.add(target); + group.placed.markers.push(marker); + } + } + return [...groups.values()].map(({ placed }) => placed); } class PluginMarker extends GutterMarker { - constructor(readonly marker: LineMarkerInfo) { + constructor(readonly placed: Placed) { super(); } override eq(other: GutterMarker): boolean { return ( other instanceof PluginMarker && - other.marker.tooltip === this.marker.tooltip && - other.marker.icon === this.marker.icon && - JSON.stringify(other.marker.target) === JSON.stringify(this.marker.target) + other.placed.icon === this.placed.icon && + other.placed.markers.length === this.placed.markers.length && + other.placed.markers.every((marker, index) => { + const current = this.placed.markers[index]!; + return marker.tooltip === current.tooltip && targetKey(marker) === targetKey(current); + }) ); } override toDOM(): Node { - const el = this.marker.target - ? navigationButton([this.marker.target], markerIcon(this.marker.icon)) - : document.createElement("span"); + const targets = this.placed.markers.flatMap((marker) => (marker.target ? [marker.target] : [])); + const tooltip = markerTooltip(this.placed.markers); + const el = targets.length ? navigationButton(targets, this.placed.icon, tooltip) : document.createElement("span"); el.className = `${styles.marker} cm-plugin-mapping-button`; - el.title = this.marker.tooltip; - el.setAttribute("aria-label", this.marker.tooltip); - el.innerHTML = gutterIconMarkup(markerIcon(this.marker.icon)) ?? ""; + el.title = tooltip; + el.setAttribute("aria-label", tooltip); + el.innerHTML = gutterIconMarkup(this.placed.icon) ?? ""; return el; } } @@ -156,7 +196,7 @@ const markerColumn: Extension = gutter({ class: `${styles.gutter} cm-openidea-gutter-pluginMarkers`, markers: (view) => RangeSet.of( - view.state.field(markersField).map((m) => new PluginMarker(m.marker).range(m.pos)), + view.state.field(markersField).map((m) => new PluginMarker(m).range(m.pos)), true, ), }); diff --git a/src/features/plugins/markerIcons.test.ts b/src/features/plugins/markerIcons.test.ts index f09b1e37b..2d288856b 100644 --- a/src/features/plugins/markerIcons.test.ts +++ b/src/features/plugins/markerIcons.test.ts @@ -29,10 +29,11 @@ it("resolves declared package paths within their plugin and uses the dark SVG", it("retains built-in names, legacy aliases and unknown-icon fallback", async () => { expect(markerIcon(await resolveMarkerIcon("p", "database"))).toBe("database"); expect(markerIcon("overriding")).toBe("gutter-overriding"); - expect(markerIcon("not-an-icon")).toBe("gutter-implementing"); - expect(markerIcon("__proto__")).toBe("gutter-implementing"); - expect(markerIcon("constructor")).toBe("gutter-implementing"); - expect(markerIcon(null)).toBe("gutter-implementing"); + expect(markerIcon("implementing")).toBe("gutter-implementing"); + expect(markerIcon("not-an-icon")).toBe("gutter-navigate"); + expect(markerIcon("__proto__")).toBe("gutter-navigate"); + expect(markerIcon("constructor")).toBe("gutter-navigate"); + expect(markerIcon(null)).toBe("gutter-navigate"); expect(mocks.assets).not.toHaveBeenCalled(); }); @@ -65,7 +66,7 @@ it("falls back when an asset fails to load", async () => { mocks.assets.mockRejectedValue(new Error("disabled")); const remove = projectMarkerIcon("p", { id: "resource", icon: "icons/resource.svg" }); try { - expect(markerIcon(await resolveMarkerIcon("p", "icons/resource.svg"))).toBe("gutter-implementing"); + expect(markerIcon(await resolveMarkerIcon("p", "icons/resource.svg"))).toBe("gutter-navigate"); } finally { remove(); warning.mockRestore(); diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index a93ebbaf4..b468ea7cb 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -1,4 +1,5 @@ { + "Related targets": "Related targets", "GDB (C, C++)": "GDB (C, C++)", "Unknown error": "Unknown error", "Retry Loading Conversation": "Retry Loading Conversation", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index bbafabf9d..f9933b1c3 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -1,4 +1,5 @@ { + "Related targets": "相关目标", "GDB (C, C++)": "GDB(C、C++)", "Unknown error": "未知错误", "Retry Loading Conversation": "重新加载对话", diff --git a/src/ui/icons.tsx b/src/ui/icons.tsx index 16240c08c..cea5d3225 100644 --- a/src/ui/icons.tsx +++ b/src/ui/icons.tsx @@ -392,6 +392,7 @@ const ICONS = { "toolwindow-coverage": "toolwindows/coverage", "toolwindow-profiler": "toolwindows/profiler", "toolwindow-logcat": "openidea/fileTypes/log", + "gutter-navigate": "general/autoscrollToSource", "gutter-run": "gutter/run", "gutter-run-all": "actions/runAll", "gutter-run-passed": "gutter/runSuccess",