Compare commits

...
Author SHA1 Message Date
l0ng-ai b27cb56093 fix(hierarchy): load library types' levels from their language server
The type hierarchy opened every node's document from disk, so a JDK or
dependency type (a jdt:// URI) failed with "No such file or directory":
its look-ahead load failed silently, leaving an expand arrow on every
library type, and expanding one showed "failed to load". Library URIs
now open as virtual documents, like the other withDocument helper does.

Fixes #3409
2026-11-17 20:24:18 +08:00
2 changed files with 31 additions and 1 deletions

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
import { describe, expect, it, vi } from "vitest";
const opened = vi.hoisted(() => [] as string[]);
vi.mock("@/platform/ipc", async (importOriginal) => {
const ipc = await importOriginal<typeof import("@/platform/ipc")>();
const doc = (path: string) => Promise.resolve({ status: "ok", data: { id: 3, path } });
return {
...ipc,
isTauri: () => true,
commands: {
...ipc.commands,
docOpen: (path: string) => (opened.push(`file ${path}`), doc(path)),
docOpenVirtual: (uri: string) => (opened.push(`virtual ${uri}`), doc(uri)),
docClose: () => Promise.resolve(),
},
};
});
const { withDocument } = await import("./ipc");
describe("withDocument", () => {
it("opens a library type through its language server, a project file from disk", async () => {
const uri = "jdt://contents/java.base/java.util/UUID.class?=demo/%5C/jdk%5C/lib%5C/jrt-fs.jar%60java.base";
await withDocument(uri, async (doc) => doc);
await withDocument("/p/src/App.java", async (doc) => doc);
expect(opened).toEqual([`virtual ${uri}`, "file /p/src/App.java"]);
});
});
+2 -1
View File
@@ -134,7 +134,8 @@ export async function readManyFileLines(
export async function withDocument<T>(path: string, fn: (doc: number) => Promise<T>): Promise<T> {
const open = editorsFor(path)[0];
if (open) return fn(open.ctx.doc);
const info = await lspRequest(() => commands.docOpen(path));
// Library types (`jdt://…`) are documents the language server provides, not files on disk.
const info = await lspRequest(() => (isVirtualUri(path) ? commands.docOpenVirtual(path) : commands.docOpen(path)));
try {
return await fn(info.id);
} finally {