Skip to content

Commit 445d1ce

Browse files
authored
fix(fd): exclude lock files from workspace file indexing (#2923)
1 parent 1885fb8 commit 445d1ce

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

  • crates/forge_services/src

crates/forge_services/src/fd.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,31 @@ pub(crate) fn has_allowed_extension(path: &Path) -> bool {
3030
}
3131
}
3232

33+
/// Returns `true` if the file at `path` should be excluded based on its name,
34+
/// regardless of extension. This covers lock files and other generated
35+
/// dependency manifest files that are not useful to index.
36+
fn is_ignored_by_name(path: &Path) -> bool {
37+
let Some(name) = path.file_name().and_then(|n| n.to_str()) else {
38+
return false;
39+
};
40+
let name_lower = name.to_lowercase();
41+
42+
// Lock files: *-lock.json, *.lock, *.lockb, *.lock.json, etc.
43+
if name_lower.ends_with(".lock")
44+
|| name_lower.ends_with(".lockb")
45+
|| name_lower.ends_with("-lock.json")
46+
|| name_lower.ends_with("-lock.yaml")
47+
|| name_lower.ends_with("-lock.yml")
48+
|| name_lower.ends_with(".lock.json")
49+
|| name_lower.ends_with(".lockfile")
50+
|| name == "Package.resolved"
51+
{
52+
return true;
53+
}
54+
55+
false
56+
}
57+
3358
/// Returns `true` if `path` is a symlink (does not follow the link).
3459
fn is_symlink(path: &Path) -> bool {
3560
path.symlink_metadata()
@@ -53,6 +78,7 @@ pub(crate) fn filter_and_resolve(
5378
.into_iter()
5479
.map(|p| dir_path.join(&p))
5580
.filter(|p| !is_symlink(p))
81+
.filter(|p| !is_ignored_by_name(p))
5682
.filter(|p| has_allowed_extension(p))
5783
.collect();
5884

0 commit comments

Comments
 (0)