1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! File and directory exclusion patterns for database loading.
//!
//! This module provides the [`Exclusion`] enum for defining rules that determine
//! which files and directories should be excluded when scanning a project with
//! [`DatabaseLoader`](crate::loader::DatabaseLoader).
//!
//! Exclusions support two modes:
//!
//! - **Exact Paths**: Exclude specific files or directories by their filesystem path
//! - **Glob Patterns**: Exclude multiple paths matching a pattern (e.g., `*.tmp`, `**/test/**`)
//!
//! # Use Cases
//!
//! - Exclude build artifacts and cache directories (`target/`, `.cache/`)
//! - Exclude version control metadata (`.git/`, `.svn/`)
//! - Exclude test files or fixtures (`tests/fixtures/`)
//! - Exclude temporary files (`*.swp`, `*.tmp`)
use Cow;
use Path;
/// A rule for excluding files or directories from filesystem scans.
///
/// This enum represents two types of exclusion rules that can be used when loading
/// a database to filter out unwanted files. Exclusions are evaluated during the
/// scan performed by [`DatabaseLoader`](crate::loader::DatabaseLoader).
///
/// # Lifetime
///
/// The `'a` lifetime parameter allows the exclusion to borrow paths and patterns
/// from configuration or other long-lived data structures, avoiding unnecessary
/// allocations during database construction.
///
/// # Variants
///
/// ## Path Exclusion
///
/// Excludes an exact filesystem path, which can be either a file or directory.
/// When a directory is excluded, all files and subdirectories within it are also
/// excluded.
///
/// Paths can be absolute or relative to the workspace. Relative paths are
/// canonicalized during loader construction.
///
/// ## Pattern Exclusion
///
/// Excludes paths matching a glob pattern. Glob patterns support wildcards and
/// are matched against the full path of each discovered file.
///
/// Common pattern syntax:
/// - `*` matches any characters except path separators
/// - `**` matches any characters including path separators (recursive)
/// - `?` matches a single character
/// - `[abc]` matches one character from the set
///
/// # Ordering
///
/// Exclusions are ordered first by variant (Path before Pattern), then by the
/// value within the variant. This enables efficient deduplication and set operations.