Compare commits

..
Author SHA1 Message Date
l0ng-ai 53502d2460 fix(editor): integrate usage access filters into the toolbars 2026-11-23 07:25:11 +08:00
l0ng-ai 844c2f3145 test(maven): wait for the background refresh of jdtls import roots (#5272)
external_maven_link_persists_reloads_and_unlink_keeps_files failed on the macOS runner: setting languages.java.maven.linkedProjects refreshes the language server's import roots on a blocking task, and the test read them right after build_model returned. It now waits up to 5 s for them to change.
2026-11-23 05:18:24 +08:00
12 changed files with 115 additions and 96 deletions

No files matched your search

+15 -2
View File
@@ -49,7 +49,7 @@ async fn external_maven_link_persists_reloads_and_unlink_keeps_files() {
assert_eq!(b.pom, canonical);
assert_eq!(dunce::canonicalize(root.join(&b.dir)).unwrap(), sibling);
assert_eq!(host.project("main").unwrap().content_roots(), vec![sibling.clone()]);
assert_eq!(host.project("main").unwrap().lsp.jdtls_import_roots(), vec![sibling.clone()]);
assert_eq!(import_roots(&host, |roots| !roots.is_empty()).await, vec![sibling.clone()]);
let reloaded = ops::build::build_model(&host, "main").await.unwrap();
assert_eq!(
@@ -63,13 +63,26 @@ async fn external_maven_link_persists_reloads_and_unlink_keeps_files() {
let gone = ops::build::build_model(&host, "main").await.unwrap();
assert!(gone.maven.unwrap().projects.iter().all(|p| p.artifact_id != "b"));
assert!(host.project("main").unwrap().content_roots().is_empty());
assert!(host.project("main").unwrap().lsp.jdtls_import_roots().is_empty());
assert!(import_roots(&host, |roots| roots.is_empty()).await.is_empty());
assert_eq!(saved(), Vec::<String>::new());
assert_eq!(std::fs::read_to_string(root.join("pom.xml")).unwrap(), a_pom);
assert_eq!(std::fs::read_to_string(sibling.join("pom.xml")).unwrap(), b_pom);
host.shutdown().await;
}
/// The language server's Maven import roots once `ready` holds: a settings change refreshes them in
/// the background.
async fn import_roots(host: &Host, ready: impl Fn(&[std::path::PathBuf]) -> bool) -> Vec<std::path::PathBuf> {
for _ in 0..200 {
let roots = host.project("main").unwrap().lsp.jdtls_import_roots();
if ready(&roots) {
return roots;
}
tokio::time::sleep(std::time::Duration::from_millis(25)).await;
}
host.project("main").unwrap().lsp.jdtls_import_roots()
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn reactor_module_beside_a_trusted_project_is_a_content_root_until_removed() {
let temp = tempfile::tempdir().unwrap();
-60
View File
@@ -85,66 +85,6 @@ test("⌘K commits the checked changes with the typed message", async ({ workben
await expect(changes.getByRole("checkbox", { name: "Include build.gradle.kts in commit" })).toBeHidden();
});
test("commit options align author fields and keep the date editable in a narrow dialog", async ({
workbench: page,
}) => {
await stubRepository(page);
await page.setViewportSize({ width: 1040, height: 700 });
await page.keyboard.press("Meta+k");
const panel = page.getByRole("region", { name: "Commit", exact: true });
await panel.getByRole("button", { name: "Commit Options", exact: true }).click();
const popup = page.getByRole("dialog", { name: "Commit Options", exact: true });
const author = popup.getByRole("textbox", { name: "Author", exact: true });
const date = popup.getByLabel("Author date", { exact: true });
const clear = popup.getByRole("button", { name: "Clear author date", exact: true });
const name = "Regional Ledger Review <[email protected]>";
const time = "2024-06-04T13:20:21";
await author.fill(name);
await date.fill(time);
const authorBox = (await author.boundingBox())!;
const dateBox = (await date.boundingBox())!;
const dateLabel = (await popup.getByText("Author date", { exact: true }).boundingBox())!;
const clearBox = (await clear.boundingBox())!;
expect(authorBox.x).toBeCloseTo(dateBox.x, 0);
expect(dateLabel.y).toBeGreaterThanOrEqual(dateBox.y);
expect(dateLabel.y).toBeLessThan(dateBox.y + dateBox.height);
expect(clearBox.x + clearBox.width).toBeCloseTo(authorBox.x + authorBox.width, 0);
await expect(clear).toBeInViewport({ ratio: 1 });
await page.keyboard.press("Escape");
await expect(popup).toBeHidden();
await page.evaluate(async () => {
const projectModule = "/src/platform/project.ts";
const { useProject } = await import(/* @vite-ignore */ projectModule);
const { settings } = useProject.getState();
useProject.setState({
settings: { ...settings, vcs: { ...settings?.vcs, commit: { ...settings?.vcs?.commit, nonModal: false } } },
});
});
await page.setViewportSize({ width: 650, height: 650 });
await page.keyboard.press("Meta+k");
const dialog = page.getByRole("dialog", { name: "Commit Changes", exact: true });
const options = dialog.getByRole("group", { name: "Commit Options", exact: true });
const compactAuthor = options.getByRole("textbox", { name: "Author", exact: true });
const compactDate = options.getByLabel("Author date", { exact: true });
const compactClear = options.getByRole("button", { name: "Clear author date", exact: true });
await expect(compactAuthor).toHaveValue(name);
await expect(compactDate).toHaveValue(time);
const labelBox = (await options.getByText("Author:", { exact: true }).boundingBox())!;
const inputBox = (await compactAuthor.boundingBox())!;
expect(inputBox.x).toBeCloseTo(labelBox.x, 0);
expect(inputBox.y).toBeGreaterThanOrEqual(labelBox.y + labelBox.height);
const box = (await compactDate.boundingBox())!;
const buttonBox = (await compactClear.boundingBox())!;
expect(box.width).toBeCloseTo(inputBox.width, 0);
expect(buttonBox.y).toBeGreaterThanOrEqual(box.y + box.height);
expect(await options.evaluate((node) => node.scrollWidth - node.clientWidth)).toBeLessThanOrEqual(1);
await compactClear.click();
await expect(compactDate).toHaveValue("");
await expect(compactClear).toBeHidden();
await expect(compactAuthor).toHaveValue(name);
});
test("the Commit window gives its message preferred focus", async ({ workbench: page }) => {
await stubRepository(page);
const stripe = page.locator('[data-stripe-button="commit"]');
+60
View File
@@ -1,6 +1,66 @@
import type { Locator } from "@playwright/test";
import { expect, stubDesktop, test } from "./fixtures";
test("Find Usages places read and write filters with the other actions", async ({ workbench: page }) => {
await stubDesktop(page);
await page.evaluate(async () => {
const modulePath = "/src/features/code-insight/usages.ts";
const { useUsagesPopup } = await import(modulePath);
const path = "/dev/acme-api/src/SettlementService.ts";
const lines = ["const current = settlement;", "settlement = next;"];
window.__ipc.handlers.fs_read_text = () => lines.join("\n");
useUsagesPopup.setState({
open: true,
anchor: { x: 100, y: 150 },
symbol: "settlement",
loading: false,
scope: "project",
groups: [
{
path,
usages: lines.map((text, line) => ({
path,
line,
col: text.indexOf("settlement"),
endCol: text.indexOf("settlement") + "settlement".length,
text,
access: line === 0 ? "read" : "write",
})),
},
],
});
});
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
const read = { name: "Show read accesses", exact: true };
const write = { name: "Show write accesses", exact: true };
const actions = popup.getByRole("button", { name: "Show Preview", exact: true }).locator("..");
await expect(popup.getByRole("option")).toHaveCount(2);
for (const width of [1120, 540]) {
await page.setViewportSize({ width, height: 640 });
expect(await actions.getByRole("toolbar", { name: "Usage access filters", exact: true }).count()).toBe(1);
await expect(actions.getByRole("button", read)).toBeInViewport({ ratio: 1 });
await expect(actions.getByRole("button", write)).toBeInViewport({ ratio: 1 });
}
await actions.getByRole("button", write).click();
await expect(popup.getByRole("option")).toHaveCount(1);
await popup.getByRole("button", { name: /Open in Find Window/ }).click();
const view = page.getByRole("region", { name: "Find Usages", exact: true });
const toolbar = view.getByRole("toolbar", { name: "Usages actions", exact: true });
const readButton = toolbar.getByRole("button", read);
const writeButton = toolbar.getByRole("button", write);
await expect(readButton).toHaveAttribute("aria-pressed", "true");
await expect(writeButton).toHaveAttribute("aria-pressed", "false");
const a = (await readButton.boundingBox())!;
const b = (await writeButton.boundingBox())!;
expect(a.x).toBeCloseTo(b.x, 0);
expect(b.y).toBeGreaterThanOrEqual(a.y + a.height);
await expect(view.locator("mark")).toHaveCount(1);
await writeButton.click();
await expect(view.locator("mark")).toHaveCount(2);
});
async function checkSize(icon: Locator, size = 16) {
const dimensions = await icon.evaluate((node) => {
const style = getComputedStyle(node);
@@ -2,6 +2,8 @@
display: flex;
align-items: center;
gap: var(--space-0-5);
padding: 3px 6px;
flex-shrink: 0;
flex: none;
}
.vertical {
flex-direction: column;
}
@@ -1,4 +1,6 @@
import { create } from "zustand";
import clsx from "clsx";
import { useTx } from "@/platform/i18n";
import { IconButton } from "@/ui";
import type { Usage } from "./usages";
import styles from "./UsageAccessFilter.module.css";
@@ -45,11 +47,16 @@ export function filterUsageAccess(items: readonly Usage[], options: UsageAccessO
export const supportsUsageAccess = (items: readonly Usage[]) => items.some((u) => u.access && u.access !== "unknown");
export function UsageAccessFilter({ items }: { items: readonly Usage[] }) {
export function UsageAccessFilter({ items, vertical }: { items: readonly Usage[]; vertical?: boolean }) {
const tx = useTx();
const options = useUsageAccessOptions();
if (!supportsUsageAccess(items)) return null;
return (
<div className={styles.toolbar} role="toolbar" aria-label="Usage access filters">
<div
className={clsx(styles.toolbar, vertical && styles.vertical)}
role={vertical ? "group" : "toolbar"}
aria-label={tx("Usage access filters")}
>
<IconButton
icon="show-read-access"
size="small"
+1 -1
View File
@@ -176,6 +176,7 @@ function UsagesPopupInner() {
</span>
</span>
<div className={styles.actions}>
<UsageAccessFilter items={all} />
{scope && (
<Select<UsageScope>
variant="ghost"
@@ -213,7 +214,6 @@ function UsagesPopupInner() {
</button>
</div>
</div>
<UsageAccessFilter items={all} />
{note && (
<div className={styles.note} data-testid="usages-note">
{note}
@@ -17,8 +17,11 @@
gap: var(--space-0-5);
padding: 4px 0;
border-right: 1px solid var(--border);
overflow-y: auto;
scrollbar-width: none;
}
.toolbarSep {
flex: none;
width: 16px;
height: 1px;
margin: 3px 0;
@@ -66,7 +69,6 @@
flex: 1;
min-height: 0;
}
.body > [role="toolbar"],
.body > .summary {
flex: 0 0 auto;
}
+1 -1
View File
@@ -284,11 +284,11 @@ export function UsagesView() {
<IconButton icon="arrow-up" action="navigate.prevOccurrence" size="small" iconSize={16} />
<IconButton icon="arrow-down" action="navigate.nextOccurrence" size="small" iconSize={16} />
<span className={styles.toolbarSep} />
<UsageAccessFilter items={allUsages} vertical />
<IconButton icon="expand-all" title="Expand All" size="small" iconSize={16} onClick={() => setAll(false)} />
<IconButton icon="collapse-all" title="Collapse All" size="small" iconSize={16} onClick={() => setAll(true)} />
</div>
<div className={styles.body} onKeyDown={onKeyDown}>
<UsageAccessFilter items={allUsages} />
{!search.loading && !search.error && search.scope === "project" && (
<div className={styles.summary}>
<T>Usages in Project Files</T>
@@ -53,7 +53,7 @@ it("shows a plain count for unclassified searches after a Java access mode was s
});
const view = render(<UsagesView />);
expect(screen.getByText("2 results")).toBeInTheDocument();
expect(screen.queryByRole("toolbar", { name: "Usage access filters" })).toBeNull();
expect(screen.queryByRole("group", { name: "Usage access filters" })).toBeNull();
view.unmount();
useUsageAccessOptions.setState({ read: true, write: true });
useUsages.setState({ tabs: [], active: null });
+7 -7
View File
@@ -33,17 +33,15 @@ export function CommitAuthorFields({
focusAuthor?: boolean;
onChange: (update: Partial<CommitAuthor>) => void;
}) {
const authorId = useId();
const authorDateId = useId();
const date = authorDate ? new Date(authorDate) : null;
return (
<div className={styles.optIdentity}>
<div className={styles.optIdentityFields}>
<label htmlFor={authorId}>
<>
<label className={styles.optField}>
<span>
<T>Author:</T>
</label>
</span>
<Input
id={authorId}
value={author}
title={tx(
preserveOriginal
@@ -55,6 +53,8 @@ export function CommitAuthorFields({
autoSelect={focusAuthor}
onChange={(e) => onChange({ author: e.target.value })}
/>
</label>
<div className={styles.optDate}>
<label htmlFor={authorDateId}>
<T>Author date</T>
</label>
@@ -81,6 +81,6 @@ export function CommitAuthorFields({
)}
</div>
</div>
</div>
</>
);
}
+13 -19
View File
@@ -309,7 +309,7 @@
}
/* Commit Options popup (gear next to Commit). */
.options {
width: 384px;
width: 340px;
max-height: min(560px, 80vh);
overflow: auto;
padding: 4px 16px 12px;
@@ -350,35 +350,29 @@
flex: 1;
min-width: 0;
}
.optIdentity {
container-type: inline-size;
}
.optIdentityFields {
display: grid;
grid-template-columns: minmax(0, 1fr);
.optField {
display: flex;
align-items: center;
gap: var(--space-1) var(--space-2);
gap: var(--space-2);
color: var(--fg);
font-size: var(--fs-ui);
}
.optIdentityFields > label {
overflow-wrap: anywhere;
.optField > :last-child {
flex: 1;
min-width: 0;
}
@container (min-width: 328px) {
.optIdentityFields {
grid-template-columns: fit-content(32%) minmax(0, 1fr);
row-gap: var(--space-1-5);
}
.optDate {
display: flex;
flex-direction: column;
gap: var(--space-1);
color: var(--fg);
}
.optDateInput {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: flex-end;
gap: var(--space-1);
}
.optDateInput input {
flex: 1 1 min(100%, 212px);
flex: 1;
min-width: 0;
}
.optLink {
+1
View File
@@ -1578,6 +1578,7 @@
"Read the project's resolved Maven and Gradle dependencies": "Read the project's resolved Maven and Gradle dependencies",
"Resolved Dependencies": "Resolved Dependencies",
"Usages of {symbol}": "Usages of {symbol}",
"Usage access filters": "Usage access filters",
"Read the clipboard's text and images when you run one of its commands": "Read the clipboard's text and images when you run one of its commands",
"Output: {channel}": "Output: {channel}",
"You can close this tab.": "You can close this tab.",