fix(plugins): index the first 20,000 files of a large project instead of none (#6958)

Plugin navigation discovery refused the whole project above 20,000 matching files, counted out-of-scope and git-ignored files toward the cap, and showed the raw error text half translated. Discovery now keeps the first 20,000 in-scope, non-ignored files, reports total/truncated, and shows one warning naming the project and the counts.

Fixes #6940

Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
LU XIANGRUIтаwildcatDownstairs authored and GitHub committed 2026-11-30 18:11:27 +08:00
1 джерело a09c9aa9ad
коміт ac88059d0f
8 files changed
+105 -11

No files matched your search

+28 -1
Переглянути файл
@@ -5,7 +5,8 @@ import { useProject } from "@/platform/project";
import { usePlugins } from "./store";
import { useEditorRegistry } from "@/editor/api";
import { lspDoc } from "@/editor/lsp/lsp";
import { synchronizeDocumentIndexes } from "@/workbench/contributions";
import { notifications, provideNotificationService, synchronizeDocumentIndexes } from "@/workbench/contributions";
import { setLocale, txTemplate, useI18n } from "@/platform/i18n";
const mocks = vi.hoisted(() => ({
files: vi.fn(),
@@ -215,3 +216,29 @@ it("keeps unrelated language-server queries available when plugin discovery fail
await expect(synchronizeDocumentIndexes("/project/notes.txt", "refactor")).resolves.toBe(true);
expect(mocks.index).not.toHaveBeenCalled();
});
it("indexes the first files of a large project and says how many it covers, in one sentence", async () => {
mocks.files.mockResolvedValue({
status: "ok",
data: { paths: ["/project/A.java"], indexing: false, extensions: ["java"], total: 28684, truncated: true },
});
useProject.setState({ project: { root: "/project", name: "big-demo", trusted: true } as never });
const notify = vi.fn();
const previous = notifications();
const locale = useI18n.getState().locale;
provideNotificationService({ notify } as never);
try {
await setLocale("zh");
off = startPluginNavigation();
await vi.advanceTimersByTimeAsync(250);
expect(mocks.index.mock.calls[0]?.[0]).toEqual(["/project/A.java"]);
expect(notify).toHaveBeenCalledTimes(1);
const body = notify.mock.calls[0]![0].body;
expect(body).toBe("插件导航仅覆盖 big-demo 中 28,684 个文件里的 1 个;可排除文件夹以缩小范围");
// The balloon and the OS toast look the text up again: it stays whole.
expect(txTemplate(body)).toBe(body);
} finally {
provideNotificationService(previous);
await setLocale(locale);
}
});
+15
Переглянути файл
@@ -47,6 +47,19 @@ export function startPluginNavigation(): () => void {
body: String(error),
});
}
let reportedTruncated = false;
function reportTruncated(count: number, total: number) {
if (reportedTruncated) return;
reportedTruncated = true;
const project = useProject.getState().project;
const name = project?.displayName || project?.name || "";
notifications().notify({
group: "plugins",
level: "warning",
title: "Plugin navigation indexing incomplete",
body: tx`Plugin navigation covers ${count.toLocaleString()} of ${total.toLocaleString()} files in ${name}; exclude folders to narrow it`,
});
}
let fileExtensions = new Set<string>();
const extensions = () => fileExtensions;
const eligible = (path: string) => extensions().has(path.split(".").pop() ?? "");
@@ -142,6 +155,7 @@ export function startPluginNavigation(): () => void {
inventory.paths.forEach((p) => known.add(p));
queue(fresh);
queue([...views.values()], true);
if (inventory.truncated) reportTruncated(inventory.paths.length, inventory.total);
} catch (error) {
discovered = false;
discoveryFailed = true;
@@ -165,6 +179,7 @@ export function startPluginNavigation(): () => void {
discoveryFailed = false;
discovery = null;
reportedError = false;
reportedTruncated = false;
notify();
if (ready())
void call(commands.pluginNavigationInvalidate(null))