Файли
openidea/src/editor/codeLocations.test.ts
T
Akbar Husain f944a51e5a perf(editor): parallelize independent awaits and suppress intentional ones (#5652)
Independent awaits in the editor now run together, and the awaits that must stay sequential carry an explained no-await-in-loop suppression.

- Implementation and override gutter markers: base resolution, subclass outlines, super-method lookups and per-owner hierarchy walks run in parallel; results are merged in the original order, and outline/hierarchy requests stay deduplicated per pass.
- Inheritance graph and super-method walks resolve all bases of one level together; levels stay sequential.
- Introduce Variable verifies up to 30 occurrences in parallel; format requests for several ranges run together and edits are applied in range order.
- Python abstract members, Python hierarchy outlines, completion sources and embedded-document shutdown run in parallel, keeping declaration/source order.
- Budgeted walks, cancellation checks, ordered marker batches and Safe Delete's per-symbol search stay sequential.

Co-authored-by: akbar1214 <[email protected]>
2026-11-25 03:32:16 +08:00

59 рядки
2.6 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
const openFile = vi.fn(async () => {});
vi.mock("@/workbench/contributions", async (importOriginal) => ({
...(await importOriginal<typeof import("@/workbench/contributions")>()),
maybeEditorService: () => ({ openFile }),
}));
import { isLibraryPath, isLibrarySource, openCodeLocation } from "./api";
import { useProject } from "@/platform/project";
describe("openCodeLocation", () => {
beforeEach(() => {
openFile.mockClear();
useProject.setState({ project: { root: "/work/app" } as never });
});
// Where language servers keep the library sources they answer with, outside the project.
it.each([
["Java (java-analyzer cache)", "/Users/me/Library/Caches/java-analyzer/sources/src/fe1e/java/util/ArrayList.java"],
["TypeScript (global typescript lib)", "/opt/homebrew/lib/node_modules/typescript/lib/lib.dom.d.ts"],
[
"PHP (Intelephense stubs)",
"/Users/me/Library/Application Support/ide/tools/node_modules/intelephense/lib/stub/standard/standard_2.php",
],
["Kotlin (kotlin-language-server temp copy)", "/private/var/folders/gx/T/kotlinlangserver1146/LocalDate1643.java"],
["Python (interpreter stdlib)", "/Users/me/.pyenv/versions/3.11.5/lib/python3.11/argparse.py"],
])("opens a %s target outside the project as a read-only library source", async (_, path) => {
expect(isLibraryPath(path)).toBe(false);
await openCodeLocation(path, { line: 3, col: 1 });
expect(openFile).toHaveBeenCalledWith(path, { selection: { line: 3, col: 1 }, focus: true });
expect(isLibraryPath(path)).toBe(true);
expect(isLibrarySource({ path, virtual: false })).toBe(true);
});
it("leaves project files and virtual documents editable", async () => {
await Promise.all(
["/work/app/src/Main.java", "jdt://contents/rt.jar/java.util/ArrayList.class"].map(async (path) => {
await openCodeLocation(path, { line: 0, col: 0 });
expect(isLibraryPath(path)).toBe(false);
}),
);
});
it("does not mark files without an open project", async () => {
useProject.setState({ project: null });
await openCodeLocation("/tmp/elsewhere/notes.txt");
expect(isLibraryPath("/tmp/elsewhere/notes.txt")).toBe(false);
});
it("keeps a workspace's other projects editable", async () => {
useProject.setState({
project: { root: "/work/app", workspace: { projects: ["/work/app", "/work/lib"] } } as never,
});
await openCodeLocation("/work/lib/src/Util.java");
expect(isLibraryPath("/work/lib/src/Util.java")).toBe(false);
});
});