Compare commits

...
3 changed files with 158 additions and 58 deletions

No files matched your search

+98
View File
@@ -0,0 +1,98 @@
import type { EditorView } from "@codemirror/view";
import { expect, stubDesktop, test } from "./fixtures";
test("Hierarchy keeps source context and controls reachable in a narrow dock", async ({ workbench: page }) => {
await page.setViewportSize({ width: 940, height: 680 });
const path = "/dev/acme-api/QuarterlySettlementReconciliationCoordinator.ts";
const caller = "reconcileQuarterlySettlementForMerchantOrders";
const context = "Checkout and settlement coordinator";
await page.evaluate(
async ({ path, caller }) => {
const backend = "/src/editor/core/backend.ts";
const { docBackend } = await import(/* @vite-ignore */ backend);
docBackend().files.set(
path,
[
"function settleOrder() {}",
"",
`function ${caller}() {`,
" settleOrder();",
" settleOrder();",
"}",
`function flushSettlementQueue() { ${caller}(); }`,
].join("\n"),
);
const service = "/src/workbench/contributions.ts";
await (await import(/* @vite-ignore */ service)).editorService().openFile(path);
},
{ path, caller },
);
const editor = page.locator(".cm-content");
await expect(editor).toContainText("settleOrder");
await editor.evaluate((el) => {
const view = (el as HTMLElement & { cmTile: { view: EditorView } }).cmTile.view;
view.dispatch({ selection: { anchor: 11 } });
view.focus();
});
await stubDesktop(page);
await page.evaluate(
async ({ path, caller, context }) => {
const range = (line: number, col: number) => ({ start: { line, col }, end: { line, col: col + 5 } });
const item = (name: string, line: number, detail: string, fromRanges: ReturnType<typeof range>[]) => ({
name,
path,
detail,
kind: "function",
range: range(line, 0),
selectionRange: range(line, 9),
fromRanges,
});
window.__ipc.handlers.lsp_call_hierarchy = ({ pos }) => {
const line = (pos as { line: number }).line;
return {
items:
line === 0
? [item(caller, 2, context, [range(3, 2), range(4, 2)])]
: [item("flushSettlementQueue", 6, "Queue processing", [range(6, 34)])],
incomplete: null,
};
};
const actions = "/src/platform/actions.ts";
await (await import(/* @vite-ignore */ actions)).executeAction("navigate.callHierarchy");
const dock = "/src/workbench/toolwindows/store.ts";
(await import(/* @vite-ignore */ dock)).setToolWindowSize("right", 136);
},
{ path, caller, context },
);
const tree = page.getByRole("tree", { name: "Call hierarchy" });
const row = tree.getByRole("treeitem").filter({ hasText: caller });
await expect(row).toBeVisible();
const detail = row.getByText(context, { exact: true });
await expect.poll(() => detail.evaluate((el) => el.clientWidth)).toBeGreaterThan(100);
expect((await row.getByText("(2 calls)", { exact: true }).boundingBox())!.x).toBeLessThan(
(await detail.boundingBox())!.x,
);
const toolbar = page.getByRole("toolbar", { name: "Hierarchy actions" });
expect(await toolbar.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
await tree.evaluate((el) => {
el.scrollLeft = el.scrollWidth;
});
expect(await tree.evaluate((el) => el.scrollLeft)).toBeGreaterThan(100);
await tree.evaluate((el) => {
el.scrollLeft = 0;
});
await row.click({ position: { x: 90, y: 12 } });
await page.keyboard.press("ArrowRight");
await expect(tree.getByRole("treeitem").filter({ hasText: "flushSettlementQueue" })).toBeVisible();
await page.keyboard.press("Enter");
await expect
.poll(() =>
page.evaluate(async () => {
const service = "/src/workbench/contributions.ts";
const cursor = (await import(/* @vite-ignore */ service)).editorService().activeCursor();
return { path: cursor?.path, line: cursor?.line, col: cursor?.col };
}),
)
.toEqual({ path, line: 3, col: 2 });
});
@@ -10,18 +10,18 @@
background: none;
}
.toolbar {
height: 32px;
min-height: var(--h-header);
flex: none;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--space-0-5) var(--space-2);
padding: var(--space-0-5) var(--space-1-5);
}
.toolbarGroup {
display: flex;
align-items: center;
gap: var(--space-0-5);
padding: 0 6px;
}
.sep {
width: 1px;
height: 16px;
margin: 0 4px;
background: var(--border);
}
.note {
flex: none;
@@ -29,6 +29,7 @@
font-size: var(--fs-small);
font-style: italic;
color: var(--fg-subtle);
overflow-wrap: anywhere;
}
.body {
flex: 1;
@@ -49,17 +50,12 @@
white-space: nowrap;
}
.name {
color: var(--fg);
}
.detail {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
color: var(--fg-subtle);
color: var(--fg-strong);
}
.muted {
flex: none;
color: var(--fg-subtle);
font-size: var(--fs-small);
}
.error {
flex: none;
+49 -43
View File
@@ -106,35 +106,37 @@ function HierarchyToolbar() {
const autoscroll = useHierarchyOptions((s) => s.autoscroll);
return (
<div className={styles.toolbar} role="toolbar" aria-label={tx("Hierarchy actions")}>
<IconButton
icon="arrow-up"
size="small"
iconSize={16}
title={tx`${directionLabel(mode, "incoming")} Hierarchy`}
pressed={direction === "incoming"}
onClick={() => setDirection("incoming")}
/>
<IconButton
icon="arrow-down"
size="small"
iconSize={16}
title={tx`${directionLabel(mode, "outgoing")} Hierarchy`}
pressed={direction === "outgoing"}
onClick={() => setDirection("outgoing")}
/>
<span className={styles.sep} />
<div className={styles.toolbarGroup}>
<IconButton
icon="arrow-up"
size="small"
iconSize={16}
title={tx`${directionLabel(mode, "incoming")} Hierarchy`}
pressed={direction === "incoming"}
onClick={() => setDirection("incoming")}
/>
<IconButton
icon="arrow-down"
size="small"
iconSize={16}
title={tx`${directionLabel(mode, "outgoing")} Hierarchy`}
pressed={direction === "outgoing"}
onClick={() => setDirection("outgoing")}
/>
</div>
<IconButton icon="refresh" size="small" iconSize={16} title="Refresh" onClick={refreshHierarchy} />
<span className={styles.sep} />
<IconButton icon="arrow-up" action="navigate.prevOccurrence" size="small" iconSize={16} />
<IconButton icon="arrow-down" action="navigate.nextOccurrence" size="small" iconSize={16} />
<IconButton
icon="autoscroll-to-source"
size="small"
iconSize={16}
title="Autoscroll to Source"
pressed={autoscroll}
onClick={() => useHierarchyOptions.setState({ autoscroll: !autoscroll })}
/>
<div className={styles.toolbarGroup}>
<IconButton icon="arrow-up" action="navigate.prevOccurrence" size="small" iconSize={16} />
<IconButton icon="arrow-down" action="navigate.nextOccurrence" size="small" iconSize={16} />
<IconButton
icon="autoscroll-to-source"
size="small"
iconSize={16}
title="Autoscroll to Source"
pressed={autoscroll}
onClick={() => useHierarchyOptions.setState({ autoscroll: !autoscroll })}
/>
</div>
</div>
);
}
@@ -183,13 +185,9 @@ export function HierarchyView() {
const renderNode = (n: Node, _state: TreeRowState) => {
if (n.kind === "root") {
return (
<span className={styles.row}>
<span className={styles.row} title={`${root.name}\n${relativePath(projectRoot, root.path)}:${root.line + 1}`}>
<SymbolBadge kind={mode === "call" ? "function" : "class"} />
<span className={styles.name}>{root.name}</span>
{root.detail && <span className={styles.detail}>{root.detail}</span>}
<span className={styles.muted}>
{basename(root.path)}:{root.line + 1}
</span>
{loading && <Spinner size={12} />}
{failed.has(ROOT_ID) && (
<span className={styles.error}>
@@ -199,35 +197,42 @@ export function HierarchyView() {
{!loading && !failed.has(ROOT_ID) && children.get(ROOT_ID)?.length === 0 && (
<span className={styles.muted}>{noneFoundLabel(mode, direction)}</span>
)}
{root.detail && <span className={styles.muted}>{root.detail}</span>}
<span className={styles.muted}>
{basename(root.path)}:{root.line + 1}
</span>
</span>
);
}
const { item } = n.node;
const calls = item.fromRanges.length;
return (
<span className={styles.row} title={relativePath(projectRoot, item.path)}>
<span
className={styles.row}
title={`${item.name}\n${relativePath(projectRoot, item.path)}:${item.selectionRange.start.line + 1}`}
>
<SymbolBadge kind={badgeKind(item.kind)} />
<span className={styles.name}>{item.name}</span>
{item.detail && <span className={styles.detail}>{item.detail}</span>}
<span className={styles.muted}>
{basename(item.path)}:{item.selectionRange.start.line + 1}
</span>
{calls > 1 && <span className={styles.muted}>{tx`(${calls} calls)`}</span>}
{n.node.recursion && (
<span className={styles.muted}>
<T>recursive</T>
</span>
)}
{notes.has(n.id) && (
<span className={styles.muted} title={notes.get(n.id)}>
{notes.get(n.id)}
</span>
)}
{failed.has(n.id) && (
<span className={styles.error}>
<T>failed to load</T>
</span>
)}
{item.detail && <span className={styles.muted}>{item.detail}</span>}
<span className={styles.muted}>
{basename(item.path)}:{item.selectionRange.start.line + 1}
</span>
{notes.has(n.id) && (
<span className={styles.muted} title={notes.get(n.id)}>
{notes.get(n.id)}
</span>
)}
</span>
);
};
@@ -244,6 +249,7 @@ export function HierarchyView() {
<Tree<Node>
key={generation}
aria-label={mode === "call" ? "Call hierarchy" : "Type hierarchy"}
horizontalScroll
roots={roots}
getKey={(n) => n.id}
getLabel={(n) => (n.kind === "root" ? root.name : n.node.item.name)}