Compare commits

..
Author SHA1 Message Date
l0ng-ai 33614e81ef fix(debugger): give Memory class filtering room 2026-11-23 09:06:15 +08:00
7 changed files with 180 additions and 175 deletions

No files matched your search

-71
View File
@@ -1,71 +0,0 @@
import type { Page } from "@playwright/test";
import { expect, test } from "./fixtures";
async function show(page: Page, action: string) {
await page.evaluate(async (action) => {
const actions = "/src/platform/actions.ts";
if (!(await (await import(/* @vite-ignore */ actions)).executeAction(action))) throw Error(action);
}, action);
}
test("analysis scope fields align with their radio choices and retain their values", async ({ workbench: page }) => {
await page.evaluate(async () => {
const search = "/src/platform/search.ts";
(await import(/* @vite-ignore */ search)).saveCustomScopes([
{ name: "Frontend", pattern: "file:src//*" },
{ name: "Tests", pattern: "file:tests//*" },
]);
});
await show(page, "analyze.inspectCode");
const dialog = page.getByRole("dialog", { name: "Specify Inspection Scope" });
const scope = dialog.getByRole("group", { name: "Scope" });
const directory = scope.getByRole("textbox", { name: "Directory" });
const custom = scope.getByRole("button", { name: "Custom scope", exact: true });
const radio = scope.getByRole("radio", { name: "Module or directory" });
const label = scope.getByText("Module or directory", { exact: true });
await radio.check();
const path = (await directory.boundingBox())!;
const choice = (await label.boundingBox())!;
expect(path.y + path.height / 2).toBeCloseTo(choice.y + choice.height / 2, 0);
await directory.fill("/dev/acme-api/src");
await expect(custom).toBeDisabled();
await scope.getByRole("radio", { name: "Custom scope", exact: true }).check();
await expect(directory).toBeDisabled();
expect((await custom.boundingBox())!.x).toBeCloseTo(path.x, 0);
await custom.click();
await page.getByRole("option", { name: /^Tests/ }).click();
await expect(custom).toContainText("Tests");
await radio.check();
await expect(directory).toHaveValue("/dev/acme-api/src");
await scope.getByRole("radio", { name: "Custom scope", exact: true }).check();
await expect(custom).toContainText("Tests");
await page.setViewportSize({ width: 400, height: 640 });
const stacked = (await directory.boundingBox())!;
const customBox = (await custom.boundingBox())!;
const radioBox = (await label.boundingBox())!;
const next = (await scope.getByText("Current file", { exact: true }).boundingBox())!;
expect(stacked.y).toBeGreaterThan(radioBox.y + radioBox.height);
expect(stacked.y + stacked.height).toBeLessThan(next.y);
expect(stacked.x).toBeCloseTo(customBox.x, 0);
expect(await scope.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
});
for (const [action, title] of [
["code.cleanup", "Run Code Cleanup"],
["analyze.locateDuplicates", "Locate Duplicates"],
["find.structural", "Structural Search"],
["find.replaceStructural", "Structural Replace"],
] as const) {
test(`${title} keeps directory options with their scope choice`, async ({ workbench: page }) => {
await show(page, action);
const dialog = page.getByRole("dialog", { name: title });
const scope = dialog.getByRole("group", { name: "Scope" });
const directory = scope.getByRole("textbox", { name: "Directory" });
await expect(directory).toBeDisabled();
await scope.getByRole("radio", { name: "Module or directory" }).check();
await expect(directory).toBeEnabled();
await expect(scope.getByRole("button", { name: "Browse…" })).toBeEnabled();
});
}
+78
View File
@@ -3,6 +3,7 @@
* with its frames and variables, and stepping and resuming go back to the adapter. The adapter is
* stubbed at the IPC layer; `crates/ide-dap/tests` drives real ones.
*/
import type { JvmMemoryResult } from "../src/platform/ipc";
import { expect, ipcCalls, openFromTree, stubDesktop, test } from "./fixtures";
const ROOT = "/dev/acme-api";
@@ -114,6 +115,83 @@ test("stops at a breakpoint, shows frames and variables, steps and resumes", asy
await expect(debug.getByText("CreateOrderRequest(sku='A-1', qty=2)")).toBeHidden();
});
test("Memory gives class filtering the available toolbar width and exposes changed-only filtering", async ({
workbench: page,
}) => {
const rows = [
{ name: "OrderCache", instances: 64, deltaInstances: 12 },
{ name: "OrderRepository", instances: 16, deltaInstances: 0 },
].map((row) => ({ ...row, bytes: row.instances * 16, deltaBytes: null, module: null, ambiguous: false }));
const result: JvmMemoryResult = {
status: "ready",
snapshot: {
rows,
totalInstances: 80,
totalBytes: 1280,
javaVersion: "21",
takenWhileSuspended: true,
hasBaseline: true,
elapsedMs: 5,
source: "debugger",
},
};
await stubDesktop(page);
await page.evaluate(
async ({ result, id }) => {
const caps = { jvmMemory: true, jvmHeap: true };
window.__ipc.handlers.debug_capabilities = () => caps;
window.__ipc.handlers.debug_jvm_memory_classes = () => result;
const debugPath = "/src/features/debugger/state.ts";
const { adoptSession } = await import(/* @vite-ignore */ debugPath);
adoptSession(id, { adapter: "java-debug", name: "Billing Service", status: "paused", caps });
const dockPath = "/src/workbench/toolwindows/store.ts";
const layout = await import(/* @vite-ignore */ dockPath);
layout.moveToolWindow("debug", "bottom");
layout.setToolWindowSize("bottom", 300);
layout.showToolWindow("debug", true);
},
{ result, id: SESSION },
);
const debug = page.getByRole("region", { name: "Debug", exact: true });
await debug.getByRole("tab", { name: "Memory" }).click();
const toolbar = debug.getByRole("toolbar", { name: "Memory", exact: true });
const filter = toolbar.getByRole("textbox", { name: "Filter classes" });
const options = toolbar.getByRole("button", { name: "View Options" });
const grid = debug.getByRole("grid", { name: "Memory", exact: true });
await expect(grid.getByText("OrderRepository", { exact: true })).toBeVisible();
expect((await filter.boundingBox())!.width).toBeGreaterThan((await toolbar.boundingBox())!.width / 2);
await page.evaluate(async () => {
const dockPath = "/src/workbench/toolwindows/store.ts";
const layout = await import(/* @vite-ignore */ dockPath);
layout.moveToolWindow("debug", "right");
layout.setToolWindowSize("right", 330);
});
await expect.poll(async () => (await toolbar.boundingBox())!.width).toBeCloseTo(330, 0);
const bar = (await toolbar.boundingBox())!;
const gear = (await options.boundingBox())!;
const input = (await filter.boundingBox())!;
expect(input.width).toBeGreaterThan(bar.width / 2);
expect(input.x + input.width).toBeLessThan(gear.x);
expect(gear.x + gear.width).toBeLessThanOrEqual(bar.x + bar.width);
await filter.fill("cache");
await expect(grid.getByText("OrderRepository", { exact: true })).toBeHidden();
await toolbar.getByRole("button", { name: "Clear", exact: true }).click();
await expect(grid.getByText("OrderRepository", { exact: true })).toBeVisible();
await options.press("Enter");
const changed = page.getByRole("menuitemcheckbox", { name: "Changed only" });
await expect(changed).not.toBeChecked();
await changed.press("Enter");
await expect(grid.getByText("OrderRepository", { exact: true })).toBeHidden();
await expect(options).toHaveAttribute("aria-pressed", "true");
await expect(options).toBeFocused();
await options.press("Enter");
await expect(changed).toBeChecked();
});
test("Evaluate keeps a multiline expression and its result visible in a short dialog", async ({ workbench: page }) => {
await page.setViewportSize({ width: 580, height: 420 });
await stubDesktop(page);
+15 -32
View File
@@ -161,51 +161,34 @@
padding: 14px;
}
.scope {
container: analysis-scope / inline-size;
min-inline-size: 0;
display: flex;
flex-direction: column;
gap: var(--space-0-5);
margin: 0;
padding: 0;
border: 0;
}
.scopeOptions {
display: grid;
grid-template-columns: fit-content(45%) minmax(0, 1fr);
align-items: center;
gap: var(--space-0-5) var(--space-2);
}
.fieldLabel {
padding: 0 0 4px;
color: var(--fg-secondary);
font-size: var(--fs-small);
}
.radioRow {
grid-column: 1 / -1;
min-width: 0;
padding-block: var(--space-0-5);
overflow-wrap: anywhere;
}
.scopeWithField {
grid-column: 1;
}
.scopeControl {
grid-column: 2;
display: flex;
align-items: center;
gap: var(--space-2);
padding: 3px 0;
color: var(--fg);
cursor: default;
}
.radioRow input {
margin: 0;
accent-color: var(--accent);
}
.dirRow {
display: flex;
gap: var(--space-1-5);
min-width: 0;
}
.scopeControl > button:last-child {
flex: none;
}
@container analysis-scope (max-width: 336px) {
.scopeOptions {
grid-template-columns: minmax(0, 1fr);
}
.scopeControl {
grid-column: 1;
padding-inline-start: calc(16px + var(--space-2));
margin-block-end: var(--space-1);
}
padding: 4px 0 0 22px;
}
.grow {
flex: 1;
+47 -60
View File
@@ -1,12 +1,11 @@
/** Dialog stack of the analysis feature and the shared "Specify Scope" fields. */
import { Fragment, type ReactNode } from "react";
import clsx from "clsx";
import { create } from "zustand";
import { executeAction } from "@/platform/actions";
import { tx } from "@/platform/i18n";
import { isTauri } from "@/platform/ipc";
import { EDIT_SCOPES_ACTION, useCustomScopeList } from "@/platform/search";
import { Button, IconButton, Input, Radio, Select, T } from "@/ui";
import { Button, IconButton, Input, Select, T } from "@/ui";
import { SCOPE_LABELS, currentFile, type ScopeChoice, type ScopeKind } from "./scope";
import styles from "./Analysis.module.css";
@@ -63,69 +62,57 @@ export function ScopeFields({
}) {
const file = currentFile();
const scopes = useCustomScopeList();
const custom = value.custom ?? scopes[0]?.name;
return (
<fieldset className={styles.scope}>
<legend className={styles.fieldLabel}>
<T>Scope</T>
</legend>
<div className={styles.scopeOptions}>
{kinds.map((kind) => {
const selected = value.kind === kind;
return (
<Fragment key={kind}>
<Radio
name={name}
checked={selected}
disabled={kind === "file" && !file}
onChange={() => onChange({ ...value, kind, custom: kind === "custom" ? custom : value.custom })}
label={
kind === "file" && file ? <span>{tx`File '${file.split("/").pop()}'`}</span> : SCOPE_LABELS[kind]
}
className={clsx(styles.radioRow, (kind === "directory" || kind === "custom") && styles.scopeWithField)}
/>
{kind === "directory" && (
<div className={styles.scopeControl}>
<Input
aria-label="Directory"
value={value.directory}
disabled={!selected}
onChange={(e) => onChange({ ...value, directory: e.target.value })}
className={styles.grow}
/>
<Button
disabled={!selected}
onClick={() =>
void browseDirectory(value.directory).then((d) => d && onChange({ ...value, directory: d }))
}
>
<T>Browse…</T>
</Button>
</div>
)}
{kind === "custom" && (
<div className={styles.scopeControl}>
<Select<string>
className={styles.grow}
value={(selected ? value.custom : custom) ?? null}
options={scopes.map((s) => ({ value: s.name, label: s.name, detail: s.pattern }))}
placeholder={scopes.length ? "Choose a scope" : "No custom scopes"}
disabled={!selected}
onChange={(custom) => onChange({ ...value, custom })}
aria-label="Custom scope"
/>
<IconButton
icon="more-horizontal"
title="Edit Scopes…"
disabled={!selected}
onClick={() => void executeAction(EDIT_SCOPES_ACTION, custom ? { select: custom } : undefined)}
/>
</div>
)}
</Fragment>
);
})}
</div>
{kinds.map((kind) => (
<label key={kind} className={styles.radioRow}>
<input
type="radio"
name={name}
checked={value.kind === kind}
disabled={kind === "file" && !file}
onChange={() =>
onChange({ ...value, kind, custom: kind === "custom" ? (value.custom ?? scopes[0]?.name) : value.custom })
}
/>
<span>{kind === "file" && file ? tx`File '${file.split("/").pop()}'` : tx(SCOPE_LABELS[kind])}</span>
</label>
))}
{value.kind === "directory" && (
<div className={styles.dirRow}>
<Input
aria-label="Directory"
value={value.directory}
onChange={(e) => onChange({ ...value, directory: e.target.value })}
className={styles.grow}
/>
<Button
onClick={() => void browseDirectory(value.directory).then((d) => d && onChange({ ...value, directory: d }))}
>
<T>Browse…</T>
</Button>
</div>
)}
{value.kind === "custom" && (
<div className={styles.dirRow}>
<Select<string>
className={styles.grow}
value={value.custom ?? null}
options={scopes.map((s) => ({ value: s.name, label: s.name, detail: s.pattern }))}
placeholder="No custom scopes"
onChange={(custom) => onChange({ ...value, custom })}
aria-label="Custom scope"
/>
<IconButton
icon="more-horizontal"
title="Edit Scopes…"
onClick={() => void executeAction(EDIT_SCOPES_ACTION, value.custom ? { select: value.custom } : undefined)}
/>
</div>
)}
</fieldset>
);
}
@@ -241,7 +241,8 @@ describe("MemoryView", () => {
expect(screen.getByRole("button", { name: "刷新内存视图" }).getAttribute("data-tooltip")).toBe("刷新内存视图");
const filter = screen.getByRole("textbox", { name: "筛选类" });
expect(filter.getAttribute("placeholder")).toBe("筛选类");
expect(screen.getByRole("checkbox", { name: "仅显示有变化的" })).toBeTruthy();
fireEvent.click(screen.getByRole("button", { name: "视图选项" }));
expect(screen.getByRole("menuitemcheckbox", { name: "仅显示有变化的" })).toBeInTheDocument();
} finally {
await setLocale("en");
}
@@ -299,10 +300,15 @@ describe("MemoryView", () => {
expect(screen.getByText("Cache$Entry")).toBeTruthy();
fireEvent.change(screen.getByRole("textbox", { name: "Filter classes" }), { target: { value: "" } });
fireEvent.click(screen.getByRole("checkbox", { name: "Changed only" }));
const options = screen.getByRole("button", { name: "View Options" });
fireEvent.click(options);
fireEvent.click(screen.getByRole("menuitemcheckbox", { name: "Changed only", checked: false }));
expect(screen.getByText("Heap$Live")).toBeTruthy();
expect(screen.queryByText("Cache$Entry")).toBeNull();
expect(screen.queryByText("Dup")).toBeNull();
expect(options).toHaveAttribute("aria-pressed", "true");
fireEvent.click(options);
expect(screen.getByRole("menuitemcheckbox", { name: "Changed only", checked: true })).toBeInTheDocument();
});
it("sorts by the clicked column and reports it with aria-sort", async () => {
@@ -18,8 +18,8 @@
}
.filter {
flex: 0 1 240px;
min-width: 80px;
flex: 1;
min-width: 0;
}
.banner,
+30 -8
View File
@@ -1,7 +1,7 @@
/** Memory tab of the Debug tool window: live instance counts per class of the debugged JVM, and heap capture. */
import { useEffect, useMemo } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
import clsx from "clsx";
import { Checkbox, Icon, IconButton, Input, List, T } from "@/ui";
import { Icon, IconButton, List, Menu, SearchField, T } from "@/ui";
import { executeAction } from "@/platform/actions";
import { useTx } from "@/platform/i18n";
import type { JvmClassRow, JvmMemorySnapshot } from "@/platform/ipc";
@@ -112,6 +112,8 @@ export function MemoryView({ session }: { session: DebugSession }) {
const id = session.id;
const entry = useMemory((s) => s.bySession[id]);
const query = entry?.query ?? DEFAULT_QUERY;
const optionsButton = useRef<HTMLButtonElement>(null);
const [optionsOpen, setOptionsOpen] = useState(false);
const result = entry?.result ?? null;
const snapshot = entry?.snapshot ?? null;
const source = snapshot?.source ?? "histogram";
@@ -161,17 +163,37 @@ export function MemoryView({ session }: { session: DebugSession }) {
disabled={entry?.loading || !canRefresh}
/>
<HeapCaptureButton session={session} />
<Input
<SearchField
className={styles.filter}
value={query.filter}
onChange={(e) => setMemoryQuery(id, { filter: e.target.value })}
onChange={(filter) => setMemoryQuery(id, { filter })}
placeholder="Filter classes"
aria-label="Filter classes"
/>
<Checkbox
checked={query.changedOnly}
onChange={(changedOnly) => setMemoryQuery(id, { changedOnly })}
label="Changed only"
<IconButton
ref={optionsButton}
icon="settings"
title="View Options"
size="small"
iconSize={16}
pressed={query.changedOnly}
aria-haspopup="menu"
aria-expanded={optionsOpen}
onClick={() => setOptionsOpen(!optionsOpen)}
/>
<Menu
open={optionsOpen}
onClose={() => setOptionsOpen(false)}
anchor={optionsButton}
placement="bottom-end"
aria-label="View Options"
items={[
{
label: "Changed only",
checked: query.changedOnly,
run: () => setMemoryQuery(id, { changedOnly: !query.changedOnly }),
},
]}
/>
</div>
{backend && (