MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / search_with_limit

Method search_with_limit

crates/opencode-grep/src/search.rs:61–83  ·  view source on GitHub ↗
(
        path: P,
        pattern: &str,
        limit: usize,
    )

Source from the content-addressed store, hash-verified

59 }
60
61 pub fn search_with_limit<P: AsRef<Path>>(
62 path: P,
63 pattern: &str,
64 limit: usize,
65 ) -> Result<Vec<MatchResult>, Box<dyn std::error::Error>> {
66 let regex = regex::Regex::new(pattern)?;
67 let path = path.as_ref();
68 let mut matches = Vec::new();
69
70 if path.is_file() {
71 search_file(path, &regex, &mut matches, limit)?;
72 } else if path.is_dir() {
73 let files = Self::files(path, FileSearchOptions::default())?;
74 for file in files {
75 if matches.len() >= limit {
76 break;
77 }
78 let _ = search_file(&file, &regex, &mut matches, limit);
79 }
80 }
81
82 Ok(matches)
83 }
84
85 pub fn files<P: AsRef<Path>>(
86 path: P,

Callers

nothing calls this directly

Calls 4

newFunction · 0.85
search_fileFunction · 0.85
is_fileMethod · 0.80
is_dirMethod · 0.80

Tested by

no test coverage detected