MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / matching_sources

Method matching_sources

atomic-repository/src/content_search.rs:252–290  ·  view source on GitHub ↗

Select matching recorded source before AST budgets. Unlike display search, this retains one source per matching path, not the first N matching lines.

(
        self,
        max_files: usize,
        max_bytes: usize,
        mut retrieve: impl FnMut(&str) -> Result<Option<Vec<u8>>, E>,
        mut accept: impl FnMut(&str, &[u8]) -> bool,
    )

Source from the content-addressed store, hash-verified

250 /// Select matching recorded source before AST budgets. Unlike display search,
251 /// this retains one source per matching path, not the first N matching lines.
252 pub(crate) fn matching_sources<E>(
253 self,
254 max_files: usize,
255 max_bytes: usize,
256 mut retrieve: impl FnMut(&str) -> Result<Option<Vec<u8>>, E>,
257 mut accept: impl FnMut(&str, &[u8]) -> bool,
258 ) -> Result<RecordedSourceMatches, E> {
259 let mut result = RecordedSourceMatches {
260 sources: vec![],
261 searched_files: 0,
262 omitted_files: 0,
263 };
264 let mut bytes = 0;
265 for path in self.paths {
266 result.searched_files += 1;
267 let Some(content) = retrieve(&path)? else {
268 continue;
269 };
270 if syntext::index::is_binary(&content)
271 || !self.re.is_match(&content)
272 || !accept(&path, &content)
273 {
274 continue;
275 }
276 if result.sources.len() >= max_files
277 || bytes + content.len() > max_bytes
278 || content.len() > atomic_semantic::MAX_SOURCE_BYTES
279 {
280 result.omitted_files += 1;
281 continue;
282 }
283 bytes += content.len();
284 match String::from_utf8(content) {
285 Ok(source) => result.sources.push((path, source)),
286 Err(_) => result.omitted_files += 1,
287 }
288 }
289 Ok(result)
290 }
291 pub(crate) fn new<'path>(
292 paths: impl IntoIterator<Item = &'path str>,
293 pattern: &str,

Calls 4

retrieveFunction · 0.85
is_binaryFunction · 0.85
lenMethod · 0.45
pushMethod · 0.45