use ignore::WalkBuilder;
use crate::error::Result;
pub fn walk_dir(path: &str) -> Result<Vec<String>> {
let mut files = Vec::new();
for entry in WalkBuilder::new(path).hidden(true).git_ignore(true).build() {
let entry = entry.map_err(|e| crate::error::Error::Other(e.to_string()))?;
let path = entry.path();
if path.is_file()
&& let Some(ext) = path.extension()
{
let ext = ext.to_string_lossy();
if is_code_file(&ext) {
files.push(path.to_string_lossy().to_string());
}
}
}
Ok(files)
}
fn is_code_file(ext: &str) -> bool {
matches!(
ext,
"rs" | "py"
| "js"
| "ts"
| "tsx"
| "jsx"
| "go"
| "java"
| "c"
| "cpp"
| "cc"
| "cxx"
| "h"
| "hpp"
| "hxx"
| "rb"
| "cs"
| "sh"
| "bash"
| "html"
| "htm"
| "css"
| "json"
| "toml"
| "lua"
| "php"
| "ex"
| "exs"
| "erl"
| "zig"
| "swift"
| "kt"
| "scala"
| "sc"
| "ml"
| "hs"
)
}