diff --git a/crates/forge_services/src/fd.rs b/crates/forge_services/src/fd.rs index 72ed9bfaf4..a86e3ac171 100644 --- a/crates/forge_services/src/fd.rs +++ b/crates/forge_services/src/fd.rs @@ -30,6 +30,31 @@ pub(crate) fn has_allowed_extension(path: &Path) -> bool { } } +/// Returns `true` if the file at `path` should be excluded based on its name, +/// regardless of extension. This covers lock files and other generated +/// dependency manifest files that are not useful to index. +fn is_ignored_by_name(path: &Path) -> bool { + let Some(name) = path.file_name().and_then(|n| n.to_str()) else { + return false; + }; + let name_lower = name.to_lowercase(); + + // Lock files: *-lock.json, *.lock, *.lockb, *.lock.json, etc. + if name_lower.ends_with(".lock") + || name_lower.ends_with(".lockb") + || name_lower.ends_with("-lock.json") + || name_lower.ends_with("-lock.yaml") + || name_lower.ends_with("-lock.yml") + || name_lower.ends_with(".lock.json") + || name_lower.ends_with(".lockfile") + || name == "Package.resolved" + { + return true; + } + + false +} + /// Returns `true` if `path` is a symlink (does not follow the link). fn is_symlink(path: &Path) -> bool { path.symlink_metadata() @@ -53,6 +78,7 @@ pub(crate) fn filter_and_resolve( .into_iter() .map(|p| dir_path.join(&p)) .filter(|p| !is_symlink(p)) + .filter(|p| !is_ignored_by_name(p)) .filter(|p| has_allowed_extension(p)) .collect();