From f71bbf0d34abe1accdd8184ef90af887e45453ba Mon Sep 17 00:00:00 2001 From: MuriloFP Date: Sat, 28 Jun 2025 13:46:30 -0300 Subject: [PATCH] fix: list_files recursive mode now works correctly for hidden directories - Fixed ripgrep exclusion pattern from `!**/.*//**` to `!**/.*/**` - Hidden directories (like .git/) now appear in recursive listings but their contents are excluded - Contents of hidden directories are only shown when explicitly targeting that directory - Prevents context window overflow from massive hidden directories like .git/ - Maintains consistent behavior: show directory exists, avoid flooding with contents Fixes #2992 --- src/services/glob/list-files.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/services/glob/list-files.ts b/src/services/glob/list-files.ts index 7cf26c7528..027cb42766 100644 --- a/src/services/glob/list-files.ts +++ b/src/services/glob/list-files.ts @@ -192,7 +192,7 @@ function buildRipgrepArgs(dirPath: string, recursive: boolean): string[] { const args = ["--files", "--hidden", "--follow"] if (recursive) { - return [...args, ...buildRecursiveArgs(), dirPath] + return [...args, ...buildRecursiveArgs(dirPath), dirPath] } else { return [...args, ...buildNonRecursiveArgs(), dirPath] } @@ -201,25 +201,31 @@ function buildRipgrepArgs(dirPath: string, recursive: boolean): string[] { /** * Build ripgrep arguments for recursive directory traversal */ -function buildRecursiveArgs(): string[] { +function buildRecursiveArgs(dirPath: string): string[] { const args: string[] = [] // In recursive mode, respect .gitignore by default // (ripgrep does this automatically) + // Check if we're explicitly targeting a hidden directory + const targetDirName = path.basename(dirPath) + const isTargetingHiddenDir = targetDirName.startsWith(".") + // Apply directory exclusions for recursive searches for (const dir of DIRS_TO_IGNORE) { // Special handling for hidden directories pattern if (dir === ".*") { - // Don't exclude hidden directories at the ripgrep level for recursive mode + // Only exclude hidden directories if we're not explicitly targeting one // This allows explicitly targeted hidden directories to be processed - // Hidden subdirectories will be filtered during directory traversal instead + // while excluding them from general recursive searches + if (!isTargetingHiddenDir) { + args.push("-g", `!**/.*/**`) + } continue } args.push("-g", `!**/${dir}/**`) } - return args } @@ -338,7 +344,11 @@ async function listFilteredDirectories( directories.push(formattedPath) // If recursive mode and not a ignored directory, scan subdirectories - if (recursive && !isDirectoryExplicitlyIgnored(dirName)) { + // Don't recurse into hidden directories unless they are the explicit target + const isHiddenDir = dirName.startsWith(".") + const shouldRecurse = + recursive && !isDirectoryExplicitlyIgnored(dirName) && !(isHiddenDir && !isTargetDir) + if (shouldRecurse) { await scanDirectory(fullDirPath, false) // Subdirectories are not target dirs } }