From ac88059d0f20e265b37a56d7c19d9ce9548ee31a Mon Sep 17 00:00:00 2001 From: LU XIANGRUI <1078666705@qq.com> Date: Mon, 30 Nov 2026 19:11:27 +0900 Subject: [PATCH] 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 <26499420+wildcatDownstairs@users.noreply.github.com> --- crates/ide-host/src/plugins/index_ops.rs | 50 +++++++++++++++++++++--- crates/ide-index/src/lib.rs | 4 +- crates/ide-index/src/tests.rs | 6 ++- src/bindings.ts | 6 +++ src/features/plugins/navigation.test.ts | 29 +++++++++++++- src/features/plugins/navigation.ts | 15 +++++++ src/platform/locales/text/en.json | 3 +- src/platform/locales/text/zh.json | 3 +- 8 files changed, 105 insertions(+), 11 deletions(-) diff --git a/crates/ide-host/src/plugins/index_ops.rs b/crates/ide-host/src/plugins/index_ops.rs index 63292745a2..7d476b14b4 100644 --- a/crates/ide-host/src/plugins/index_ops.rs +++ b/crates/ide-host/src/plugins/index_ops.rs @@ -9,6 +9,22 @@ pub struct NavigationFiles { pub paths: Vec, pub indexing: bool, pub extensions: Vec, + /// In-scope files matching `extensions`; `paths` holds the first + /// `MAX_NAVIGATION_FILES` of them. + pub total: u32, + pub truncated: bool, +} + +/// Discovery offers at most this many files; larger projects get navigation +/// on the first ones instead of none. +const MAX_NAVIGATION_FILES: usize = 20_000; + +/// The first `limit` files `in_scope` accepts, and how many it accepts in all. +fn first_in_scope(files: Vec, in_scope: impl Fn(&PathBuf) -> bool, limit: usize) -> (Vec, usize) { + let mut files: Vec<_> = files.into_iter().filter(in_scope).collect(); + let total = files.len(); + files.truncate(limit); + (files, total) } #[command(trust = trusted)] @@ -24,19 +40,25 @@ pub async fn plugin_navigation_files( blocking(move || { let extensions = plugins.navigation_extensions(&project.root); if extensions.is_empty() { - return Ok(NavigationFiles { paths: vec![], indexing: false, extensions: vec![] }); + return Ok(NavigationFiles { + paths: vec![], + indexing: false, + extensions: vec![], + total: 0, + truncated: false, + }); } let indexing = project.index.status().indexing; - let files = project.index.files_with_extensions(&extensions, 20_001); - if files.len() > 20_000 { - return Err(IdeError::unavailable("plugin navigation supports up to 20,000 matching files")); - } + let files = project.index.files_with_extensions(&extensions, usize::MAX); // A project window group's members are project scope: their files are // in the group's index (the group root holds none of them). let members = crate::project::workspace_member_roots(&project.root); let in_scope = |p: &PathBuf| p.starts_with(&project.root) || members.iter().any(|m| p.starts_with(m)); + let (files, total) = first_in_scope(files, in_scope, MAX_NAVIGATION_FILES); Ok(NavigationFiles { - paths: files.into_iter().filter(in_scope).map(Into::into).collect(), + truncated: total > files.len(), + total: u32::try_from(total).unwrap_or(u32::MAX), + paths: files.into_iter().map(Into::into).collect(), indexing, extensions, }) @@ -210,3 +232,19 @@ ide_command::domain!( plugin_navigation_invalidate, plugin_navigation_markers, ); + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn discovery_keeps_the_first_in_scope_files_and_counts_them_all() { + let files: Vec = (0..7).map(|i| PathBuf::from(format!("/p/{}/f{i}.xml", i % 2))).collect(); + let (kept, total) = first_in_scope(files, |p| p.starts_with("/p/0"), 3); + // Out-of-scope files neither take a slot nor count toward the total. + assert_eq!(total, 4); + assert_eq!(kept, ["/p/0/f0.xml", "/p/0/f2.xml", "/p/0/f4.xml"].map(PathBuf::from)); + let (kept, total) = first_in_scope(kept, |_| true, 20_000); + assert_eq!((kept.len(), total), (3, 3)); + } +} diff --git a/crates/ide-index/src/lib.rs b/crates/ide-index/src/lib.rs index f2860d4e02..83367ab1c7 100644 --- a/crates/ide-index/src/lib.rs +++ b/crates/ide-index/src/lib.rs @@ -258,7 +258,8 @@ impl ProjectIndex { } /// Bounded file inventory for background plugin indexers; honors the same - /// project/exclude scope as search and never walks the filesystem. + /// project/exclude scope as search, leaves VCS-ignored files out and never + /// walks the filesystem. pub fn files_with_extensions(&self, extensions: &[String], limit: usize) -> Vec { self.shared .data @@ -266,6 +267,7 @@ impl ProjectIndex { .files .iter() .flatten() + .filter(|f| !f.ignored) .filter(|f| f.path.extension().and_then(|e| e.to_str()).is_some_and(|e| extensions.iter().any(|x| x == e))) .take(limit) .map(|f| f.path.clone()) diff --git a/crates/ide-index/src/tests.rs b/crates/ide-index/src/tests.rs index cd067cd265..198ae4962d 100644 --- a/crates/ide-index/src/tests.rs +++ b/crates/ide-index/src/tests.rs @@ -895,15 +895,19 @@ fn workspace_scope_excludes_state_from_scans_updates_and_cached_results() { } #[test] -fn plugin_inventory_respects_excludes_and_symbols_require_matching_text() { +fn plugin_inventory_respects_excludes_and_ignores_and_symbols_require_matching_text() { let java = "package demo; interface UserMapper { void find(); }"; let f = Fixture::new(&[ ("src/UserMapper.java", java), ("src/mapper.xml", ""), ("target/Generated.java", "class Generated {}"), ("other.txt", "ignored"), + (".gitignore", "gen/\n"), + ("gen/Ignored.java", "class Ignored {}"), ]); let index = f.open(); + // Go to File lists the git-ignored file; plugin navigation leaves it out. + assert_eq!(files(&index, "Ignored"), ["gen/Ignored.java"]); let paths = index.files_with_extensions(&["java".into(), "xml".into()], 100); assert_eq!(paths.len(), 2); assert!(paths.iter().all(|p| p.starts_with(f.root.join("src")))); diff --git a/src/bindings.ts b/src/bindings.ts index c249989fec..005cef5277 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -11748,6 +11748,12 @@ export type NavigationFiles = { paths: IpcPath[], indexing: boolean, extensions: string[], + /** + * In-scope files matching `extensions`; `paths` holds the first + * `MAX_NAVIGATION_FILES` of them. + */ + total: number, + truncated: boolean, }; export type NavigationResult = { diff --git a/src/features/plugins/navigation.test.ts b/src/features/plugins/navigation.test.ts index 85e76e76b7..f7965754da 100644 --- a/src/features/plugins/navigation.test.ts +++ b/src/features/plugins/navigation.test.ts @@ -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); + } +}); diff --git a/src/features/plugins/navigation.ts b/src/features/plugins/navigation.ts index 32c4e6ad75..27ed37f6bb 100644 --- a/src/features/plugins/navigation.ts +++ b/src/features/plugins/navigation.ts @@ -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(); 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)) diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 51dd5a1429..e36b79bf55 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -4810,5 +4810,6 @@ "{count} files aren't in the Xcode project": "{count} files aren't in the Xcode project", "xcodebuild doesn't compile it until it's in a target of {name}. Add it in Xcode or convert the group to a folder.": "xcodebuild doesn't compile it until it's in a target of {name}. Add it in Xcode or convert the group to a folder.", "xcodebuild doesn't compile {files} until they're in a target of {name}. Add them in Xcode or convert the group to a folder.": "xcodebuild doesn't compile {files} until they're in a target of {name}. Add them in Xcode or convert the group to a folder.", - "Open in Xcode": "Open in Xcode" + "Open in Xcode": "Open in Xcode", + "Plugin navigation covers {count} of {total} files in {project}; exclude folders to narrow it": "Plugin navigation covers {count} of {total} files in {project}; exclude folders to narrow it" } diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index c023750f01..63ca504ebd 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -11463,5 +11463,6 @@ "{count} files aren't in the Xcode project": "{count} 个文件不在 Xcode 项目中", "xcodebuild doesn't compile it until it's in a target of {name}. Add it in Xcode or convert the group to a folder.": "在加入 {name} 的某个 target 之前,xcodebuild 不会编译它。请在 Xcode 中添加,或把该组转换为文件夹。", "xcodebuild doesn't compile {files} until they're in a target of {name}. Add them in Xcode or convert the group to a folder.": "在加入 {name} 的某个 target 之前,xcodebuild 不会编译 {files}。请在 Xcode 中添加,或把该组转换为文件夹。", - "Open in Xcode": "在 Xcode 中打开" + "Open in Xcode": "在 Xcode 中打开", + "Plugin navigation covers {count} of {total} files in {project}; exclude folders to narrow it": "插件导航仅覆盖 {project} 中 {total} 个文件里的 {count} 个;可排除文件夹以缩小范围" }