feat(java): strike out deprecated classes in the Project view and editor tabs (#4349)

The JVM file presentation now reports whether a file's primary type is deprecated: annotated @Deprecated (Java and Kotlin), or a Java type whose Javadoc has a @deprecated tag. The Project view and editor tabs strike the name out, and an error marker on the same file still shows.

Closes #4151
This commit is contained in:
l0ng-ai
2026-11-18 23:21:04 +08:00
committed by GitHub
parent 6829022b71
commit 6bf69cfb2a
10 changed files with 99 additions and 21 deletions
+17 -10
View File
@@ -16,10 +16,10 @@ vi.mock("@/platform/ipc", async (original) => ({
vi.mock("@/platform/projectPresentation", () => ({
useProjectPresentation: () => ({ spring: false, modules: new Map() }),
}));
import { useFilePresentation, useFilePresentationIcons } from "./filePresentation";
import { useFilePresentation, useFilePresentations } from "./filePresentation";
const answer = (path: string, kind = "interface") => ({
path,
presentation: { kind, springBoot: false, runnable: false },
presentation: { kind, springBoot: false, runnable: false, deprecated: path.includes("Old") },
});
const tick = async () => {
await act(async () => {
@@ -39,25 +39,32 @@ describe("visible file resolver", () => {
vi.useRealTimers();
});
it("shows a plain icon immediately and batches mounted paths only", async () => {
const { result } = renderHook(() => useFilePresentationIcons(["/p/Foo.java", "/p/Bar.kt", "/p/config.yml"]));
expect(result.current.get("/p/Foo.java")).toBe("file-java");
const { result } = renderHook(() => useFilePresentations(["/p/Foo.java", "/p/Bar.kt", "/p/config.yml"]));
expect(result.current.get("/p/Foo.java")?.icon).toBe("file-java");
expect(backend.resolve).not.toHaveBeenCalled();
await tick();
expect(backend.resolve).toHaveBeenCalledOnce();
expect(backend.resolve.mock.calls[0]?.[0]).toEqual(["/p/Foo.java", "/p/Bar.kt"]);
expect(result.current.get("/p/Foo.java")).toBe("interface");
expect(result.current.get("/p/Foo.java")?.icon).toBe("interface");
expect(result.current.get("/p/Foo.java")?.deprecated).toBe(false);
});
it("marks deprecated types", async () => {
const { result } = renderHook(() => useFilePresentations(["/p/OldApi.java"]));
expect(result.current.get("/p/OldApi.java")?.deprecated).toBe(false);
await tick();
expect(result.current.get("/p/OldApi.java")?.deprecated).toBe(true);
const single = renderHook(() => useFilePresentation("/p/OldApi.java"));
expect(single.result.current.deprecated).toBe(true);
});
it("drops unmounted requests and splits large sets into bounded batches", async () => {
const dropped = renderHook(() => useFilePresentation("/p/Invisible.java"));
dropped.unmount();
const { result } = renderHook(() =>
useFilePresentationIcons(Array.from({ length: 130 }, (_, i) => `/p/F${i}.java`)),
);
const { result } = renderHook(() => useFilePresentations(Array.from({ length: 130 }, (_, i) => `/p/F${i}.java`)));
await tick();
await tick();
await tick();
expect(backend.resolve.mock.calls.map(([paths]) => paths.length)).toEqual([64, 64, 2]);
expect(result.current.get("/p/F129.java")).toBe("interface");
expect(result.current.get("/p/F129.java")?.icon).toBe("interface");
expect(backend.resolve.mock.calls.flatMap(([paths]) => paths)).not.toContain("/p/Invisible.java");
});
it("invalidates on watcher changes and rejects an in-flight stale result", async () => {
@@ -94,7 +101,7 @@ describe("visible file resolver", () => {
});
it("caches failures instead of continuously retrying visible batches", async () => {
backend.resolve.mockRejectedValue(new Error("offline"));
renderHook(() => useFilePresentationIcons(Array.from({ length: 65 }, (_, i) => `/p/F${i}.java`)));
renderHook(() => useFilePresentations(Array.from({ length: 65 }, (_, i) => `/p/F${i}.java`)));
await tick();
await tick();
await tick();
+6 -1
View File
@@ -9,7 +9,12 @@ const roots: RootFolder[] = [
{ path: "src/main/resources", kind: "resources", detectedFrom: "pom.xml" },
{ path: "src/test/resources", kind: "testResources", detectedFrom: "pom.xml" },
];
const type = (kind: JvmPresentation["kind"]): JvmPresentation => ({ kind, springBoot: false, runnable: false });
const type = (kind: JvmPresentation["kind"]): JvmPresentation => ({
kind,
springBoot: false,
runnable: false,
deprecated: false,
});
const icon = (path: string, info: JvmPresentation | null = null, spring = false) =>
presentationIcon(`/p/${path}`, info, roots, "/p", spring);
+10 -3
View File
@@ -163,11 +163,15 @@ export function useFilePresentation(path: string, mtime?: number | null) {
const root = useProject((s) => s.project?.root ?? null);
const build = useProjectPresentation();
const icon = presentationIcon(path, info, roots, root, build.spring);
return { icon, runnable: !!info?.runnable && icon !== "spring-boot" && icon !== "jvm-test" };
return {
icon,
runnable: !!info?.runnable && icon !== "spring-boot" && icon !== "jvm-test",
deprecated: !!info?.deprecated,
};
}
/** Tab strips resolve their mounted file tabs through the same batch as tree rows. */
export function useFilePresentationIcons(paths: readonly string[]) {
export function useFilePresentations(paths: readonly string[]) {
const key = JSON.stringify(paths);
useEffect(() => {
const disposers = (JSON.parse(key) as string[]).map(mount);
@@ -183,7 +187,10 @@ export function useFilePresentationIcons(paths: readonly string[]) {
new Map(
(JSON.parse(key) as string[]).map((path) => [
path,
presentationIcon(path, entries.get(path), roots, root, build.spring),
{
icon: presentationIcon(path, entries.get(path), roots, root, build.spring),
deprecated: !!entries.get(path)?.deprecated,
},
]),
),
// eslint-disable-next-line react-hooks/exhaustive-deps -- iconRevision: the file icon theme changed