Файли
openidea/src/features/project-tree/safeDelete.test.ts
T
l0ng-ai 81e0e8e2d0 feat: Align interactions with IntelliJ IDEA (#22)
* feat(nav): Complete file paths and flag unresolved web file references

Path completion in href/src/url()/@import, Markdown links and path-like strings, folders first. HTML and CSS paths that name no file get a 'Cannot resolve file' warning. File references resolve in the backend like IDEA's: relative to the file, /-rooted against the project and resource roots.

* feat: Align editor, workbench, run/debug and VCS interactions with IntelliJ IDEA

Keymap
- Let AltGr characters through instead of firing Ctrl+Alt shortcuts (Windows/Linux)
- Double Shift: strict press/release timing, ignored while typing or after Shift+click
- Chords wait 2s and swallow an unmatched second stroke
- Drop CodeMirror defaults that clash with IDEA keys; ⌘Enter is Split Line, add
  Scroll to Center and Code Block Start/End
- Add missing IDEA defaults (⌃J, ⌘Y, ⇧⌘C, ⌥⌘Y, ⇧⌘M, F9 Resume, ⌘R Rerun, …)

Editor
- Tab inserts at the caret; smart Backspace to the proper indent; Enter continues
  a `//` comment; per-language line comment placement
- Back/Forward records navigations only; ⌘F searches the selected text
- In-place rename; ⌃Space inserts a sole candidate; commit characters only for a
  focused lookup; usage highlighting survives edits; ⌥Enter offers fixes from the
  caret line; ⌘-hover shows declaration info only for navigable targets

Workbench
- Tool windows: primary and split area per side, six Move To anchors, layout migration
- ⌘W closes tool window content; Shift+Esc from the editor; closing a tab
  activates the left neighbour; preview tab and tab limit follow IDEA defaults
- Switcher lists open editors and tool windows; Recent Files Delete removes items
- Search Everywhere tab/scope behaviour; popups close when the window deactivates
- Project view: Copy/Move dialogs on paste, skippable usage search on delete,
  new-file input cancels on blur; Settings search Esc clears the filter
- Status bar breadcrumbs open a children popup; notification timeouts

Run / Debug / Build / Terminal
- Run asks to stop a running single-instance config; Rerun restarts silently;
  "Allow multiple instances" option
- Run chooser: Enter runs, Shift debugs, F4/Delete/digits
- Type into the console for stdin; Stop covers debug sessions
- Log (Shift+click) and temporary (Alt+click) breakpoints; independent suspend/log
  options; Evaluate prefill and history; changed-value highlighting; expandable hints
- Build window opens on failure and jumps to the first error
- Terminal confirms closing a busy tab and lets IDE shortcuts through

VCS
- Correct ours/theirs labels during rebase, cherry-pick and revert
- Smart/Force Checkout; remote branch checkout updates the local branch
- Partial commit by changed block; inline before-commit check results
- F7 continues into the next file; Rollback Lines; Commit and Push; Amend message swap
- Branch delete with Restore; force push confirmation; editable push target;
  update summary with the incoming commits

* chore: Regenerate bindings
2026-10-25 09:34:02 +08:00

79 рядки
3.2 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "vitest";
import type { Location } from "@/bindings";
const fileUsages = vi.fn();
const askUsagesDetected = vi.fn();
const viewUsages = vi.fn();
vi.mock("@/editor/refactor", () => ({ fileUsages, askUsagesDetected, viewUsages }));
const notify = vi.fn();
vi.mock("@/workbench/contributions", async (orig) => ({
...(await orig<typeof import("@/workbench/contributions")>()),
notifications: () => ({ notify }),
}));
const ask = vi.fn();
vi.mock("@/workbench/messages", async (orig) => ({
...(await orig<typeof import("@/workbench/messages")>()),
ask,
}));
const { safeToDelete } = await import("./operations");
const usage: Location = { path: "/p/main.rs", range: { start: { line: 1, col: 0 }, end: { line: 1, col: 1 } } };
afterEach(() => vi.clearAllMocks());
describe("safe delete of files", () => {
it("deletes without asking again when nothing uses the file or usages can't be searched", async () => {
fileUsages.mockResolvedValueOnce({ status: "ok", usages: [] });
expect(await safeToDelete(["/p/a.rs"])).toBe(true);
fileUsages.mockResolvedValueOnce({ status: "unsupported", reason: "no server" });
expect(await safeToDelete(["/p/a.md"])).toBe(true);
expect(askUsagesDetected).not.toHaveBeenCalled();
});
it("asks Usages Detected and follows the answer", async () => {
fileUsages.mockResolvedValue({ status: "ok", usages: [usage] });
askUsagesDetected.mockResolvedValueOnce("delete");
expect(await safeToDelete(["/p/a.rs"])).toBe(true);
expect(askUsagesDetected).toHaveBeenCalledWith("File 'a.rs'", [usage], false);
askUsagesDetected.mockResolvedValueOnce("view");
expect(await safeToDelete(["/p/a.rs", "/p/b.rs"])).toBe(false);
expect(askUsagesDetected).toHaveBeenLastCalledWith("The 2 files", [usage], true);
expect(viewUsages).toHaveBeenCalledWith("2 files", [usage]);
askUsagesDetected.mockResolvedValueOnce("cancel");
expect(await safeToDelete(["/p/a.rs"])).toBe(false);
});
it("deletes nothing when the search fails", async () => {
fileUsages.mockRejectedValueOnce(new Error("cancelled"));
expect(await safeToDelete(["/p/a.rs"])).toBe(false);
expect(notify).toHaveBeenCalledWith(expect.objectContaining({ level: "warning" }));
});
it("lets a slow search be skipped (delete anyway) or cancelled", async () => {
vi.useFakeTimers();
try {
const pending = (_: string[], signal: AbortSignal) =>
new Promise((_r, reject) => signal.addEventListener("abort", () => reject(new Error("aborted"))));
fileUsages.mockImplementation(pending);
ask.mockResolvedValueOnce({ button: "skip", checked: false });
const skipped = safeToDelete(["/p/a.rs"]);
await vi.advanceTimersByTimeAsync(500);
expect(await skipped).toBe(true);
expect(ask).toHaveBeenCalledWith(expect.objectContaining({ body: "Looking for usages…" }));
ask.mockResolvedValueOnce({ button: "cancel", checked: false });
const cancelled = safeToDelete(["/p/a.rs"]);
await vi.advanceTimersByTimeAsync(500);
expect(await cancelled).toBe(false);
expect(notify).not.toHaveBeenCalled();
} finally {
fileUsages.mockReset();
vi.useRealTimers();
}
});
});