mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-22 09:39:27 -10:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fab386a4b4 | ||
|
|
c79530f7ad |
No files matched your search
@@ -715,6 +715,58 @@ test("rename keeps the typed name, uses the editor font and shows long preview n
|
||||
await expect.poll(() => ipcCalls(page, "apply_workspace_edit")).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("intentions separate quick fixes from other actions and navigate across the divider", async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
const editor = await openSample(page);
|
||||
const fix = "Correct the Order type";
|
||||
const refactor = "Extract the order value";
|
||||
await page.evaluate(
|
||||
({ file, edit, fix, refactor }) => {
|
||||
const action = (title: string, kind: string, newText: string) => ({
|
||||
title,
|
||||
kind,
|
||||
isPreferred: false,
|
||||
disabledReason: null,
|
||||
edit: { files: [{ kind: "edit", path: file, edits: [{ range: edit, new_text: newText }] }] },
|
||||
command: null,
|
||||
data: null,
|
||||
server: 1,
|
||||
});
|
||||
window.__ipc.handlers.lsp_code_actions = () => [
|
||||
action(refactor, "refactor.extract", "ExtractedOrder"),
|
||||
action(fix, "quickfix", "CorrectOrder"),
|
||||
];
|
||||
window.__ipc.handlers.lsp_execute_code_action = () => [];
|
||||
},
|
||||
{ file: FILE, edit: range(20, 19, 24), fix, refactor },
|
||||
);
|
||||
await caretAt(editor, page, "val order: Order", "Order ");
|
||||
await page.keyboard.press("Alt+Enter");
|
||||
|
||||
const popup = page.getByRole("dialog", { name: "Intentions", exact: true });
|
||||
const list = popup.getByRole("listbox", { name: "Intentions" });
|
||||
const divider = list.locator("[class*=listDivider]");
|
||||
const preview = popup.locator('[aria-label="Preview"] pre');
|
||||
await expect(list.getByRole("option", { name: fix })).toBeVisible();
|
||||
await page.keyboard.type("order");
|
||||
await expect(list.getByRole("option")).toHaveText([fix, refactor]);
|
||||
await expect(divider).toHaveCount(1);
|
||||
await expect(list.getByRole("option", { name: fix })).toHaveAttribute("aria-selected", "true");
|
||||
await expect(preview).toContainText("CorrectOrder");
|
||||
await list.press("ArrowDown");
|
||||
await expect(list.getByRole("option", { name: refactor })).toHaveAttribute("aria-selected", "true");
|
||||
await expect(preview).toContainText("ExtractedOrder");
|
||||
|
||||
for (const _character of "order") await list.press("Backspace");
|
||||
await page.keyboard.type("extract");
|
||||
await expect(list.getByRole("option")).toHaveText([refactor]);
|
||||
await expect(divider).toHaveCount(0);
|
||||
await list.press("Enter");
|
||||
await expect(popup).toBeHidden();
|
||||
await expect.poll(() => ipcCalls(page, "lsp_execute_code_action")).toHaveLength(1);
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
@@ -15,7 +15,7 @@ vi.mock("@/workbench/contributions", async (orig) => {
|
||||
});
|
||||
|
||||
const { LspPopups, DocumentationWindow } = await import("./Popups");
|
||||
const { closePopup, openPopup, useLspPopup } = await import("./popupStore");
|
||||
const { closePopup, openPopup, updatePopup, useLspPopup } = await import("./popupStore");
|
||||
const { useDocWindow, hoverDoc, pushHistory, stepHistory, hoverCandidates } = await import("./docs");
|
||||
const { mountHoverDoc } = await import("./DocView");
|
||||
const { hoverSource } = await import("./hover");
|
||||
@@ -139,6 +139,31 @@ describe("list popup", () => {
|
||||
expect(onClose).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("keeps the chosen intention when a quick-fix section arrives ahead of it", () => {
|
||||
const local = ["Extract variable", "Inline value"].map((label) => ({
|
||||
id: label,
|
||||
label,
|
||||
section: { id: "intentions" },
|
||||
run: vi.fn(),
|
||||
}));
|
||||
openPopup({ kind: "list", title: "Intentions", anchor: { x: 0, y: 0 }, items: local, busy: true });
|
||||
render(<LspPopups />);
|
||||
fireEvent.keyDown(screen.getByRole("listbox"), { key: "ArrowDown" });
|
||||
expect(screen.getByRole("option", { name: "Inline value", selected: true })).toBeVisible();
|
||||
|
||||
const runFix = vi.fn();
|
||||
act(() =>
|
||||
updatePopup("list", {
|
||||
busy: false,
|
||||
items: [{ id: "fix", label: "Correct type", section: { id: "quick-fixes" }, run: runFix }, ...local],
|
||||
}),
|
||||
);
|
||||
expect(screen.getByRole("option", { name: "Inline value", selected: true })).toBeVisible();
|
||||
fireEvent.keyDown(screen.getByRole("listbox"), { key: "Enter" });
|
||||
expect(local[1]!.run).toHaveBeenCalledOnce();
|
||||
expect(runFix).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("focuses the rows, not the header's pin button, when it opens", () => {
|
||||
openPopup({
|
||||
kind: "list",
|
||||
|
||||
@@ -112,14 +112,10 @@ function ListPopup({ popup }: { popup: Extract<LspPopup, { kind: "list" }> }) {
|
||||
const [query, setQuery] = useState("");
|
||||
const rows = useMemo(() => listPopupRows(popup.items, query), [popup.items, query]);
|
||||
const firstEnabled = rows.findIndex((row) => row.kind === "action" && !row.item.disabled);
|
||||
const [active, setActive] = useState(firstEnabled);
|
||||
const clamped = Math.min(active, rows.length - 1);
|
||||
const [activeId, setActiveId] = useState<string | null>(null);
|
||||
const selected = rows.findIndex((row) => row.kind === "action" && row.item.id === activeId);
|
||||
const activeIndex =
|
||||
rows[clamped]?.kind === "action"
|
||||
? clamped
|
||||
: firstEnabled >= 0
|
||||
? firstEnabled
|
||||
: firstSelectable(rows, isListSection);
|
||||
selected >= 0 ? selected : firstEnabled >= 0 ? firstEnabled : firstSelectable(rows, isListSection);
|
||||
const activeRow = rows[activeIndex];
|
||||
const activeItem = activeRow?.kind === "action" ? activeRow.item : undefined;
|
||||
const showIcons = !popup.compact || popup.items.some((item) => item.icon || item.symbol);
|
||||
@@ -183,11 +179,11 @@ function ListPopup({ popup }: { popup: Extract<LspPopup, { kind: "list" }> }) {
|
||||
if (item) activate(item);
|
||||
} else if (e.key === "Backspace" && query) {
|
||||
setQuery(query.slice(0, -1));
|
||||
setActive(-1);
|
||||
setActiveId(null);
|
||||
e.preventDefault();
|
||||
} else if (e.key.length === 1 && !(e.key === " " && !query)) {
|
||||
setQuery(query + e.key);
|
||||
setActive(-1);
|
||||
setActiveId(null);
|
||||
e.preventDefault();
|
||||
}
|
||||
};
|
||||
@@ -297,7 +293,10 @@ function ListPopup({ popup }: { popup: Extract<LspPopup, { kind: "list" }> }) {
|
||||
row.kind === "section" && row.label ? <T>{row.label}</T> : <span className={styles.listDivider} />
|
||||
}
|
||||
activeIndex={activeIndex}
|
||||
onActiveChange={setActive}
|
||||
onActiveChange={(index) => {
|
||||
const row = rows[index];
|
||||
setActiveId(row?.kind === "action" ? row.item.id : null);
|
||||
}}
|
||||
hoverSelects
|
||||
autoFocus
|
||||
aria-label={popup.title}
|
||||
|
||||
@@ -60,11 +60,18 @@ export function quickFixIcon(view: EditorView): "bulb" | "bulb-fix" {
|
||||
|
||||
const isFixItem = (item: ListPopupItem) => item.quickFix ?? item.icon === "bulb-fix";
|
||||
|
||||
/** Local and language-server fixes share icons and the same stable ordering. */
|
||||
/** Local and language-server fixes share icons and are grouped separately from other actions. */
|
||||
export function listedIntentions(view: EditorView, items: ListPopupItem[]): ListPopupItem[] {
|
||||
const rank = (item: ListPopupItem) => (item.disabled ? 4 : 0) + (isFixItem(item) ? 0 : 2) + (item.emphasis ? 0 : 1);
|
||||
return items
|
||||
.map((item) => (isFixItem(item) ? { ...item, quickFix: true, icon: quickFixIcon(view) } : item))
|
||||
.map((item) => {
|
||||
const fix = isFixItem(item);
|
||||
return {
|
||||
...item,
|
||||
...(fix && { quickFix: true, icon: quickFixIcon(view) }),
|
||||
section: item.section ?? { id: item.disabled ? "unavailable" : fix ? "quick-fixes" : "intentions" },
|
||||
};
|
||||
})
|
||||
.sort((a, b) => rank(a) - rank(b));
|
||||
}
|
||||
|
||||
@@ -497,6 +504,7 @@ export function withInspectionControls(view: EditorView, items: ListPopupItem[])
|
||||
...inspections.map((inspection) => ({
|
||||
id: `inspection:${inspection.id}`,
|
||||
label: tx`Inspection '${txPart(inspection.name)}' options`,
|
||||
section: { id: "inspection-options" },
|
||||
icon: "settings",
|
||||
run: () => editInspectionSettings(inspection.id),
|
||||
submenu: intentionControls(inspection),
|
||||
|
||||
Reference in new issue
Block a user