mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-22 09:39:27 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dfae74cf5c |
No files matched your search
@@ -1,9 +1,7 @@
|
||||
import type { EditorView } from "@codemirror/view";
|
||||
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
|
||||
|
||||
test("Quick Evaluate opens an object tree that fits the editor and returns focus on Escape", async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
test("Quick Evaluate and hover keep value previews usable in a narrow editor", async ({ workbench: page }) => {
|
||||
await page.setViewportSize({ width: 445, height: 500 });
|
||||
await stubDesktop(page);
|
||||
await page.evaluate(async () => {
|
||||
@@ -19,7 +17,9 @@ test("Quick Evaluate opens an object tree that fits the editor and returns focus
|
||||
h.fs_probe = () => ({ size: 48, binary: false, tooLarge: false });
|
||||
h.fs_read_text = () => "summary = {}\nsubtotal = 42\n";
|
||||
h.debug_evaluate_in = ({ expression }) =>
|
||||
expression === "summary" ? value("summary", "{...}", "dict", 101) : value("subtotal", "42", "int");
|
||||
expression === "summary"
|
||||
? value("summary", `{'audit': '${"Regional settlement totals ".repeat(8)}'}`, "dict", 101)
|
||||
: value("subtotal", "42", "int");
|
||||
h.debug_variables = ({ reference }) =>
|
||||
reference === 101
|
||||
? [value("audit", "{...}", "dict", 102), value("total", "47.74", "float")]
|
||||
@@ -81,8 +81,59 @@ test("Quick Evaluate opens an object tree that fits the editor and returns focus
|
||||
await evaluate(2);
|
||||
await expect(hint.getByRole("tree")).toHaveCount(0);
|
||||
await expect(hint).toHaveText(/subtotal\s*=\s*42/);
|
||||
expect(await ipcCalls(page, "debug_evaluate_in")).toEqual([
|
||||
const scalar = hint.locator("[class*='_valueTooltip_']");
|
||||
const uiFont = await page.locator("body").evaluate((el) => getComputedStyle(el).fontFamily);
|
||||
await expect(scalar).toHaveCSS("font-family", uiFont);
|
||||
await expect(scalar).toHaveCSS("font-size", "13px");
|
||||
await expect(scalar).toHaveCSS("font-weight", "700");
|
||||
await expect(scalar.locator(".cm-openidea-icon")).toHaveCount(1);
|
||||
await content.press("Escape");
|
||||
await expect(hint).toBeHidden();
|
||||
|
||||
await page.setViewportSize({ width: 620, height: 480 });
|
||||
await page.evaluate(async () => {
|
||||
const layoutModule = "/src/workbench/toolwindows/store.ts";
|
||||
const servicesModule = "/src/workbench/contributions.ts";
|
||||
const { moveToolWindow, setToolWindowSize } = await import(/* @vite-ignore */ layoutModule);
|
||||
const { toolWindowService } = await import(/* @vite-ignore */ servicesModule);
|
||||
moveToolWindow("project", "left");
|
||||
setToolWindowSize("left", 220);
|
||||
toolWindowService().show("project", false);
|
||||
});
|
||||
await expect.poll(async () => (await editor.boundingBox())!.x).toBeGreaterThan(160);
|
||||
const position = await content.evaluate((el) => {
|
||||
const { view } = (el as HTMLElement & { cmTile: { view: EditorView } }).cmTile;
|
||||
return view.coordsAtPos(view.state.doc.line(1).from + 2);
|
||||
});
|
||||
await page.mouse.move(position!.left, (position!.top + position!.bottom) / 2);
|
||||
const hover = page.locator(".cm-tooltip-hover").locator("[class*='_valueTooltip_']");
|
||||
const expand = hover.getByRole("button", { name: "Expand value" });
|
||||
await expect(hover).toContainText("Regional settlement totals");
|
||||
await expect(hover).toHaveCSS("font-family", uiFont);
|
||||
const summary = hover.locator("[class*='_valueText_']");
|
||||
const textBox = (await summary.boundingBox())!;
|
||||
const controlBox = (await expand.boundingBox())!;
|
||||
const iconBox = (await hover.locator(".cm-openidea-icon").boundingBox())!;
|
||||
expect(textBox.height).toBeGreaterThan(20);
|
||||
expect(Math.abs(controlBox.y - iconBox.y)).toBeLessThan(1);
|
||||
expect(textBox.x).toBeGreaterThanOrEqual(iconBox.x + iconBox.width);
|
||||
const fitsEditor = async () => {
|
||||
const tooltip = await hover.boundingBox();
|
||||
const pane = (await editor.boundingBox())!;
|
||||
return !!tooltip && tooltip.x >= pane.x - 1 && tooltip.x + tooltip.width <= pane.x + pane.width + 1;
|
||||
};
|
||||
await expect.poll(fitsEditor).toBe(true);
|
||||
await page.setViewportSize({ width: 555, height: 480 });
|
||||
await expect.poll(fitsEditor).toBe(true);
|
||||
await expand.click();
|
||||
const pinned = hint.getByRole("tree", { name: "summary" });
|
||||
await expect(pinned).toBeFocused();
|
||||
await pinned.press("Escape");
|
||||
await expect(content).toBeFocused();
|
||||
const calls = await ipcCalls(page, "debug_evaluate_in");
|
||||
expect(calls.filter((call) => call.context === "watch")).toEqual([
|
||||
{ session: 91, frameId: 11, expression: "summary", context: "watch" },
|
||||
{ session: 91, frameId: 11, expression: "subtotal", context: "watch" },
|
||||
]);
|
||||
expect(calls).toContainEqual({ session: 91, frameId: 11, expression: "summary", context: "hover" });
|
||||
});
|
||||
@@ -38,7 +38,7 @@ afterEach(() => {
|
||||
|
||||
describe("value hint", () => {
|
||||
it("keeps a hint whose value was expanded past the hint's timeout", () => {
|
||||
showHint(view, () => valueHint("order", order, session), { pos: 0, timeout: 4000 });
|
||||
showHint(view, () => valueHint(view, "order", order, session), { pos: 0, timeout: 4000 });
|
||||
expand();
|
||||
expect(document.querySelector(".cm-lsp-hint .tree")).not.toBeNull();
|
||||
vi.advanceTimersByTime(60_000);
|
||||
@@ -47,7 +47,7 @@ describe("value hint", () => {
|
||||
|
||||
it("hands an expanded hover hint to its pin instead of growing in place", () => {
|
||||
const pin = vi.fn();
|
||||
showHint(view, () => valueHint("order", order, session, 400, { pin }), { pos: 0 });
|
||||
showHint(view, () => valueHint(view, "order", order, session, 400, { pin }), { pos: 0 });
|
||||
expand();
|
||||
expect(pin).toHaveBeenCalled();
|
||||
expect(document.querySelector(".tree")).toBeNull();
|
||||
|
||||
@@ -169,13 +169,25 @@
|
||||
|
||||
/* Data Views › Show value tooltip on mouse hover. */
|
||||
.valueTooltip {
|
||||
max-width: 520px;
|
||||
padding: 4px 8px;
|
||||
font-family: var(--font-mono);
|
||||
font-weight: var(--fw-code);
|
||||
font-size: var(--fs-code);
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: var(--space-1);
|
||||
max-width: min(90vw, calc(var(--debug-value-editor-width, 100vw) - var(--space-2)));
|
||||
padding: var(--space-1) var(--space-2);
|
||||
font-family: var(--font-ui);
|
||||
font-size: var(--fs-ui);
|
||||
font-weight: 700;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.valueText {
|
||||
min-width: 0;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.valueGlyph {
|
||||
display: inline-flex;
|
||||
flex: none;
|
||||
margin-top: 1px;
|
||||
}
|
||||
.valueTooltipTree {
|
||||
display: flex;
|
||||
@@ -194,19 +206,22 @@
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
:global(.cm-lsp-hint):has(> .valueTooltip) {
|
||||
padding: 0;
|
||||
}
|
||||
.valueExpand {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
margin-right: 4px;
|
||||
flex: none;
|
||||
margin-top: 1px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: var(--radius-small);
|
||||
background: transparent;
|
||||
color: var(--fg-muted);
|
||||
vertical-align: -3px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.valueExpand:hover {
|
||||
|
||||
@@ -49,7 +49,7 @@ class InlineValues extends WidgetType {
|
||||
e.stopPropagation();
|
||||
const session = activeSession();
|
||||
if (!session || session.status !== "paused") return;
|
||||
showHint(view, () => valueHint(part.name, part.variable, session.id, null), {
|
||||
showHint(view, () => valueHint(view, part.name, part.variable, session.id, null), {
|
||||
pos: view.posAtDOM(piece),
|
||||
timeout: 60_000,
|
||||
});
|
||||
@@ -65,7 +65,7 @@ class InlineValues extends WidgetType {
|
||||
e.stopPropagation();
|
||||
const session = activeSession();
|
||||
if (!session || session.status !== "paused") return;
|
||||
showHint(view, () => valueHint(part.name, part.variable, session.id, null), {
|
||||
showHint(view, () => valueHint(view, part.name, part.variable, session.id, null), {
|
||||
pos: view.posAtDOM(show),
|
||||
timeout: 60_000,
|
||||
});
|
||||
|
||||
@@ -13,6 +13,7 @@ import { activeSession, evaluate, useDebug } from "../state";
|
||||
import { inlineValue, shownValue } from "../values";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { iconMarkup, selectableText } from "@/ui";
|
||||
import { iconNode } from "@/ui/iconNode";
|
||||
import { mountValueTree } from "../ui/ValueHintTree";
|
||||
import styles from "./editor.module.css";
|
||||
|
||||
@@ -96,6 +97,7 @@ export function expressionAt(
|
||||
|
||||
/** IDEA's value hint: `expression = value {type}`, objects expandable into a variables tree in place. */
|
||||
export function valueHint(
|
||||
view: EditorView,
|
||||
expression: string,
|
||||
value: Variable,
|
||||
session: DebugSessionId,
|
||||
@@ -104,15 +106,21 @@ export function valueHint(
|
||||
): { dom: HTMLElement; destroy: () => void } {
|
||||
const dom = document.createElement("div");
|
||||
dom.className = `${styles.valueTooltip} ${selectableText}`;
|
||||
const stopSizing = watchHintWidth(view, dom);
|
||||
let tree: { unmount(): void } | null = null;
|
||||
const destroy = () => {
|
||||
stopSizing();
|
||||
tree?.unmount();
|
||||
};
|
||||
const expandTree = () => {
|
||||
dom.classList.remove(styles.valueTooltip!);
|
||||
dom.classList.replace(selectableText, styles.valueTooltipTree!);
|
||||
dom.replaceChildren();
|
||||
tree = mountValueTree(dom, expression, value, session);
|
||||
};
|
||||
if (value.variablesReference > 0 && opts.expanded) {
|
||||
expandTree();
|
||||
return { dom, destroy: () => tree?.unmount() };
|
||||
return { dom, destroy };
|
||||
}
|
||||
if (value.variablesReference > 0) {
|
||||
// IDEA's value hint: the "+" expands the object into a variables tree in place.
|
||||
@@ -131,6 +139,8 @@ export function valueHint(
|
||||
});
|
||||
dom.append(expand);
|
||||
}
|
||||
const summary = document.createElement("span");
|
||||
summary.className = styles.valueText!;
|
||||
const name = document.createElement("span");
|
||||
name.className = styles.valueName!;
|
||||
name.textContent = `${expression} = `;
|
||||
@@ -143,11 +153,33 @@ export function valueHint(
|
||||
span.textContent = text;
|
||||
return span;
|
||||
};
|
||||
dom.append(name);
|
||||
if (leading) dom.append(type(`${shown.label} `));
|
||||
dom.append(max === null ? shown.text : inlineValue(shown.text, max));
|
||||
if (shown.label && !leading) dom.append(type(` ${shown.label}`));
|
||||
return { dom, destroy: () => tree?.unmount() };
|
||||
summary.append(name);
|
||||
if (leading) summary.append(type(`${shown.label} `));
|
||||
summary.append(max === null ? shown.text : inlineValue(shown.text, max));
|
||||
if (shown.label && !leading) summary.append(type(` ${shown.label}`));
|
||||
dom.append(iconNode("variable", 16, styles.valueGlyph), summary);
|
||||
return { dom, destroy };
|
||||
}
|
||||
|
||||
function watchHintWidth(view: EditorView, dom: HTMLElement): () => void {
|
||||
let width = 0;
|
||||
let resizeFrame = 0;
|
||||
const updateWidth = () => {
|
||||
const next = view.dom.clientWidth;
|
||||
if (!next || next === width) return;
|
||||
width = next;
|
||||
dom.style.setProperty("--debug-value-editor-width", `${width}px`);
|
||||
};
|
||||
updateWidth();
|
||||
const resize = new ResizeObserver(() => {
|
||||
cancelAnimationFrame(resizeFrame);
|
||||
resizeFrame = requestAnimationFrame(updateWidth);
|
||||
});
|
||||
resize.observe(view.dom);
|
||||
return () => {
|
||||
resize.disconnect();
|
||||
cancelAnimationFrame(resizeFrame);
|
||||
};
|
||||
}
|
||||
|
||||
export function showQuickValue(
|
||||
@@ -158,7 +190,7 @@ export function showQuickValue(
|
||||
session: DebugSessionId,
|
||||
) {
|
||||
if (value.variablesReference > 0) showValueTree(view, pos, expression, value, session);
|
||||
else showHint(view, () => valueHint(expression, value, session), { pos, timeout: 60_000 });
|
||||
else showHint(view, () => valueHint(view, expression, value, session), { pos, timeout: 60_000 });
|
||||
}
|
||||
|
||||
export function valueTooltip(): Extension {
|
||||
@@ -185,7 +217,7 @@ export function valueTooltip(): Extension {
|
||||
end: expr.to,
|
||||
above: true,
|
||||
create: (view) =>
|
||||
valueHint(expr.text, value, session.id, 400, {
|
||||
valueHint(view, expr.text, value, session.id, 400, {
|
||||
// The tree outgrows the hint and may move to the other side of the line, away from the
|
||||
// mouse, which closed the hover tooltip before it could be reached. Like IDEA's value
|
||||
// popup it stays until Escape, a click in the editor or the next step.
|
||||
@@ -208,21 +240,7 @@ function pinnedTree(view: EditorView, expression: string, value: Variable, sessi
|
||||
const unsubscribe = useDebug.subscribe((s) => {
|
||||
if (s.stopSeq !== stop || s.sessions[session]?.status !== "paused") hideHint(view);
|
||||
});
|
||||
const hint = valueHint(expression, value, session, 400, { expanded: true });
|
||||
let width = 0;
|
||||
let resizeFrame = 0;
|
||||
const updateWidth = () => {
|
||||
const next = view.dom.clientWidth;
|
||||
if (!next || next === width) return;
|
||||
width = next;
|
||||
hint.dom.style.setProperty("--debug-value-editor-width", `${width}px`);
|
||||
};
|
||||
updateWidth();
|
||||
const resize = new ResizeObserver(() => {
|
||||
cancelAnimationFrame(resizeFrame);
|
||||
resizeFrame = requestAnimationFrame(updateWidth);
|
||||
});
|
||||
resize.observe(view.dom);
|
||||
const hint = valueHint(view, expression, value, session, 400, { expanded: true });
|
||||
// The tree has the focus, so the editor's Escape doesn't reach the hint.
|
||||
hint.dom.addEventListener("keydown", (e) => {
|
||||
if (e.key !== "Escape" || e.defaultPrevented) return;
|
||||
@@ -233,8 +251,6 @@ function pinnedTree(view: EditorView, expression: string, value: Variable, sessi
|
||||
return {
|
||||
dom: hint.dom,
|
||||
destroy: () => {
|
||||
resize.disconnect();
|
||||
cancelAnimationFrame(resizeFrame);
|
||||
unsubscribe();
|
||||
hint.destroy();
|
||||
},
|
||||
@@ -287,7 +303,10 @@ export function selectionValueTooltip(): Extension {
|
||||
}
|
||||
// The selection moved on while evaluating.
|
||||
if (seq !== this.seq) return;
|
||||
showHint(this.view, () => valueHint(expr.text, value, session.id), { pos: expr.from, timeout: 60_000 });
|
||||
showHint(this.view, () => valueHint(this.view, expr.text, value, session.id), {
|
||||
pos: expr.from,
|
||||
timeout: 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
||||
Reference in new issue
Block a user