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

Function find_files

crates/opencode-server/src/routes.rs:3133–3169  ·  view source on GitHub ↗
(Query(query): Query<FindFilesQuery>)

Source from the content-addressed store, hash-verified

3131}
3132
3133async fn find_files(Query(query): Query<FindFilesQuery>) -> Result<Json<Vec<String>>> {
3134 let base_path = project_root()?;
3135 let mut results = Vec::new();
3136 let limit = query.limit.unwrap_or(100);
3137
3138 fn find_recursive(
3139 path: &FsPath,
3140 root: &FsPath,
3141 query: &str,
3142 results: &mut Vec<String>,
3143 limit: usize,
3144 ) {
3145 if results.len() >= limit {
3146 return;
3147 }
3148 if path.is_dir() {
3149 if let Ok(entries) = std::fs::read_dir(path) {
3150 for entry in entries.flatten() {
3151 let path_buf = entry.path();
3152 if !is_within_root(&path_buf, root) {
3153 continue;
3154 }
3155 let name = entry.file_name().to_string_lossy().to_string();
3156 if name.contains(query) {
3157 results.push(path_buf.to_string_lossy().to_string());
3158 }
3159 if path_buf.is_dir() && results.len() < limit {
3160 find_recursive(&path_buf, root, query, results, limit);
3161 }
3162 }
3163 }
3164 }
3165 }
3166
3167 find_recursive(&base_path, &base_path, &query.query, &mut results, limit);
3168 Ok(Json(results))
3169}
3170
3171#[derive(Debug, Deserialize)]
3172pub struct FindSymbolsQuery {

Callers

nothing calls this directly

Calls 3

project_rootFunction · 0.85
newFunction · 0.85
find_recursiveFunction · 0.85

Tested by

no test coverage detected