Skip to main content

fff_query_parser/
constraints.rs

1use smallvec::SmallVec;
2
3/// Constraint types that can be extracted from a query
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum Constraint<'a> {
6    /// Match file extension: *.rs -> Extension("rs")
7    Extension(&'a str),
8
9    /// Glob pattern: **/*.rs -> Glob("**/*.rs")
10    Glob(&'a str),
11
12    /// Multiple text search parts: ["src", "name"]
13    /// Uses slice to avoid allocation
14    Parts(&'a [&'a str]),
15
16    /// Single text token (optimized case)
17    Text(&'a str),
18
19    /// Exclude pattern: !test -> Exclude(&["test"])
20    Exclude(&'a [&'a str]),
21
22    /// Path constraint: /src/ -> PathSegment("src")
23    PathSegment(&'a str),
24
25    /// File path constraint (AI mode): "libswscale/input.c" → FilePath("libswscale/input.c")
26    /// Matches files whose relative path ends with this suffix at a `/` boundary.
27    FilePath(&'a str),
28
29    /// File type constraint: type:rust -> FileType("rust")
30    FileType(&'a str),
31
32    /// Git status constraint: status:modified -> GitStatus(Modified)
33    GitStatus(GitStatusFilter),
34
35    /// Negation constraint: !extension:rs -> Not(Extension("rs"))
36    /// Negates the inner constraint
37    Not(Box<Constraint<'a>>),
38}
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41pub enum GitStatusFilter {
42    Modified,
43    Untracked,
44    Staged,
45    Unmodified,
46}
47
48/// Stack-allocated buffer for text parts (up to 16 parts without heap allocation)
49pub(crate) type TextPartsBuffer<'a> = SmallVec<[&'a str; 16]>;