refactor: Switch over to unified shouldIgnoreFile (#11815)

This commit is contained in:
Eric Rahm
2025-10-24 18:55:12 -07:00
committed by GitHub
parent 145e099ca5
commit b1059f891f
6 changed files with 51 additions and 84 deletions
+17 -18
View File
@@ -8,7 +8,10 @@ import * as fs from 'node:fs/promises';
import type { Dirent } from 'node:fs';
import * as path from 'node:path';
import { getErrorMessage, isNodeError } from './errors.js';
import type { FileDiscoveryService } from '../services/fileDiscoveryService.js';
import type {
FileDiscoveryService,
FilterFilesOptions,
} from '../services/fileDiscoveryService.js';
import type { FileFilteringOptions } from '../config/constants.js';
import { DEFAULT_FILE_FILTERING_OPTIONS } from '../config/constants.js';
import { debugLogger } from './debugLogger.js';
@@ -119,6 +122,10 @@ async function readFullStructure(
const filesInCurrentDir: string[] = [];
const subFoldersInCurrentDir: FullFolderInfo[] = [];
const filterFileOptions: FilterFilesOptions = {
respectGitIgnore: options.fileFilteringOptions?.respectGitIgnore,
respectGeminiIgnore: options.fileFilteringOptions?.respectGeminiIgnore,
};
// Process files first in the current directory
for (const entry of entries) {
@@ -129,15 +136,10 @@ async function readFullStructure(
}
const fileName = entry.name;
const filePath = path.join(currentPath, fileName);
if (options.fileService) {
const shouldIgnore =
(options.fileFilteringOptions.respectGitIgnore &&
options.fileService.shouldGitIgnoreFile(filePath)) ||
(options.fileFilteringOptions.respectGeminiIgnore &&
options.fileService.shouldGeminiIgnoreFile(filePath));
if (shouldIgnore) {
continue;
}
if (
options.fileService?.shouldIgnoreFile(filePath, filterFileOptions)
) {
continue;
}
if (
!options.fileIncludePattern ||
@@ -168,14 +170,11 @@ async function readFullStructure(
const subFolderName = entry.name;
const subFolderPath = path.join(currentPath, subFolderName);
let isIgnored = false;
if (options.fileService) {
isIgnored =
(options.fileFilteringOptions.respectGitIgnore &&
options.fileService.shouldGitIgnoreFile(subFolderPath)) ||
(options.fileFilteringOptions.respectGeminiIgnore &&
options.fileService.shouldGeminiIgnoreFile(subFolderPath));
}
const isIgnored =
options.fileService?.shouldIgnoreFile(
subFolderPath,
filterFileOptions,
) ?? false;
if (options.ignoredFolders.has(subFolderName) || isIgnored) {
const ignoredSubFolder: FullFolderInfo = {