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
80
#![cfg_attr(coverage_nightly, coverage(off))]
//! Raw file search — rg-compatible line-level search across all project files.
//!
//! Used as a fallback/complement to the AST-based function index when:
//! - Searching non-code files (TOML, YAML, Markdown, etc.)
//! - Finding module-level items (use, const, static, impl blocks)
//! - User wants pure line-level grep-like results (`--raw` mode)
use ignore::WalkBuilder;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::Path;
/// A single line match from raw file search
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RawSearchResult {
/// File path relative to project root
pub file_path: String,
/// 1-based line number
pub line_number: usize,
/// The matching line content (trimmed trailing newline)
pub line_content: String,
/// Context lines before the match
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub context_before: Vec<String>,
/// Context lines after the match
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub context_after: Vec<String>,
}
/// Options for raw search
pub struct RawSearchOptions<'a> {
/// Regex pattern to search for
pub pattern: &'a str,
/// Whether to treat pattern as literal (no regex)
pub literal: bool,
/// Case-insensitive search
pub case_insensitive: bool,
/// Lines of context before match
pub before_context: usize,
/// Lines of context after match
pub after_context: usize,
/// Maximum results to return
pub limit: usize,
/// Filter to files matching this language extension
pub language_filter: Option<&'a str>,
/// Exclude files matching these glob patterns (repeatable)
pub exclude_file_pattern: Vec<&'a str>,
/// Exclude results matching content patterns (repeatable)
pub exclude_pattern: Vec<&'a str>,
/// Only return file paths (like rg -l)
pub files_with_matches: bool,
/// Only return match counts per file (like rg -c)
pub count_mode: bool,
}
/// Per-file match count for --count mode
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileMatchCount {
pub file_path: String,
pub count: usize,
}
/// Result of a raw search operation
pub enum RawSearchOutput {
/// Normal line matches
Lines(Vec<RawSearchResult>),
/// File paths only (--files-with-matches)
Files(Vec<String>),
/// Match counts per file (--count)
Counts(Vec<FileMatchCount>),
}
// Search engine: file walking, pattern matching, match collection, and utilities
include!("raw_search_engine.rs");
// Tests for raw search functionality
#[cfg(test)]
include!("raw_search_tests.rs");