Compare commits

...
9 changed files with 165 additions and 88 deletions

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
import { expect, openFromTree, test } from "./fixtures";
test("Reformat File aligns scope and option controls and supports arrow-key scope changes", async ({
workbench: page,
}) => {
const editor = await openFromTree(page, "build.gradle.kts");
await editor.locator(".cm-line").first().click();
await page.keyboard.press("Home");
await page.keyboard.press("Shift+End");
await page.evaluate(async () => {
const path = "/src/platform/actions.ts";
const { executeAction } = await import(/* @vite-ignore */ path);
await executeAction("code.reformatDialog");
});
const dialog = page.getByRole("dialog", { name: /Reformat File/ });
const scope = dialog.getByRole("group", { name: "Scope" });
const selected = scope.getByRole("radio", { name: "Selected text" });
await expect(selected).toBeChecked();
await expect(scope.getByRole("radio").first()).toHaveAccessibleName("Selected text");
await selected.press("ArrowDown");
await expect(scope.getByRole("radio", { name: "Whole file" })).toBeChecked();
const optimize = dialog.getByRole("group", { name: "Options" }).getByRole("checkbox", { name: "Optimize imports" });
expect((await selected.boundingBox())!.x).toBeCloseTo((await optimize.boundingBox())!.x, 0);
await page.keyboard.press("Escape");
await expect(dialog).toBeHidden();
});
test("Reformat Code keeps long targets and the file mask usable in a narrow window", async ({ workbench: page }) => {
await page.setViewportSize({ width: 340, height: 460 });
const target = "InternationalSettlementReconciliation".repeat(4);
await page.evaluate(async (target) => {
const path = "/src/platform/actions.ts";
const { executeAction } = await import(/* @vite-ignore */ path);
await executeAction("code.reformatFiles", { directories: [`/dev/acme-api/${target}`] });
}, target);
const dialog = page.getByRole("dialog", { name: "Reformat Code", exact: true });
await expect(dialog.getByText(target, { exact: true })).toBeVisible();
const body = dialog.locator("[data-dialog-body]");
expect(await body.evaluate((el) => el.scrollWidth)).toBe(await body.evaluate((el) => el.clientWidth));
await expect(
dialog.getByRole("group", { name: "Options" }).getByRole("checkbox", { name: "Include subdirectories" }),
).toBeChecked();
const filters = dialog.getByRole("group", { name: "Filters" });
const mask = filters.getByRole("textbox", { name: "File mask" });
await expect(mask).toBeDisabled();
await filters.getByText("File mask:", { exact: true }).click();
await mask.fill("*.java");
await expect(mask).toHaveValue("*.java");
await dialog.getByRole("button", { name: "Cancel" }).click();
await expect(dialog).toBeHidden();
});
-27
View File
@@ -553,33 +553,6 @@
}
/* Dialog bodies get no padding of their own; wrap the groups like Analysis dialogs' .form. */
.reformatBody {
display: flex;
flex-direction: column;
gap: 10px;
padding: 14px;
}
.reformatGroup {
margin: 0;
padding: 0;
border: 0;
display: flex;
flex-direction: column;
gap: var(--space-1-5);
}
.reformatLegend {
margin-bottom: 6px;
padding: 0;
font-size: var(--fs-small);
color: var(--fg-subtle);
}
.reformatOption {
display: flex;
align-items: center;
gap: var(--space-1-5);
font-size: var(--fs-ui);
}
.pasteImports {
display: flex;
flex-direction: column;
+6 -6
View File
@@ -1,5 +1,5 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { act, fireEvent, render, screen } from "@testing-library/react";
import { act, fireEvent, render, screen, within } from "@testing-library/react";
import type { Location } from "@/bindings";
const openFile = vi.fn(async () => undefined);
@@ -19,7 +19,6 @@ const { closePopup, openPopup, useLspPopup } = await import("./popupStore");
const { useDocWindow, hoverDoc, pushHistory, stepHistory, hoverCandidates } = await import("./docs");
const { mountHoverDoc } = await import("./DocView");
const { hoverSource } = await import("./hover");
import popupStyles from "./Popups.module.css";
import { registerImportsOnPasteActions } from "./importsOnPaste";
import { EditorState } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
@@ -352,7 +351,7 @@ describe("quick definition popup", () => {
});
describe("reformat dialog", () => {
it("wraps its content in the padded body", () => {
it("offers only whole-file formatting when the editor has no selection", () => {
const onRun = vi.fn();
openPopup({
kind: "reformat",
@@ -363,9 +362,10 @@ describe("reformat dialog", () => {
onRun,
});
render(<LspPopups />);
const body = screen.getByRole("dialog", { name: "Reformat File" }).querySelector("[data-dialog-body]")!;
expect(body.firstElementChild).toHaveClass(popupStyles.reformatBody!);
expect(body.firstElementChild!.querySelectorAll("fieldset")).toHaveLength(2);
const scope = within(screen.getByRole("group", { name: "Scope" }));
expect(scope.getByRole("radio", { name: "Selected text" })).toBeDisabled();
expect(scope.getByRole("radio", { name: "Whole file" })).toBeChecked();
expect(within(screen.getByRole("group", { name: "Options" })).getByRole("checkbox")).not.toBeChecked();
fireEvent.click(screen.getByRole("button", { name: "Run" }));
expect(onRun).toHaveBeenCalledWith({ selectionOnly: false, optimizeImports: false });
});
+21 -25
View File
@@ -11,6 +11,7 @@ import {
List,
MenuList,
Popup,
Radio,
Select,
Spinner,
SymbolBadge,
@@ -35,6 +36,7 @@ import { renderCode } from "./markdown";
import { describeSummary } from "./workspaceEdit";
import { useUsagesStatus } from "./navigation";
import styles from "./Popups.module.css";
import fieldsetStyles from "@/ui/DialogFieldset.module.css";
import { tx } from "@/platform/i18n";
import { executeAction } from "@/platform/actions";
@@ -681,7 +683,7 @@ function ReformatDialog({ popup }: { popup: Extract<LspPopup, { kind: "reformat"
open
onClose={closePopup}
title={popup.title}
width={380}
width={400}
buttons={[
{
label: "Run",
@@ -695,33 +697,27 @@ function ReformatDialog({ popup }: { popup: Extract<LspPopup, { kind: "reformat"
{ label: "Cancel", role: "cancel" },
]}
>
<div className={styles.reformatBody}>
<fieldset className={styles.reformatGroup}>
<legend className={styles.reformatLegend}>
<div className={fieldsetStyles.body}>
<fieldset className={fieldsetStyles.group}>
<legend className={fieldsetStyles.legend}>
<T>Scope</T>
</legend>
<label className={styles.reformatOption}>
<input
type="radio"
name="reformat-scope"
checked={!selectionOnly}
onChange={() => setSelectionOnly(false)}
/>
<T>Whole file</T>
</label>
<label className={clsx(styles.reformatOption, !popup.hasSelection && styles.disabled)}>
<input
type="radio"
name="reformat-scope"
checked={selectionOnly}
disabled={!popup.hasSelection}
onChange={() => setSelectionOnly(true)}
/>
<T>Selected text</T>
</label>
<Radio
name="reformat-scope"
checked={selectionOnly}
disabled={!popup.hasSelection}
onChange={() => setSelectionOnly(true)}
label="Selected text"
/>
<Radio
name="reformat-scope"
checked={!selectionOnly}
onChange={() => setSelectionOnly(false)}
label="Whole file"
/>
</fieldset>
<fieldset className={styles.reformatGroup}>
<legend className={styles.reformatLegend}>
<fieldset className={fieldsetStyles.group}>
<legend className={fieldsetStyles.legend}>
<T>Options</T>
</legend>
<Checkbox
+15
View File
@@ -199,6 +199,21 @@
align-items: center;
gap: var(--space-2);
}
.reformatSubject {
overflow-wrap: anywhere;
font-size: var(--fs-ui);
font-weight: 600;
}
.reformatMask {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--space-2);
}
.reformatMaskInput {
flex: 1 1 12ch;
min-width: 0;
}
.languageSelect {
min-width: 180px;
}
+41 -30
View File
@@ -29,6 +29,7 @@ import {
type StructuralForm,
} from "./structural";
import styles from "./Analysis.module.css";
import fieldsetStyles from "@/ui/DialogFieldset.module.css";
import { tx } from "@/platform/i18n";
import { notifications } from "@/workbench/contributions";
@@ -168,40 +169,50 @@ function ReformatCodeDialog({ targets, onClose }: { targets: readonly ReformatTa
{ label: "Cancel", role: "cancel" },
]}
>
<div className={styles.form}>
<div className={styles.hint}>{subject}</div>
{targets.some((t) => t.dir) && (
<div className={fieldsetStyles.body}>
<div className={styles.reformatSubject}>{subject}</div>
<fieldset className={fieldsetStyles.group}>
<legend className={fieldsetStyles.legend}>
<T>Options</T>
</legend>
<Checkbox
checked={options.recursive}
onChange={(recursive) => setOptions({ ...options, recursive })}
label="Include subdirectories"
checked={options.optimizeImports}
onChange={(optimizeImports) => setOptions({ ...options, optimizeImports })}
label="Optimize imports"
/>
)}
<Checkbox
checked={options.optimizeImports}
onChange={(optimizeImports) => setOptions({ ...options, optimizeImports })}
label="Optimize imports"
/>
<Checkbox
checked={options.changedTextOnly}
onChange={(changedTextOnly) => setOptions({ ...options, changedTextOnly })}
label="Only VCS changed text"
/>
<div className={styles.fieldRow}>
<Checkbox
checked={options.useMask}
onChange={(useMask) => setOptions({ ...options, useMask })}
label="File mask:"
checked={options.changedTextOnly}
onChange={(changedTextOnly) => setOptions({ ...options, changedTextOnly })}
label="Only VCS changed text"
/>
<Input
className={styles.grow}
value={options.mask}
disabled={!options.useMask}
placeholder="*.sh, *.py"
onChange={(e) => setOptions({ ...options, mask: e.target.value })}
aria-label="File mask"
/>
</div>
{targets.some((t) => t.dir) && (
<Checkbox
checked={options.recursive}
onChange={(recursive) => setOptions({ ...options, recursive })}
label="Include subdirectories"
/>
)}
</fieldset>
<fieldset className={fieldsetStyles.group}>
<legend className={fieldsetStyles.legend}>
<T>Filters</T>
</legend>
<div className={styles.reformatMask}>
<Checkbox
checked={options.useMask}
onChange={(useMask) => setOptions({ ...options, useMask })}
label="File mask:"
/>
<Input
className={styles.reformatMaskInput}
value={options.mask}
disabled={!options.useMask}
placeholder="*.sh, *.py"
onChange={(e) => setOptions({ ...options, mask: e.target.value })}
aria-label="File mask"
/>
</div>
</fieldset>
<div className={styles.hint}>
<T>Files are reformatted by their language's formatter and saved; files without one are skipped.</T>
</div>
+2
View File
@@ -2486,6 +2486,8 @@
"{length} selected items": "{length} selected items",
"Include subdirectories": "Include subdirectories",
"Only VCS changed text": "Only VCS changed text",
"Options": "Options",
"Filters": "Filters",
"Files are reformatted by their language's formatter and saved; files without one are skipped.": "Files are reformatted by their language's formatter and saved; files without one are skipped.",
"No changed files to reformat": "No changed files to reformat",
"No files to reformat": "No files to reformat",
+1
View File
@@ -8875,6 +8875,7 @@
"{length} selected items": "已选择 {length} 项",
"Include subdirectories": "包含子目录",
"Only VCS changed text": "仅 VCS 更改的文本",
"Filters": "筛选条件",
"Files are reformatted by their language's formatter and saved; files without one are skipped.": "文件由各自语言的格式化程序重新格式化并保存;没有格式化程序的文件将被跳过。",
"No changed files to reformat": "没有需要重新格式化的已更改文件",
"No files to reformat": "没有需要重新格式化的文件",
+24
View File
@@ -0,0 +1,24 @@
.body {
display: flex;
flex-direction: column;
gap: var(--space-3);
padding: var(--space-4);
font-size: var(--fs-ui);
}
.group {
display: flex;
flex-direction: column;
gap: var(--space-2);
min-inline-size: 0;
margin: 0;
padding: var(--space-2) 0 0;
border: 0;
border-block-start: 1px solid var(--border-popup);
}
.legend {
padding: 0 var(--space-2) 0 0;
color: var(--fg-strong);
font-weight: 600;
}