Попытки в мультипарсинг
This commit is contained in:
52
CodeBase/Services/UniversalFileFilter.cs
Normal file
52
CodeBase/Services/UniversalFileFilter.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
namespace CodeBase.Services
|
||||
{
|
||||
public class UniversalFileFilter
|
||||
{
|
||||
// 1. Оставляем только те языки, которые нам реально интересны
|
||||
private readonly HashSet<string> _allowedExtensions = new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
".cs", ".py", ".go", ".ts", ".js", ".java", ".cpp", ".c", ".h", ".json"
|
||||
};
|
||||
|
||||
// 2. Глобальные папки с мусором и зависимостями (универсально для разных стеков)
|
||||
private readonly string[] _ignoredDirectories =
|
||||
{
|
||||
"/obj/", "\\obj\\",
|
||||
"/bin/", "\\bin\\",
|
||||
"/node_modules/", "\\node_modules\\",
|
||||
"/venv/", "\\venv\\",
|
||||
"/.env/", "\\.env\\",
|
||||
"/dist/", "\\dist\\",
|
||||
"/build/", "\\build\\",
|
||||
"/.git/", "\\.git\\"
|
||||
};
|
||||
|
||||
// 3. Паттерны автосгенерированных файлов
|
||||
private readonly string[] _ignoredFileSuffixes =
|
||||
{
|
||||
".g.cs",
|
||||
".designer.cs",
|
||||
".generated.cs",
|
||||
"AssemblyInfo.cs"
|
||||
};
|
||||
|
||||
public bool IsValidCodeFile(string relativePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(relativePath)) return false;
|
||||
|
||||
// Проверка 1: Расширение файла
|
||||
var ext = Path.GetExtension(relativePath);
|
||||
if (!_allowedExtensions.Contains(ext)) return false;
|
||||
|
||||
// Проверка 2: Находится ли файл в мусорной папке
|
||||
if (_ignoredDirectories.Any(dir => relativePath.Contains(dir, StringComparison.OrdinalIgnoreCase)))
|
||||
return false;
|
||||
|
||||
// Проверка 3: Является ли файл автосгенерированным
|
||||
if (_ignoredFileSuffixes.Any(suffix => relativePath.EndsWith(suffix, StringComparison.OrdinalIgnoreCase)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user