Порівняти коміти

...
5 змінених файлів з 252 додано та 84 видалено

No files matched your search

+64
Переглянути файл
@@ -427,6 +427,70 @@ test("Find Usages from the editor context menu lists every usage by file and ope
).toHaveAttribute("aria-selected", "true");
});
test("usage locations and preview stay readable as the available space changes", async ({ workbench: page }) => {
await page.setViewportSize({ width: 1040, height: 760 });
const editor = await openSample(page);
await page.evaluate(
({ file, other }) => {
const locations = [
{ path: file, range: { start: { line: 16, col: 8 }, end: { line: 16, col: 15 } } },
{ path: file, range: { start: { line: 20, col: 27 }, end: { line: 20, col: 34 } } },
{ path: other, range: { start: { line: 0, col: 0 }, end: { line: 0, col: 7 } } },
];
window.__ipc.handlers.lsp_references = () => ({
locations,
classified: [{ location: locations[2], kind: "code", text: "service.submit(order)" }],
incomplete: null,
librariesSkipped: true,
});
},
{ file: FILE, other: `${ROOT}/domain/checkout/processing/calculations/PaymentProcessingService.kt` },
);
await caretAt(editor, page, "val order: Order", "service");
await page.keyboard.press("Meta+Alt+F7");
const popup = page.getByRole("dialog", { name: "Usages" });
const scope = popup.getByRole("button", { name: "Scope" });
const openWindow = popup.getByRole("button", { name: /^Open in Find Window/ });
await expect(popup.getByTestId("usage-row")).toHaveCount(3);
await popup.getByRole("button", { name: "Show Preview" }).click();
const code = popup.getByRole("region", { name: "Preview" });
await expect(code.locator(".cm-content")).toContainText("service.find(status");
await page.setViewportSize({ width: 480, height: 470 });
const within = async (child: Locator, parent: Locator) => {
const [c, p] = await Promise.all([child.boundingBox(), parent.boundingBox()]);
return (
!!c &&
!!p &&
c.x >= p.x - 1 &&
c.y >= p.y - 1 &&
c.x + c.width <= p.x + p.width + 1 &&
c.y + c.height <= p.y + p.height + 1
);
};
await expect.poll(() => within(scope, popup)).toBe(true);
await expect.poll(() => within(openWindow, popup)).toBe(true);
await expect.poll(() => within(code, popup)).toBe(true);
const results = popup.getByRole("listbox", { name: "Usages" });
await expect.poll(() => within(popup.getByTestId("usage-row").last(), results)).toBe(true);
const firstRow = popup.getByTestId("usage-row").first();
const file = firstRow.getByText("build.gradle.kts", { exact: true });
await expect(file).toBeVisible();
const [filename, snippet] = await Promise.all([file.boundingBox(), firstRow.locator("mark").boundingBox()]);
expect(filename!.x + filename!.width).toBeLessThan(snippet!.x);
await openWindow.click();
const tree = page.getByRole("tree", { name: "Usages" });
const target = tree.getByRole("treeitem", { name: /^17 service\.find\(status/ });
await target.click();
const preview = page.getByRole("region", { name: "Preview" });
await expect(preview).toContainText("service.find(status");
await expect.poll(async () => (await preview.boundingBox())!.y > (await tree.boundingBox())!.y).toBe(true);
await page.setViewportSize({ width: 1040, height: 760 });
await expect.poll(async () => (await preview.boundingBox())!.x > (await tree.boundingBox())!.x).toBe(true);
await expect(preview).toContainText("service.find(status");
});
test("⇧F6 renames in place and sends the server's edit to be applied", async ({ workbench: page }) => {
const editor = await openSample(page);
await page.evaluate(
+54 -17
Переглянути файл
@@ -5,18 +5,27 @@
overflow: hidden;
}
.header {
height: 26px;
flex: none;
display: flex;
align-items: center;
gap: var(--space-2);
padding: 0 10px;
flex-wrap: wrap;
min-height: var(--h-field);
gap: var(--space-0-5) var(--space-2);
padding: var(--space-0-5) 10px;
border-bottom: 1px solid var(--border-popup);
font-size: var(--fs-small);
font-size: var(--fs-ui);
color: var(--fg-muted);
}
.actions {
display: flex;
align-items: center;
flex-wrap: wrap;
min-width: 0;
gap: var(--space-0-5) var(--space-2);
font-size: var(--fs-small);
}
.scope {
flex: none;
max-width: min(100%, 18em);
}
.searching {
@@ -26,23 +35,32 @@
}
.title {
flex: 1;
flex: 1 1 160px;
display: flex;
align-items: baseline;
gap: var(--space-1);
min-width: 0;
color: var(--fg-emphasis);
}
.titleLabel {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--fg-emphasis);
}
.count {
flex: none;
white-space: nowrap;
font-size: var(--fs-small);
color: var(--fg-subtle);
}
.link {
flex: none;
max-width: 100%;
border: none;
background: none;
padding: 0;
font: inherit;
color: var(--link);
text-align: left;
cursor: pointer;
}
.link:hover {
@@ -52,7 +70,6 @@
.body {
display: flex;
flex-direction: column;
min-height: 24px;
padding: 2px 0;
box-sizing: content-box;
}
@@ -60,21 +77,31 @@
flex: 1;
}
.row {
display: flex;
display: grid;
grid-template-columns: min(34%, 176px) 5ch minmax(0, 1fr);
align-items: center;
gap: var(--space-2);
min-width: 0;
width: 100%;
}
.file {
display: flex;
align-items: center;
gap: var(--space-1);
min-width: 0;
}
.icon {
flex: none;
color: var(--fg-muted);
}
.spacer {
flex: 1;
.fileName {
overflow: hidden;
text-overflow: ellipsis;
}
.where {
flex: none;
.line {
overflow: hidden;
text-align: right;
font-variant-numeric: tabular-nums;
font-size: var(--fs-small);
color: var(--fg-subtle);
}
@@ -95,12 +122,15 @@
outline: none;
}
.filter {
flex: none;
max-width: 12ch;
font-family: var(--font-mono);
color: var(--fg-strong);
background: var(--accent-soft);
border-radius: var(--radius-small);
padding: 0 4px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.noMatch {
color: var(--danger);
@@ -111,8 +141,9 @@
font-size: var(--fs-small);
}
.preview {
flex: none;
height: 200px;
flex: 0 1 auto;
height: min(164px, 32vh);
min-height: min(64px, 18vh);
border-top: 1px solid var(--border-popup);
overflow: hidden;
}
@@ -131,3 +162,9 @@
.previewMatch {
background: var(--bg-text-search-result);
}
@media (max-width: 600px) {
.title {
flex-basis: 100%;
}
}
+49 -41
Переглянути файл
@@ -93,6 +93,7 @@ function UsagesPopupInner() {
const [active, setActive] = useState(0);
const current = Math.min(active, items.length - 1);
const total = usageCount(groups);
const rowCount = Math.max(1, Math.min(14, items.length));
const pick = (u: Usage | undefined) => {
if (!u) return;
close();
@@ -158,46 +159,48 @@ function UsagesPopupInner() {
>
<div className={styles.header}>
<span className={styles.title}>
{symbol ? tx`Usages of ${symbol}` : tx("Usages")}{" "}
<span className={styles.titleLabel}>{symbol ? tx`Usages of ${symbol}` : tx("Usages")}</span>{" "}
<span className={styles.count}>
{filter || items.length !== total ? tx`${items.length} of ${total} found` : tx`${total} found`}
</span>
</span>
{scope && (
<Select<UsageScope>
variant="ghost"
aria-label={tx("Scope")}
className={styles.scope}
value={scope}
options={[
{ value: "project", label: tx("Project Files") },
{ value: "libraries", label: tx("Project and Libraries") },
]}
onChange={setUsagesPopupScope}
<div className={styles.actions}>
{scope && (
<Select<UsageScope>
variant="ghost"
aria-label={tx("Scope")}
className={styles.scope}
value={scope}
options={[
{ value: "project", label: tx("Project Files") },
{ value: "libraries", label: tx("Project and Libraries") },
]}
onChange={setUsagesPopupScope}
/>
)}
{loading && (
<span className={styles.searching} role="status" aria-label={tx("Searching for more usages")}>
<Spinner size={16} variant="spokes" />
</span>
)}
{filter && (
<span className={clsx(styles.filter, !items.length && styles.noMatch)} role="status">
{filter}
</span>
)}
<IconButton
icon="preview-details"
size="small"
title="Show Preview"
pressed={preview}
onMouseDown={(e) => e.preventDefault()}
onClick={() => setUsagesPopupPreview(!preview)}
/>
)}
{loading && (
<span className={styles.searching} role="status" aria-label={tx("Searching for more usages")}>
<Spinner size={16} variant="spokes" />
</span>
)}
{filter && (
<span className={clsx(styles.filter, !items.length && styles.noMatch)} role="status">
{filter}
</span>
)}
<IconButton
icon="preview-details"
size="small"
title="Show Preview"
pressed={preview}
onMouseDown={(e) => e.preventDefault()}
onClick={() => setUsagesPopupPreview(!preview)}
/>
<button type="button" className={styles.link} onClick={openInFindWindow}>
{tx("Open in Find Window")}
{keys ? ` ${keys}` : ""}
</button>
<button type="button" className={styles.link} onClick={openInFindWindow}>
{tx("Open in Find Window")}
{keys ? ` ${keys}` : ""}
</button>
</div>
</div>
<UsageAccessFilter items={all} />
{note && (
@@ -205,7 +208,10 @@ function UsagesPopupInner() {
{note}
</div>
)}
<div className={styles.body} style={{ height: Math.max(1, Math.min(14, items.length)) * ROW }}>
<div
className={styles.body}
style={{ height: rowCount * ROW, minHeight: `min(${Math.min(rowCount, 3) * ROW}px, 18vh)` }}
>
<List
items={items}
getKey={(u) =>
@@ -225,12 +231,14 @@ function UsagesPopupInner() {
}
renderItem={(u) => (
<div className={styles.row} data-testid="usage-row" data-path={u.path} data-line={u.line}>
<Icon name={fileIconName(basename(u.path), u.path)} size={16} className={styles.icon} />
<UsagePreview usage={u} />
<span className={styles.spacer} />
<span className={styles.where}>
{basename(u.path)}:{u.line + 1}
<span className={styles.file}>
<Icon name={fileIconName(basename(u.path), u.path)} size={16} className={styles.icon} />
<span className={styles.fileName} title={u.path}>
{basename(u.path)}
</span>
</span>
<span className={styles.line}>{u.line + 1}</span>
<UsagePreview usage={u} />
</div>
)}
/>
+32 -7
Переглянути файл
@@ -25,15 +25,15 @@
background: var(--border);
}
.summary {
height: 26px;
min-height: 26px;
flex: none;
display: flex;
align-items: center;
gap: var(--space-1-5);
padding: 0 10px;
flex-wrap: wrap;
gap: var(--space-0-5) var(--space-1-5);
padding: var(--space-0-5) 10px;
font-size: var(--fs-ui);
color: var(--fg-subtle);
white-space: nowrap;
}
.groupLabel {
color: var(--fg);
@@ -42,12 +42,13 @@
color: var(--danger);
}
.link {
flex: none;
max-width: 100%;
border: none;
background: none;
padding: 0;
font: inherit;
color: var(--link);
text-align: left;
cursor: pointer;
}
.link:hover {
@@ -81,9 +82,18 @@
flex: none;
}
.file {
flex: none;
max-width: 56%;
overflow: hidden;
text-overflow: ellipsis;
color: var(--fg);
}
.muted,
.directory {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
color: var(--fg-subtle);
}
.count {
flex: none;
color: var(--fg-subtle);
@@ -101,7 +111,7 @@
overflow: hidden;
text-overflow: ellipsis;
font-family: var(--font-mono);
font-size: var(--fs-ui);
font-size: var(--fs-code);
color: var(--fg);
}
.match {
@@ -135,3 +145,18 @@
flex: 1;
min-height: 0;
}
.splitFrame {
display: flex;
min-width: 0;
}
.sourcePreview {
display: flex;
flex-direction: column;
font-family: var(--font-mono);
font-size: var(--fs-code);
line-height: 1.45;
}
.sourcePreview .sourceText[role="region"] {
font: inherit;
font-weight: var(--fw-code);
}
+53 -19
Переглянути файл
@@ -2,11 +2,13 @@
* "usages" tool window: Find Usages results grouped by file with line
* previews, one tab per search (pinnable, as the Find tool window's tabs).
*/
import { useCallback, useMemo, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
import { useCallback, useLayoutEffect, useMemo, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
import clsx from "clsx";
import { create } from "zustand";
import { previewColors, tokenSpans, useLineTokens } from "@/editor/lineTokens";
import { formatMessage, useTx } from "@/platform/i18n";
import { useEditorPrefs } from "@/platform/editorSettings";
import { BUNDLED_MONO_FAMILY, monoFontFamily } from "@/platform/fonts";
import { shortcutLabel } from "@/platform/keymap";
import { basename, relativeDir, useProject } from "@/platform/project";
import { maybeEditorService, useOccurrenceNavigator } from "@/workbench/contributions";
@@ -245,8 +247,12 @@ export function UsagesView() {
return (
<span className={clsx(styles.row, isExcluded(n) && styles.excluded)}>
<Icon name={fileIconName(basename(path), path)} size={16} className={styles.icon} />
<span className={styles.file}>{basename(path)}</span>
<span className={styles.muted}>{relativeDir(root, path)}</span>
<span className={styles.file} title={path}>
{basename(path)}
</span>
<span className={styles.directory} title={path}>
{relativeDir(root, path)}
</span>
<span className={styles.count}>
{n.group.usages.length} {tx(n.group.usages.length === 1 ? "usage" : "usages")}
</span>
@@ -401,34 +407,62 @@ export function useUsagesHeaderMenu(): MenuItem[] {
function UsagesSplit({ preview, children }: { preview: ReactNode; children: ReactNode }) {
const show = useUsagesOptions((s) => s.preview);
const frame = useRef<HTMLDivElement>(null);
const [stacked, setStacked] = useState(false);
useLayoutEffect(() => {
const el = frame.current;
if (!show || !el) return;
const measure = () => setStacked(el.clientWidth < 580);
measure();
if (typeof ResizeObserver === "undefined") return;
const observer = new ResizeObserver(measure);
observer.observe(el);
return () => observer.disconnect();
}, [show]);
if (!show) return children;
return (
<SplitGroup orientation="horizontal" id="usages-preview-split" storageKey="openidea.usages.previewSplit">
<SplitPanel id="usages" minSize={160} className={styles.panel}>
{children}
</SplitPanel>
<SplitHandle />
<SplitPanel id="preview" minSize={160} defaultSize="45%" className={styles.panel}>
{preview}
</SplitPanel>
</SplitGroup>
<div ref={frame} className={styles.splitFrame}>
<SplitGroup
orientation={stacked ? "vertical" : "horizontal"}
id="usages-preview-split"
storageKey={stacked ? "openidea.usages.previewSplit.vertical" : "openidea.usages.previewSplit"}
>
<SplitPanel id="usages" minSize={stacked ? "30%" : 160} className={styles.panel}>
{children}
</SplitPanel>
<SplitHandle />
<SplitPanel id="preview" minSize={stacked ? "30%" : 160} defaultSize="45%" className={styles.panel}>
{preview}
</SplitPanel>
</SplitGroup>
</div>
);
}
function UsagesPreview({ node }: { node: Node | null }) {
const usage = node?.kind === "usage" ? node.usage : node?.kind === "file" ? (node.group.usages[0] ?? null) : null;
const search = useUsages(activeUsageSearch);
const settings = useProject((s) => s.settings?.editor);
const { fallbackFont } = useEditorPrefs();
const family = settings?.fontFamily;
const fontFamily =
(family && family !== BUNDLED_MONO_FAMILY) || fallbackFont.trim()
? monoFontFamily(family, fallbackFont, "var(--font-mono)")
: undefined;
const highlights = useMemo(() => {
const group = usage && search?.groups.find((g) => g.path === usage.path);
return (group?.usages ?? []).map((u) => ({ line: u.line, ranges: [[u.col, u.endCol] as const] }));
}, [usage, search?.groups]);
return (
<SourcePreview
path={usage?.path ?? null}
line={usage?.line ?? 0}
highlights={highlights}
load={previewText}
colorize={previewColors}
/>
<div className={styles.sourcePreview} style={{ fontFamily, fontSize: settings?.fontSize ?? undefined }}>
<SourcePreview
path={usage?.path ?? null}
line={usage?.line ?? 0}
highlights={highlights}
load={previewText}
colorize={previewColors}
className={styles.sourceText}
/>
</div>
);
}