дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-21 09:00:49 +02:00
Порівняти коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
4f788591f2 | ||
|
|
5621a429e9 |
No files matched your search
@@ -498,6 +498,85 @@ test("indexed single-file rename previews all anchors and applies only after con
|
||||
expect(apply.edit).toMatchObject({ preconditions: [{ path: FILE, hash: "indexed-snapshot" }] });
|
||||
});
|
||||
|
||||
test("intention previews fit narrow windows and wrap long code lines", async ({ workbench: page }) => {
|
||||
await page.setViewportSize({ width: 1600, height: 900 });
|
||||
const editor = await openSample(page);
|
||||
await page.evaluate(async () => {
|
||||
const path = "/src/platform/project.ts";
|
||||
const { useProject } = await import(/* @vite-ignore */ path);
|
||||
const { settings } = useProject.getState();
|
||||
useProject.setState({ settings: { ...settings, editor: { ...settings?.editor, fontSize: 16 } } });
|
||||
});
|
||||
await expect(editor.locator(".cm-content")).toHaveCSS("font-size", "16px");
|
||||
const replacement = "com.acme.orders." + "SharedDevelopmentOrderModel".repeat(6);
|
||||
await page.evaluate(
|
||||
({ file, replacement, edit }) => {
|
||||
window.__ipc.handlers.lsp_code_actions = () => [
|
||||
{
|
||||
title: "Replace Order with the fully qualified shared development order model",
|
||||
kind: "quickfix",
|
||||
isPreferred: true,
|
||||
disabledReason: null,
|
||||
edit: { files: [{ kind: "edit", path: file, edits: [{ range: edit, new_text: replacement }] }] },
|
||||
command: null,
|
||||
data: null,
|
||||
server: 1,
|
||||
},
|
||||
...Array.from({ length: 11 }, (_, i) => ({
|
||||
title: `Create alternative Order model ${i + 1}`,
|
||||
kind: "quickfix",
|
||||
isPreferred: false,
|
||||
disabledReason: null,
|
||||
edit: null,
|
||||
command: null,
|
||||
data: null,
|
||||
server: 1,
|
||||
})),
|
||||
];
|
||||
window.__ipc.handlers.lsp_execute_code_action = () => [];
|
||||
},
|
||||
{ file: FILE, replacement, edit: range(20, 19, 24) },
|
||||
);
|
||||
await caretAt(editor, page, "val order: Order", "Order ");
|
||||
await page.keyboard.press("Alt+Enter");
|
||||
const popup = page.getByRole("dialog", { name: "Intentions", exact: true });
|
||||
const options = popup.getByRole("listbox", { name: "Intentions" });
|
||||
const preview = popup.locator('[aria-label="Preview"]');
|
||||
await expect(preview.locator("pre")).toContainText(replacement);
|
||||
const wide = (await options.boundingBox())!;
|
||||
const widePreview = (await preview.boundingBox())!;
|
||||
expect(widePreview.x).toBeGreaterThanOrEqual(wide.x + wide.width - 1);
|
||||
|
||||
await page.setViewportSize({ width: 1050, height: 900 });
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const list = (await options.boundingBox())!;
|
||||
const code = (await preview.boundingBox())!;
|
||||
return code.x + code.width - list.x;
|
||||
})
|
||||
.toBeLessThanOrEqual(1);
|
||||
|
||||
await page.setViewportSize({ width: 520, height: 540 });
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const menu = (await popup.boundingBox())!;
|
||||
const list = (await options.boundingBox())!;
|
||||
const code = (await preview.boundingBox())!;
|
||||
return {
|
||||
popupFits: menu.x >= 0 && menu.y >= 0 && menu.x + menu.width <= 521 && menu.y + menu.height <= 541,
|
||||
previewBelow: code.y >= list.y + list.height - 1,
|
||||
previewFits: code.x >= menu.x && code.x + code.width <= menu.x + menu.width + 1,
|
||||
};
|
||||
})
|
||||
.toEqual({ popupFits: true, previewBelow: true, previewFits: true });
|
||||
expect(await preview.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
|
||||
await expect(preview.locator("pre")).toHaveCSS("font-size", "16px");
|
||||
await expect(options).toBeFocused();
|
||||
await page.keyboard.press("Enter");
|
||||
await expect(popup).toBeHidden();
|
||||
await expect.poll(() => ipcCalls(page, "lsp_execute_code_action")).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("diagnostics underline the range and ⌥⏎ applies the preferred quick fix", async ({ workbench: page }) => {
|
||||
const editor = await openSample(page);
|
||||
await page.evaluate(
|
||||
|
||||
@@ -30,8 +30,7 @@
|
||||
}
|
||||
.withPreview {
|
||||
flex-direction: row;
|
||||
width: auto;
|
||||
max-width: min(1160px, 94vw);
|
||||
min-width: 0;
|
||||
}
|
||||
.listMain {
|
||||
display: flex;
|
||||
@@ -39,6 +38,11 @@
|
||||
min-width: 0;
|
||||
flex: none;
|
||||
}
|
||||
.withPreview .listMain {
|
||||
flex: 1 1 320px;
|
||||
min-width: 300px;
|
||||
min-height: 0;
|
||||
}
|
||||
.mnemonic {
|
||||
width: 10px;
|
||||
flex: none;
|
||||
@@ -48,14 +52,39 @@
|
||||
text-align: right;
|
||||
}
|
||||
.previewPanel {
|
||||
width: 420px;
|
||||
flex: none;
|
||||
flex: 0 1 var(--list-preview-width);
|
||||
min-width: 300px;
|
||||
min-height: 60px;
|
||||
max-height: 340px;
|
||||
max-height: 300px;
|
||||
overflow: auto;
|
||||
border-left: 1px solid var(--border-popup);
|
||||
background: var(--bg-popup-inline, var(--bg-elev));
|
||||
}
|
||||
.previewLeft {
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
.previewLeft .previewPanel {
|
||||
border-left: 0;
|
||||
border-right: 1px solid var(--border-popup);
|
||||
}
|
||||
.previewBelow {
|
||||
flex-direction: column;
|
||||
}
|
||||
.previewBelow .listMain {
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
}
|
||||
.previewBelow .previewPanel {
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
max-height: min(300px, 40vh);
|
||||
border-left: 0;
|
||||
border-top: 1px solid var(--border-popup);
|
||||
}
|
||||
.previewBelow .previewPanel[aria-busy] {
|
||||
height: 60px;
|
||||
}
|
||||
.previewText {
|
||||
padding: 8px 10px;
|
||||
font-size: var(--fs-small);
|
||||
@@ -66,12 +95,13 @@
|
||||
padding: 6px 0;
|
||||
font-family: var(--openidea-editor-font, var(--font-mono));
|
||||
font-weight: var(--fw-code);
|
||||
font-size: var(--fs-small);
|
||||
font-size: var(--openidea-editor-font-size, var(--fs-code));
|
||||
color: var(--fg-editor);
|
||||
}
|
||||
.diffLine {
|
||||
padding: 0 10px;
|
||||
white-space: pre;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
min-height: 1.4em;
|
||||
}
|
||||
.diff-added {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/** React popups for LSP editor features, rendered as a workbench overlay. */
|
||||
import { useEffect, useMemo, useRef, useState, type KeyboardEvent } from "react";
|
||||
import { useEffect, useMemo, useRef, useState, type CSSProperties, type KeyboardEvent } from "react";
|
||||
import clsx from "clsx";
|
||||
import {
|
||||
Checkbox,
|
||||
@@ -49,11 +49,17 @@ function ItemIcon({ item }: { item: ListPopupItem }) {
|
||||
return <span className={styles.iconSpacer} />;
|
||||
}
|
||||
|
||||
function ListPreviewPanel({ preview }: { preview: ListPreview | null | "loading" }) {
|
||||
function ListPreviewPanel({
|
||||
preview,
|
||||
themeClasses,
|
||||
}: {
|
||||
preview: ListPreview | null | "loading";
|
||||
themeClasses?: string;
|
||||
}) {
|
||||
if (preview === "loading") return <div className={styles.previewPanel} aria-busy="true" />;
|
||||
if (!preview) return null;
|
||||
return (
|
||||
<div className={styles.previewPanel} aria-label={tx("Preview")}>
|
||||
<div className={clsx(styles.previewPanel, themeClasses)} role="region" aria-label={tx("Preview")}>
|
||||
{preview.kind === "text" ? (
|
||||
<div className={styles.previewText}>{preview.text}</div>
|
||||
) : (
|
||||
@@ -70,6 +76,9 @@ function ListPreviewPanel({ preview }: { preview: ListPreview | null | "loading"
|
||||
);
|
||||
}
|
||||
|
||||
const LIST_PREVIEW_WIDTH = 420;
|
||||
const MIN_SIDE_BY_SIDE_WIDTH = 660;
|
||||
|
||||
function ListPopup({ popup }: { popup: Extract<LspPopup, { kind: "list" }> }) {
|
||||
const [query, setQuery] = useState("");
|
||||
const filtered = useMemo(() => {
|
||||
@@ -91,6 +100,13 @@ function ListPopup({ popup }: { popup: Extract<LspPopup, { kind: "list" }> }) {
|
||||
|
||||
const [preview, setPreview] = useState<{ id: string; data: ListPreview | null } | null>(null);
|
||||
const fetchPreview = popup.preview;
|
||||
const [viewportWidth, setViewportWidth] = useState(() => window.innerWidth);
|
||||
useEffect(() => {
|
||||
if (!fetchPreview) return;
|
||||
const resize = () => setViewportWidth(window.innerWidth);
|
||||
window.addEventListener("resize", resize);
|
||||
return () => window.removeEventListener("resize", resize);
|
||||
}, [fetchPreview]);
|
||||
useEffect(() => {
|
||||
if (!fetchPreview || !activeItem || activeItem.disabled) return;
|
||||
const ctrl = new AbortController();
|
||||
@@ -164,22 +180,46 @@ function ListPopup({ popup }: { popup: Extract<LspPopup, { kind: "list" }> }) {
|
||||
? ("loading" as const)
|
||||
: null
|
||||
: null;
|
||||
const hasPreview = shownPreview !== null;
|
||||
const previewBelow = hasPreview && viewportWidth <= MIN_SIDE_BY_SIDE_WIDTH;
|
||||
const previewLeft =
|
||||
hasPreview &&
|
||||
!previewBelow &&
|
||||
popup.anchor.x + width + LIST_PREVIEW_WIDTH > viewportWidth - 6 &&
|
||||
popup.anchor.x >= LIST_PREVIEW_WIDTH + 6;
|
||||
const anchor = useMemo(() => {
|
||||
if (!fetchPreview) return popup.anchor;
|
||||
const x = popup.anchor.x - (previewLeft ? LIST_PREVIEW_WIDTH : 0);
|
||||
return {
|
||||
getBoundingClientRect: () =>
|
||||
new DOMRect(
|
||||
Math.max(0, Math.min(x, window.innerWidth)),
|
||||
Math.max(0, Math.min(popup.anchor.y, window.innerHeight)),
|
||||
0,
|
||||
0,
|
||||
),
|
||||
};
|
||||
}, [fetchPreview, popup.anchor, previewLeft]);
|
||||
const popupSize = {
|
||||
width: hasPreview ? width + LIST_PREVIEW_WIDTH : width,
|
||||
"--list-preview-width": `${LIST_PREVIEW_WIDTH}px`,
|
||||
} as CSSProperties;
|
||||
const indexOf = (item: ListPopupItem) => popup.items.indexOf(item);
|
||||
return (
|
||||
<Popup
|
||||
open
|
||||
anchor={popup.anchor}
|
||||
anchor={anchor}
|
||||
onClose={closePopup}
|
||||
aria-label={popup.title}
|
||||
className={clsx(styles.listPopup, popup.preview && styles.withPreview)}
|
||||
style={popup.preview ? undefined : { width }}
|
||||
className={clsx(
|
||||
styles.listPopup,
|
||||
hasPreview && styles.withPreview,
|
||||
previewBelow && styles.previewBelow,
|
||||
previewLeft && styles.previewLeft,
|
||||
)}
|
||||
style={popupSize}
|
||||
>
|
||||
<div
|
||||
className={styles.listMain}
|
||||
style={popup.preview ? { width } : undefined}
|
||||
data-testid="list-popup"
|
||||
aria-busy={popup.busy || undefined}
|
||||
>
|
||||
<div className={styles.listMain} data-testid="list-popup" aria-busy={popup.busy || undefined}>
|
||||
<div className={styles.listHeader}>
|
||||
<span className={styles.listTitle}>{popup.title}</span>
|
||||
{popup.busy && <Spinner size={12} />}
|
||||
@@ -260,7 +300,7 @@ function ListPopup({ popup }: { popup: Extract<LspPopup, { kind: "list" }> }) {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{popup.preview && <ListPreviewPanel preview={shownPreview} />}
|
||||
{popup.preview && <ListPreviewPanel preview={shownPreview} themeClasses={popup.themeClasses} />}
|
||||
{sub?.item.submenu && (
|
||||
<Popup
|
||||
open
|
||||
|
||||
@@ -552,6 +552,7 @@ export async function showIntentions(view: EditorView) {
|
||||
items,
|
||||
busy,
|
||||
preview,
|
||||
themeClasses: view.themeClasses,
|
||||
onClose: () => {
|
||||
dismissed = true;
|
||||
},
|
||||
|
||||
@@ -104,6 +104,7 @@ export type LspPopup =
|
||||
pin?: { label: string; run: () => void };
|
||||
/** Side panel for the selected row, fetched lazily; `signal` aborts when the selection moves. */
|
||||
preview?: (item: ListPopupItem, signal: AbortSignal) => Promise<ListPreview | null>;
|
||||
themeClasses?: string;
|
||||
/** Runs when the popup goes away (closed, replaced or a row ran). */
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
Reference in new issue
Заблокувати користувача