mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
fix(editor): make workspace refactoring previews easier to scan (#5183)
Separate the filename from its directory in workspace refactoring previews. This gives same-named files distinct locations and frees space for rename targets and occurrence counts. Hovering a file or a rename target shows its full path.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { expect, test } from "./fixtures";
|
||||
|
||||
test("the workspace refactoring preview separates filenames from directories and keeps outcomes readable", async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
await page.setViewportSize({ width: 420, height: 620 });
|
||||
await page.evaluate(async () => {
|
||||
const popupPath = "/src/editor/lsp/popupStore.ts";
|
||||
const editPath = "/src/editor/lsp/workspaceEdit.ts";
|
||||
const { openPopup } = await import(/* @vite-ignore */ popupPath);
|
||||
const { summarizeWorkspaceEdit } = await import(/* @vite-ignore */ editPath);
|
||||
const root = "/dev/acme-api";
|
||||
const edit = {
|
||||
range: { start: { line: 0, col: 0 }, end: { line: 0, col: 9 } },
|
||||
new_text: "postInvoice",
|
||||
};
|
||||
openPopup({
|
||||
kind: "preview",
|
||||
title: "Rename 'saveOrder' to 'postInvoice'",
|
||||
summary: summarizeWorkspaceEdit({
|
||||
files: [
|
||||
{ kind: "edit", path: `${root}/README.md`, edits: [edit] },
|
||||
{ kind: "edit", path: `${root}/packages/billing/src/Routes.ts`, edits: [edit, edit] },
|
||||
{ kind: "edit", path: `${root}/packages/checkout/src/Routes.ts`, edits: [edit] },
|
||||
{
|
||||
kind: "rename",
|
||||
from: `${root}/packages/checkout/src/Invoice.ts`,
|
||||
to: `${root}/packages/checkout/src/InvoiceReconciliationForInternationalOrders.ts`,
|
||||
},
|
||||
],
|
||||
}),
|
||||
renameThemeClasses: "",
|
||||
confirmLabel: "Do Refactor",
|
||||
onConfirm: () => {
|
||||
document.body.dataset.refactorConfirmed = "true";
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const dialog = page.getByRole("dialog", { name: "Rename 'saveOrder' to 'postInvoice'" });
|
||||
const rows = dialog.getByRole("list", { name: "Changes" }).getByRole("listitem");
|
||||
await expect(rows).toHaveCount(4);
|
||||
await expect(dialog.getByText("4 occurrences in 4 files")).toBeVisible();
|
||||
const root = rows.filter({ hasText: "README.md" });
|
||||
await expect(root.getByText("README.md", { exact: true })).toHaveCount(1);
|
||||
|
||||
const billing = rows.filter({ hasText: "2 occurrences" });
|
||||
await expect(billing.getByText("Routes.ts", { exact: true })).toBeVisible();
|
||||
await expect(billing.getByText("packages/billing/src", { exact: true })).toBeVisible();
|
||||
await expect(billing.getByTitle("packages/billing/src/Routes.ts", { exact: true })).toBeVisible();
|
||||
const checkout = rows.filter({ hasText: "packages/checkout/src" }).filter({ hasText: "Routes.ts" });
|
||||
await expect(checkout.getByText("packages/checkout/src", { exact: true })).toBeVisible();
|
||||
|
||||
const rename = rows.filter({ hasText: "Invoice.ts" });
|
||||
const target = rename.getByText("→ InvoiceReconciliationForInternationalOrders.ts", { exact: true });
|
||||
await expect(target).toBeVisible();
|
||||
await expect(target).toHaveAttribute("title", "packages/checkout/src/InvoiceReconciliationForInternationalOrders.ts");
|
||||
expect((await target.boundingBox())!.width).toBeGreaterThan(35);
|
||||
await expect(dialog.getByRole("button", { name: "Do Refactor", exact: true })).toBeInViewport();
|
||||
await dialog.getByRole("button", { name: "Do Refactor", exact: true }).click();
|
||||
await expect(dialog).toBeHidden();
|
||||
await expect(page.locator("body")).toHaveAttribute("data-refactor-confirmed", "true");
|
||||
});
|
||||
@@ -532,20 +532,6 @@
|
||||
.renamePreview .previewList {
|
||||
overflow: visible;
|
||||
}
|
||||
.renamePreview .previewName {
|
||||
min-width: 0;
|
||||
max-width: 55%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.renamePreview .previewOp {
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.renamePreview .previewWarning {
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
@@ -571,23 +557,46 @@
|
||||
padding: 0 14px;
|
||||
font-size: var(--fs-ui);
|
||||
}
|
||||
.previewName {
|
||||
color: var(--fg-emphasis);
|
||||
.previewFile {
|
||||
flex: 1 1 auto;
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: var(--space-2);
|
||||
min-width: 0;
|
||||
}
|
||||
.previewPath {
|
||||
.previewName,
|
||||
.previewDirectory,
|
||||
.previewOp {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.previewName {
|
||||
flex: none;
|
||||
max-inline-size: 100%;
|
||||
color: var(--fg-emphasis);
|
||||
}
|
||||
.previewFile:has(.previewDirectory) .previewName {
|
||||
max-inline-size: 70%;
|
||||
}
|
||||
.previewDirectory {
|
||||
color: var(--fg-subtle);
|
||||
font-size: var(--fs-small);
|
||||
direction: rtl;
|
||||
}
|
||||
.previewOp,
|
||||
.previewCount {
|
||||
flex: none;
|
||||
font-size: var(--fs-small);
|
||||
color: var(--fg-muted);
|
||||
}
|
||||
.previewOp {
|
||||
max-inline-size: 55%;
|
||||
}
|
||||
.previewCount {
|
||||
flex: none;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.previewWarning {
|
||||
flex: none;
|
||||
|
||||
+28
-19
@@ -22,7 +22,7 @@ import {
|
||||
selectableText,
|
||||
T,
|
||||
} from "@/ui";
|
||||
import { basename, relativePath, useProject } from "@/platform/project";
|
||||
import { basename, relativeDir, relativePath, useProject } from "@/platform/project";
|
||||
import {
|
||||
closePopup,
|
||||
updatePopup,
|
||||
@@ -761,25 +761,34 @@ function PreviewDialog({ popup }: { popup: Extract<LspPopup, { kind: "preview" }
|
||||
</ul>
|
||||
) : (
|
||||
<ul data-testid="refactor-preview" className={styles.previewList} aria-label={tx("Changes")}>
|
||||
{summary.entries.map((e) => (
|
||||
<li key={e.path} className={styles.previewRow}>
|
||||
<Icon name={fileIconName(basename(e.path), e.path)} size={14} className={styles.itemIcon} />
|
||||
<span className={styles.previewName} title={relativePath(root, e.path)}>
|
||||
{basename(e.path)}
|
||||
</span>
|
||||
<span className={styles.previewPath} title={relativePath(root, e.path)}>
|
||||
{relativePath(root, e.path)}
|
||||
</span>
|
||||
<span className={styles.spacer} />
|
||||
{e.operation === "rename" && e.to && <span className={styles.previewOp}>→ {basename(e.to)}</span>}
|
||||
{e.operation && e.operation !== "rename" && <span className={styles.previewOp}>{e.operation}</span>}
|
||||
{e.edits > 0 && (
|
||||
<span className={styles.previewCount}>
|
||||
{e.edits} {e.edits === 1 ? "occurrence" : "occurrences"}
|
||||
{summary.entries.map((e) => {
|
||||
const name = basename(e.path);
|
||||
const directory = relativeDir(root, e.path);
|
||||
return (
|
||||
<li key={e.path} className={styles.previewRow}>
|
||||
<Icon name={fileIconName(name, e.path)} size={14} className={styles.itemIcon} />
|
||||
<span className={styles.previewFile} title={relativePath(root, e.path)}>
|
||||
<span className={styles.previewName}>{name}</span>
|
||||
{directory && (
|
||||
<span className={styles.previewDirectory}>
|
||||
<bdi>{directory}</bdi>
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
{e.operation === "rename" && e.to && (
|
||||
<span className={styles.previewOp} title={relativePath(root, e.to)}>
|
||||
→ {basename(e.to)}
|
||||
</span>
|
||||
)}
|
||||
{e.operation && e.operation !== "rename" && <span className={styles.previewOp}>{e.operation}</span>}
|
||||
{e.edits > 0 && (
|
||||
<span className={styles.previewCount}>
|
||||
{e.edits} {e.edits === 1 ? "occurrence" : "occurrences"}
|
||||
</span>
|
||||
)}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</Dialog>
|
||||
|
||||
Reference in New Issue
Block a user