From 8b1ca86526a3479b0c44de098d21bccea2eabe2d Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Fri, 4 Dec 2026 12:37:54 +0800 Subject: [PATCH] fix(search): show a library class's archive instead of its document URI (#7938) Search Everywhere listed classes from dependency jars and the JDK with the language server's raw jdt:// URI as their location. Library rows now show the archive or JDK module, and the status line the archive and package. Refs #7919 --- .../search/__tests__/everywhereModel.test.ts | 12 ++++++++++++ src/features/search/everywhere/SearchEverywhere.tsx | 3 +++ src/features/search/everywhere/model.ts | 8 +++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/features/search/__tests__/everywhereModel.test.ts b/src/features/search/__tests__/everywhereModel.test.ts index 5f0170c151..d4c329de13 100644 --- a/src/features/search/__tests__/everywhereModel.test.ts +++ b/src/features/search/__tests__/everywhereModel.test.ts @@ -105,6 +105,18 @@ describe("mergeSymbols", () => { expect(mergeSymbols([], lsp, "ord", { ...opts, includeNonProject: true }).items[0]!.rel).toBe("/usr/lib/x.kt"); }); + it("locates library classes by their archive, not the server's document URI", () => { + const jdt = + "jdt://contents/opentest4j-1.3.0.jar/org.opentest4j/AssertionFailedError.class?=demo/%5C/m2%5C/opentest4j-1.3.0.jar%3Corg.opentest4j%28AssertionFailedError.class"; + const jdk = "jdt://contents/java.base/java.util/ArrayList.class?=demo/%5C/jdk%5C/lib%5C/jrt-fs.jar%60java.base"; + const lsp = [ws("AssertionFailedError", "class", jdt, 20), ws("ArrayList", "class", jdk, 100)]; + const all = { ...opts, includeNonProject: true }; + expect(mergeSymbols([], lsp, "AssertionFailedError", all).items.map((i) => [i.path, i.rel])).toEqual([ + [jdt, "opentest4j-1.3.0.jar"], + ]); + expect(mergeSymbols([], lsp, "ArrayList", all).items[0]!.rel).toBe("java.base"); + }); + it("applies type filters and reports overflow", () => { const index = [ sym("Order", "class", "/p/A.kt", 0), diff --git a/src/features/search/everywhere/SearchEverywhere.tsx b/src/features/search/everywhere/SearchEverywhere.tsx index 3232a5daa1..a428f9a1c8 100644 --- a/src/features/search/everywhere/SearchEverywhere.tsx +++ b/src/features/search/everywhere/SearchEverywhere.tsx @@ -84,6 +84,7 @@ import { import styles from "./SearchEverywhere.module.css"; import { isImeKey } from "@/platform/ime"; import { nativePath } from "@/platform/paths"; +import { isVirtualUri, virtualContainer } from "@/platform/virtualDocs"; type SeScope = "allPlaces" | ProjectFileSet; @@ -889,6 +890,8 @@ function describe(row: SeRow | undefined): string { case "file": return row.rel; case "symbol": + // A library class: its archive and package, not the server's document URI. + return isVirtualUri(row.path) ? virtualContainer(row.path) : `${row.rel}:${row.line + 1}`; case "text": return `${row.rel}:${row.line + 1}`; } diff --git a/src/features/search/everywhere/model.ts b/src/features/search/everywhere/model.ts index f65c907b21..1ec45cf1da 100644 --- a/src/features/search/everywhere/model.ts +++ b/src/features/search/everywhere/model.ts @@ -9,6 +9,7 @@ import { tx } from "@/platform/i18n"; import { basename, isTypeKind, relDir, symbolDisplayName } from "../common/open"; import { byScore, matchText } from "../common/rank"; import { wordMatch } from "@/ui"; +import { isVirtualUri, virtualContainer } from "@/platform/virtualDocs"; export type SeTab = "all" | "classes" | "files" | "symbols" | "endpoints" | "actions" | "text" | SearchCategoryId; export const isCustomTab = (tab: string): tab is SearchCategoryId => tab.startsWith("plugin:"); @@ -295,6 +296,11 @@ const dedupeKey = (path: string, line: number, name: string) => `${path}\u0000${ * index doesn't know are scored locally and appended (or interleaved when they * clearly match better, e.g. an exact name hit). */ +/** A library class (`jdt://`, `jar:`) by its archive or JDK module, e.g. `spring-boot-4.1.1.jar`. */ +function libraryLocation(path: string): string { + return isVirtualUri(path) ? (virtualContainer(path).split(" › ")[0] ?? path) : path; +} + export function mergeSymbols( index: readonly SymbolMatch[], lsp: readonly WorkspaceSymbol[], @@ -325,7 +331,7 @@ export function mergeSymbols( if (!hit) continue; if (qualified.container && !(s.container && matchText(containerTail(s.container), qualified.container))) continue; seen.add(k); - const rel = opts.root && inProject ? path.slice(opts.root.length + 1) : path; + const rel = opts.root && inProject ? path.slice(opts.root.length + 1) : libraryLocation(path); scored.push({ item: { kind: "symbol",