mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-22 23:56:05 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9415584b54 |
No files matched your search
@@ -3,7 +3,6 @@
|
||||
* 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";
|
||||
@@ -115,83 +114,6 @@ 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);
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
import type { Page } from "@playwright/test";
|
||||
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
|
||||
|
||||
async function openTable(page: Page, columns: number) {
|
||||
await stubDesktop(page);
|
||||
await page.evaluate(async (columns) => {
|
||||
window.__ipc.handlers.debug_evaluate_in = ({ expression }) => {
|
||||
const query = String(expression);
|
||||
const sliced = query.includes("totals.iloc[:2, :2]");
|
||||
const visibleColumns = sliced ? 2 : Math.min(30, columns);
|
||||
const columnsInFrame = sliced ? 2 : columns;
|
||||
const start = query.includes("100, 100,") ? 100 : 0;
|
||||
const rows = sliced ? 2 : 220;
|
||||
const count = sliced ? 2 : 100;
|
||||
const result = query.includes("missing_table")
|
||||
? { error: "NameError: missing_table" }
|
||||
: {
|
||||
kind: "frame",
|
||||
shape: [rows, columnsInFrame],
|
||||
rows,
|
||||
columns: columnsInFrame,
|
||||
headers: Array.from({ length: visibleColumns }, (_, i) => `Amount ${i + 1}`),
|
||||
dtypes: Array.from({ length: visibleColumns }, () => "int64"),
|
||||
index: Array.from({ length: count }, (_, i) => String(i + start)),
|
||||
cells: Array.from({ length: count }, (_, row) =>
|
||||
Array.from({ length: visibleColumns }, (_, column) => String((row + start + 1) * 10 + column)),
|
||||
),
|
||||
};
|
||||
return {
|
||||
name: "",
|
||||
value: JSON.stringify(JSON.stringify(result)),
|
||||
typeName: "str",
|
||||
variablesReference: 0,
|
||||
evaluateName: null,
|
||||
};
|
||||
};
|
||||
const stateModule = "/src/features/debugger/state.ts";
|
||||
const overlaysModule = "/src/features/debugger/ui/popoverStore.ts";
|
||||
const { adoptSession } = await import(/* @vite-ignore */ stateModule);
|
||||
const { openTableView } = await import(/* @vite-ignore */ overlaysModule);
|
||||
adoptSession(91, { name: "Settlement review", adapter: "debugpy", status: "paused", selectedFrame: 11 });
|
||||
openTableView("totals", 91);
|
||||
}, columns);
|
||||
const dialog = page.getByRole("dialog", { name: "Table view of totals", exact: true });
|
||||
await expect(dialog.getByRole("table")).toBeVisible();
|
||||
return dialog;
|
||||
}
|
||||
|
||||
test("View as Table gives the grid the dialog width and puts the expression below it", async ({ workbench: page }) => {
|
||||
await page.setViewportSize({ width: 1120, height: 760 });
|
||||
const dialog = await openTable(page, 3);
|
||||
const scroll = dialog.getByRole("region", { name: "Table", exact: true });
|
||||
const grid = dialog.getByRole("table");
|
||||
const expression = dialog.getByRole("textbox", { name: "Expression", exact: true });
|
||||
const shape = dialog.getByText("Shape (220, 3)", { exact: true });
|
||||
const body = (await scroll.boundingBox())!;
|
||||
const input = (await expression.boundingBox())!;
|
||||
expect(input.y).toBeGreaterThan(body.y + body.height);
|
||||
expect((await shape.boundingBox())!.y).toBeLessThan(body.y);
|
||||
expect(Math.abs((await grid.boundingBox())!.width - (await scroll.evaluate((el) => el.clientWidth)))).toBeLessThan(1);
|
||||
expect((await dialog.boundingBox())!.width).toBeCloseTo(700, 0);
|
||||
await expect(expression).toBeFocused();
|
||||
await expect(grid).toHaveCSS("font-family", /Inter/);
|
||||
await expect(grid.getByRole("columnheader").nth(1)).toHaveCSS("text-align", "center");
|
||||
await expect(grid.getByRole("rowheader").first()).toHaveCSS("text-align", "center");
|
||||
await expect(grid.getByRole("cell").first()).toHaveCSS("text-align", /^(start|left)$/);
|
||||
});
|
||||
|
||||
test("View as Table keeps paging, slice input and Close usable in a narrow window", async ({ workbench: page }) => {
|
||||
await page.setViewportSize({ width: 450, height: 620 });
|
||||
const dialog = await openTable(page, 36);
|
||||
const expression = dialog.getByRole("textbox", { name: "Expression", exact: true });
|
||||
const scroll = dialog.getByRole("region", { name: "Table", exact: true });
|
||||
const rows = dialog.getByRole("button", { name: "Next Rows", exact: true });
|
||||
const columns = dialog.getByRole("button", { name: "Next Columns", exact: true });
|
||||
const close = dialog.getByRole("button", { name: "Close", exact: true }).filter({ hasText: /^Close$/ });
|
||||
const input = (await expression.boundingBox())!;
|
||||
const grid = (await scroll.boundingBox())!;
|
||||
expect(input.y).toBeGreaterThan(grid.y + grid.height);
|
||||
expect(input.width).toBeCloseTo(grid.width, 0);
|
||||
for (const control of [expression, rows, columns, close]) await expect(control).toBeInViewport({ ratio: 0.98 });
|
||||
await scroll.evaluate((el) => {
|
||||
el.scrollLeft = 300;
|
||||
el.scrollTop = 150;
|
||||
});
|
||||
await expect(dialog.getByRole("rowheader").filter({ hasText: /^9$/ })).toBeInViewport({ ratio: 0.98 });
|
||||
await rows.click();
|
||||
await expect(dialog.getByText("Rows 101–200 of 220", { exact: true })).toBeVisible();
|
||||
await expect
|
||||
.poll(() => ipcCalls(page, "debug_evaluate_in"))
|
||||
.toContainEqual(expect.objectContaining({ expression: expect.stringContaining("100, 100, 0, 30") }));
|
||||
await expression.fill("totals.iloc[:2, :2]");
|
||||
await expression.press("Enter");
|
||||
const sliced = page.getByRole("dialog", { name: "Table view of totals.iloc[:2, :2]", exact: true });
|
||||
await expect(sliced.getByText("Shape (2, 2)", { exact: true })).toBeVisible();
|
||||
const slicedExpression = sliced.getByRole("textbox", { name: "Expression", exact: true });
|
||||
await slicedExpression.fill("missing_table");
|
||||
await slicedExpression.press("Enter");
|
||||
const failed = page.getByRole("dialog", { name: "Table view of missing_table", exact: true });
|
||||
const alert = failed.getByRole("alert");
|
||||
await expect(alert).toHaveText("NameError: missing_table");
|
||||
expect((await alert.boundingBox())!.y).toBeGreaterThan(
|
||||
(await failed.getByRole("textbox", { name: "Expression", exact: true }).boundingBox())!.y,
|
||||
);
|
||||
await failed
|
||||
.getByRole("button", { name: "Close", exact: true })
|
||||
.filter({ hasText: /^Close$/ })
|
||||
.click();
|
||||
await expect(failed).toHaveCount(0);
|
||||
});
|
||||
@@ -1,74 +0,0 @@
|
||||
import type { MavenModel } from "../src/platform/ipc";
|
||||
import { expect, stubDesktop, test } from "./fixtures";
|
||||
|
||||
const maven: MavenModel = {
|
||||
projects: [
|
||||
{
|
||||
pom: "pom.xml",
|
||||
dir: "",
|
||||
groupId: "dev.acme",
|
||||
artifactId: "billing",
|
||||
version: "1.0.0",
|
||||
packaging: "jar",
|
||||
displayName: "Billing",
|
||||
parent: null,
|
||||
modules: [],
|
||||
aggregated: false,
|
||||
plugins: [
|
||||
{
|
||||
groupId: "org.apache.maven.plugins",
|
||||
artifactId: "maven-surefire-plugin",
|
||||
version: "3.2.5",
|
||||
prefix: "surefire",
|
||||
goals: ["test"],
|
||||
},
|
||||
],
|
||||
dependencies: [],
|
||||
profiles: [],
|
||||
javaVersion: 21,
|
||||
command: "mvn",
|
||||
options: [],
|
||||
env: {},
|
||||
},
|
||||
],
|
||||
profiles: [],
|
||||
syncedAt: 1,
|
||||
stale: false,
|
||||
syncError: null,
|
||||
};
|
||||
|
||||
test("Maven plugin rows give the name priority over coordinates in narrow docks", async ({ workbench: page }) => {
|
||||
await stubDesktop(page);
|
||||
await page.evaluate(async (maven) => {
|
||||
window.__ipc.handlers.build_model = () => ({ maven, gradle: [] });
|
||||
const buildModule = "/src/features/build-tools/store.ts";
|
||||
const { loadModel, setExpanded } = await import(/* @vite-ignore */ buildModule);
|
||||
await loadModel();
|
||||
setExpanded("maven", new Set(["mvn:pom.xml", "mvn:pom.xml:plugins"]));
|
||||
const dockModule = "/src/workbench/toolwindows/store.ts";
|
||||
const { showToolWindow, setToolWindowSize } = await import(/* @vite-ignore */ dockModule);
|
||||
showToolWindow("maven", true);
|
||||
setToolWindowSize("right", 190);
|
||||
}, maven);
|
||||
|
||||
const tree = page.getByRole("tree", { name: "Maven projects" });
|
||||
const coordinates = "(org.apache.maven.plugins:maven-surefire-plugin:3.2.5)";
|
||||
const plugin = tree.getByRole("treeitem", { name: `surefire ${coordinates}`, exact: true });
|
||||
const name = plugin.getByText("surefire", { exact: true });
|
||||
const metadata = plugin.getByText(coordinates, { exact: true });
|
||||
await expect(name).toBeVisible();
|
||||
await expect(metadata).toHaveAttribute("title", coordinates);
|
||||
const fit = (el: Element) => {
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(el);
|
||||
return range.getBoundingClientRect().width <= el.getBoundingClientRect().width;
|
||||
};
|
||||
expect(await name.evaluate(fit)).toBe(true);
|
||||
expect(await metadata.evaluate(fit)).toBe(false);
|
||||
expect(await metadata.evaluate((el) => getComputedStyle(el).color)).not.toBe(
|
||||
await name.evaluate((el) => getComputedStyle(el).color),
|
||||
);
|
||||
|
||||
await plugin.locator("[data-tree-toggle]").click();
|
||||
await expect(tree.getByRole("treeitem", { name: "surefire:test", exact: true })).toBeVisible();
|
||||
});
|
||||
@@ -121,10 +121,7 @@ test("Git Log settings group display and column options with aligned checkboxes"
|
||||
|
||||
for (const width of [1000, 520]) {
|
||||
await page.setViewportSize({ width, height: 760 });
|
||||
// Read both rows together once the dialog has finished opening and relaid out.
|
||||
await expect
|
||||
.poll(async () => Math.abs((await tagNames.boundingBox())!.x - (await hash.boundingBox())!.x))
|
||||
.toBeLessThan(0.5);
|
||||
expect((await tagNames.boundingBox())!.x).toBeCloseTo((await hash.boundingBox())!.x, 0);
|
||||
}
|
||||
|
||||
await expect(hash).not.toBeChecked();
|
||||
|
||||
@@ -31,7 +31,6 @@ import {
|
||||
mavenRoots,
|
||||
nodeIcon,
|
||||
nodeLabel,
|
||||
pluginCoordinates,
|
||||
profileChecked,
|
||||
withGradleOptions,
|
||||
gradleHasTestTask,
|
||||
@@ -311,8 +310,6 @@ function NodeRow({ node, state }: { node: BuildNode; state: TreeRowState }) {
|
||||
</span>
|
||||
);
|
||||
}
|
||||
const plugin = node.kind === "plugin" ? node.plugin : null;
|
||||
const coordinates = plugin && `(${pluginCoordinates(plugin)})`;
|
||||
const detail =
|
||||
node.kind === "profiles" && node.projectRoot
|
||||
? node.projectRoot.split("/").pop()
|
||||
@@ -324,24 +321,12 @@ function NodeRow({ node, state }: { node: BuildNode; state: TreeRowState }) {
|
||||
const skipped =
|
||||
(mavenSkipTests && node.kind === "phase" && node.phase === "test") ||
|
||||
(gradleSkipTests && node.kind === "task" && node.task.name === "test");
|
||||
const label = (
|
||||
<span className={clsx(styles.label, state.selected && styles.selectedLabel, skipped && styles.skippedGoal)}>
|
||||
{plugin?.prefix ?? nodeLabel(node)}
|
||||
</span>
|
||||
);
|
||||
return (
|
||||
<span className={styles.row}>
|
||||
<Icon name={nodeIcon(node)} size={16} className={styles.icon} />
|
||||
{coordinates ? (
|
||||
<span className={styles.pluginText}>
|
||||
{label}
|
||||
<span className={styles.detail} title={coordinates}>
|
||||
{coordinates}
|
||||
</span>
|
||||
</span>
|
||||
) : (
|
||||
label
|
||||
)}
|
||||
<span className={clsx(styles.label, state.selected && styles.selectedLabel, skipped && styles.skippedGoal)}>
|
||||
{nodeLabel(node)}
|
||||
</span>
|
||||
{detail && <span className={styles.detail}>{detail}</span>}
|
||||
</span>
|
||||
);
|
||||
|
||||
@@ -96,18 +96,6 @@
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.pluginText {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1-5);
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.pluginText > .label {
|
||||
flex: none;
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
}
|
||||
.profile {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
@@ -99,8 +99,8 @@ export function dependencyLabel(d: MavenDependency): string {
|
||||
return parts.join(":");
|
||||
}
|
||||
|
||||
export function pluginCoordinates(p: MavenPlugin): string {
|
||||
return `${p.groupId}:${p.artifactId}${p.version ? `:${p.version}` : ""}`;
|
||||
export function pluginLabel(p: MavenPlugin): string {
|
||||
return `${p.prefix} (${p.groupId}:${p.artifactId}${p.version ? `:${p.version}` : ""})`;
|
||||
}
|
||||
|
||||
/** Profile choices in different workspace members are independent. */
|
||||
@@ -363,7 +363,7 @@ export function nodeLabel(node: BuildNode): string {
|
||||
case "plugins":
|
||||
return tx("Plugins");
|
||||
case "plugin":
|
||||
return `${node.plugin.prefix} (${pluginCoordinates(node.plugin)})`;
|
||||
return pluginLabel(node.plugin);
|
||||
case "goal":
|
||||
return `${node.plugin.prefix}:${node.goal}`;
|
||||
case "dependencies":
|
||||
|
||||
@@ -241,8 +241,7 @@ describe("MemoryView", () => {
|
||||
expect(screen.getByRole("button", { name: "刷新内存视图" }).getAttribute("data-tooltip")).toBe("刷新内存视图");
|
||||
const filter = screen.getByRole("textbox", { name: "筛选类" });
|
||||
expect(filter.getAttribute("placeholder")).toBe("筛选类");
|
||||
fireEvent.click(screen.getByRole("button", { name: "视图选项" }));
|
||||
expect(screen.getByRole("menuitemcheckbox", { name: "仅显示有变化的" })).toBeInTheDocument();
|
||||
expect(screen.getByRole("checkbox", { name: "仅显示有变化的" })).toBeTruthy();
|
||||
} finally {
|
||||
await setLocale("en");
|
||||
}
|
||||
@@ -300,15 +299,10 @@ describe("MemoryView", () => {
|
||||
expect(screen.getByText("Cache$Entry")).toBeTruthy();
|
||||
|
||||
fireEvent.change(screen.getByRole("textbox", { name: "Filter classes" }), { target: { value: "" } });
|
||||
const options = screen.getByRole("button", { name: "View Options" });
|
||||
fireEvent.click(options);
|
||||
fireEvent.click(screen.getByRole("menuitemcheckbox", { name: "Changed only", checked: false }));
|
||||
fireEvent.click(screen.getByRole("checkbox", { name: "Changed only" }));
|
||||
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: 1;
|
||||
min-width: 0;
|
||||
flex: 0 1 240px;
|
||||
min-width: 80px;
|
||||
}
|
||||
|
||||
.banner,
|
||||
|
||||
@@ -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, useRef, useState } from "react";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import clsx from "clsx";
|
||||
import { Icon, IconButton, List, Menu, SearchField, T } from "@/ui";
|
||||
import { Checkbox, Icon, IconButton, Input, List, T } from "@/ui";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { useTx } from "@/platform/i18n";
|
||||
import type { JvmClassRow, JvmMemorySnapshot } from "@/platform/ipc";
|
||||
@@ -112,8 +112,6 @@ 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";
|
||||
@@ -163,37 +161,17 @@ export function MemoryView({ session }: { session: DebugSession }) {
|
||||
disabled={entry?.loading || !canRefresh}
|
||||
/>
|
||||
<HeapCaptureButton session={session} />
|
||||
<SearchField
|
||||
<Input
|
||||
className={styles.filter}
|
||||
value={query.filter}
|
||||
onChange={(filter) => setMemoryQuery(id, { filter })}
|
||||
onChange={(e) => setMemoryQuery(id, { filter: e.target.value })}
|
||||
placeholder="Filter classes"
|
||||
aria-label="Filter classes"
|
||||
/>
|
||||
<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 }),
|
||||
},
|
||||
]}
|
||||
<Checkbox
|
||||
checked={query.changedOnly}
|
||||
onChange={(changedOnly) => setMemoryQuery(id, { changedOnly })}
|
||||
label="Changed only"
|
||||
/>
|
||||
</div>
|
||||
{backend && (
|
||||
|
||||
@@ -12,11 +12,6 @@ export function isTableType(typeName: string | null | undefined): boolean {
|
||||
return !!typeName && TABLE_TYPES.has(typeName);
|
||||
}
|
||||
|
||||
/** Numbers are right-aligned, as in the database grid. */
|
||||
export function isNumericDtype(dtype: string | undefined): boolean {
|
||||
return !!dtype && /^(u?int|float|complex|Int|UInt|Float)\d*$/.test(dtype);
|
||||
}
|
||||
|
||||
export const ROW_PAGE = 100;
|
||||
export const COLUMN_PAGE = 30;
|
||||
|
||||
|
||||
@@ -1,39 +1,35 @@
|
||||
.dialog {
|
||||
height: clamp(320px, 60vh, 760px);
|
||||
height: 500px;
|
||||
}
|
||||
|
||||
/* The table scrolls under a fixed bar, not the whole dialog body. */
|
||||
/* Scroll only the grid between the toolbar and the expression field. */
|
||||
.content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
padding: var(--space-2) var(--space-3) 0;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.bar {
|
||||
flex: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-2);
|
||||
padding-bottom: var(--space-2);
|
||||
justify-content: space-between;
|
||||
gap: var(--space-1) var(--space-2);
|
||||
}
|
||||
|
||||
.expression {
|
||||
flex: 1 1 200px;
|
||||
min-width: 0;
|
||||
height: var(--h-list-row);
|
||||
padding: 0 6px;
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-ui);
|
||||
color: var(--fg);
|
||||
background: var(--bg-input);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-small);
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.expression:focus {
|
||||
outline: none;
|
||||
border-color: var(--focus-ring);
|
||||
.pagers {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-1) var(--space-2);
|
||||
}
|
||||
|
||||
.summary,
|
||||
@@ -59,7 +55,8 @@
|
||||
.table {
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
font-family: var(--font-mono);
|
||||
min-width: 100%;
|
||||
font-family: var(--font-ui);
|
||||
font-size: var(--fs-ui);
|
||||
color: var(--fg);
|
||||
}
|
||||
@@ -77,7 +74,7 @@
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
text-align: left;
|
||||
text-align: center;
|
||||
font-weight: normal;
|
||||
color: var(--fg-secondary);
|
||||
background: var(--bg-island);
|
||||
@@ -86,7 +83,8 @@
|
||||
.table .index {
|
||||
position: sticky;
|
||||
left: 0;
|
||||
text-align: right;
|
||||
text-align: center;
|
||||
font-variant-numeric: tabular-nums;
|
||||
font-weight: normal;
|
||||
color: var(--fg-secondary);
|
||||
background: var(--bg-island);
|
||||
@@ -100,16 +98,22 @@
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
|
||||
.numeric {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.dtype {
|
||||
margin-left: var(--space-1);
|
||||
color: var(--fg-subtle);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
|
||||
.message {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
padding: var(--space-3) 0;
|
||||
color: var(--fg-secondary);
|
||||
}
|
||||
|
||||
.error {
|
||||
max-height: 5em;
|
||||
overflow: auto;
|
||||
overflow-wrap: anywhere;
|
||||
color: var(--danger);
|
||||
}
|
||||
@@ -1,19 +1,10 @@
|
||||
/** View as Table: a DataFrame / Series / ndarray of the paused frame, one page of rows and columns at a time. */
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import clsx from "clsx";
|
||||
import type { DebugSessionId } from "@/platform/ipc";
|
||||
import { Dialog, IconButton } from "@/ui";
|
||||
import { Dialog, IconButton, Input } from "@/ui";
|
||||
import { formatMessage, tx } from "@/platform/i18n";
|
||||
import { evaluate, useDebug } from "../state";
|
||||
import {
|
||||
COLUMN_PAGE,
|
||||
ROW_PAGE,
|
||||
clampWindow,
|
||||
isNumericDtype,
|
||||
parseTableResult,
|
||||
tableExpression,
|
||||
type TableResult,
|
||||
} from "../tableView";
|
||||
import { COLUMN_PAGE, ROW_PAGE, clampWindow, parseTableResult, tableExpression, type TableResult } from "../tableView";
|
||||
import styles from "./TableViewDialog.module.css";
|
||||
|
||||
export function TableViewDialog({
|
||||
@@ -63,7 +54,7 @@ export function TableViewDialog({
|
||||
};
|
||||
}, [expression, win, session, stops, frame, paused]);
|
||||
|
||||
const page = result && "page" in result ? result.page : null;
|
||||
const page = paused && result && "page" in result ? result.page : null;
|
||||
const error = !paused
|
||||
? tx("Values are available while the program is paused")
|
||||
: result && "error" in result
|
||||
@@ -114,54 +105,37 @@ export function TableViewDialog({
|
||||
open
|
||||
onClose={onClose}
|
||||
// An element, not a string: Dialog would translate a variable named like a catalog text ("tasks").
|
||||
title={<span>{initial}</span>}
|
||||
width="clamp(520px, 70vw, 1100px)"
|
||||
title={<span>{expression}</span>}
|
||||
width={700}
|
||||
minWidth={420}
|
||||
minHeight={260}
|
||||
resizable="both"
|
||||
aria-label={formatMessage(tx("Table view of {label}"), { label: initial })}
|
||||
aria-label={formatMessage(tx("Table view of {label}"), { label: expression })}
|
||||
buttons={[{ label: "Close", role: "cancel" }]}
|
||||
className={styles.dialog}
|
||||
>
|
||||
<div className={styles.content}>
|
||||
<div className={styles.bar}>
|
||||
<input
|
||||
className={styles.expression}
|
||||
value={draft}
|
||||
spellCheck={false}
|
||||
autoComplete="off"
|
||||
aria-label={tx("Expression")}
|
||||
onChange={(e) => setDraft(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key !== "Enter" || !draft.trim()) return;
|
||||
e.preventDefault();
|
||||
setExpression(draft.trim());
|
||||
setWin({ row: 0, column: 0 });
|
||||
}}
|
||||
/>
|
||||
{page && (
|
||||
{page && (
|
||||
<div className={styles.bar}>
|
||||
<span className={styles.summary}>
|
||||
{formatMessage(tx("Shape ({shape})"), { shape: page.shape.join(", ") })}
|
||||
{page.kind !== "frame" ? ` · ${page.dtypes[0]}` : ""}
|
||||
</span>
|
||||
)}
|
||||
{page &&
|
||||
pager(win.row, ROW_PAGE, page.rows, (row) => setWin({ ...win, row }), {
|
||||
range: tx("Rows {from}–{to} of {total}"),
|
||||
previous: tx("Previous Rows"),
|
||||
next: tx("Next Rows"),
|
||||
})}
|
||||
{page &&
|
||||
pager(win.column, COLUMN_PAGE, page.columns, (column) => setWin({ ...win, column }), {
|
||||
range: tx("Columns {from}–{to} of {total}"),
|
||||
previous: tx("Previous Columns"),
|
||||
next: tx("Next Columns"),
|
||||
})}
|
||||
</div>
|
||||
{error ? (
|
||||
<div className={styles.message} role="alert">
|
||||
{error}
|
||||
<div className={styles.pagers}>
|
||||
{pager(win.row, ROW_PAGE, page.rows, (row) => setWin({ ...win, row }), {
|
||||
range: tx("Rows {from}–{to} of {total}"),
|
||||
previous: tx("Previous Rows"),
|
||||
next: tx("Next Rows"),
|
||||
})}
|
||||
{pager(win.column, COLUMN_PAGE, page.columns, (column) => setWin({ ...win, column }), {
|
||||
range: tx("Columns {from}–{to} of {total}"),
|
||||
previous: tx("Previous Columns"),
|
||||
next: tx("Next Columns"),
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
) : page ? (
|
||||
)}
|
||||
{page ? (
|
||||
<div className={styles.scroll} tabIndex={0} role="region" aria-label={tx("Table")}>
|
||||
<table className={styles.table}>
|
||||
<thead>
|
||||
@@ -182,14 +156,7 @@ export function TableViewDialog({
|
||||
{page.index[r]}
|
||||
</th>
|
||||
{row.map((cell, c) => (
|
||||
<td
|
||||
key={c}
|
||||
className={clsx(
|
||||
isNumericDtype(page.kind === "frame" ? page.dtypes[c] : page.dtypes[0]) && styles.numeric,
|
||||
)}
|
||||
>
|
||||
{cell}
|
||||
</td>
|
||||
<td key={c}>{cell}</td>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
@@ -197,7 +164,26 @@ export function TableViewDialog({
|
||||
</table>
|
||||
</div>
|
||||
) : (
|
||||
<div className={styles.message}>{tx("Loading…")}</div>
|
||||
<div className={styles.message}>{!error && tx("Loading…")}</div>
|
||||
)}
|
||||
<Input
|
||||
className={styles.expression}
|
||||
mono
|
||||
data-autofocus=""
|
||||
value={draft}
|
||||
aria-label="Expression"
|
||||
onChange={(e) => setDraft(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key !== "Enter" || !draft.trim()) return;
|
||||
e.preventDefault();
|
||||
setExpression(draft.trim());
|
||||
setWin({ row: 0, column: 0 });
|
||||
}}
|
||||
/>
|
||||
{error && (
|
||||
<div className={styles.error} role="alert">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Dialog>
|
||||
|
||||
Reference in new issue
Block a user