processMemoryFile method
Recursively processes a memory file and all its @include references.
Implementation
Future<List<MemoryFileInfo>> processMemoryFile(
String filePath,
MemoryType type,
Set<String> processedPaths,
bool includeExternal, {
int depth = 0,
String? parent,
}) async {
final normalizedPath = filePath.toLowerCase();
if (processedPaths.contains(normalizedPath) || depth >= _maxIncludeDepth) {
return [];
}
if (_isNeomageMdExcluded(filePath, type)) return [];
processedPaths.add(normalizedPath);
final readResult = await _safelyReadMemoryFileAsync(
filePath,
type,
includeBasePath: filePath,
);
final memoryFile = readResult.info;
if (memoryFile == null || memoryFile.content.trim().isEmpty) return [];
final withParent = parent != null
? memoryFile.copyWith(parent: parent)
: memoryFile;
final result = <MemoryFileInfo>[withParent];
for (final resolvedIncludePath in readResult.includePaths) {
final isExternal = !_pathInWorkingPath(
resolvedIncludePath,
_getOriginalCwd(),
);
if (isExternal && !includeExternal) continue;
final includedFiles = await processMemoryFile(
resolvedIncludePath,
type,
processedPaths,
includeExternal,
depth: depth + 1,
parent: filePath,
);
result.addAll(includedFiles);
}
return result;
}