summaryrefslogtreecommitdiff
path: root/packages/core/src/utils/getFolderStructure.ts
diff options
context:
space:
mode:
authorPyush Sinha <[email protected]>2025-07-20 00:55:33 -0700
committerGitHub <[email protected]>2025-07-20 07:55:33 +0000
commita01b1219a3e814c370f6827b81c9118f2cbc7a64 (patch)
treeb4b406518a04f3cc4fc054b3b86612bf9b1ade51 /packages/core/src/utils/getFolderStructure.ts
parent76b935d598b895240b9bc2b182eb9f1e1b24be0d (diff)
feat: full implementation for .geminiignore in settings and respective tool calls (#3727)
Diffstat (limited to 'packages/core/src/utils/getFolderStructure.ts')
-rw-r--r--packages/core/src/utils/getFolderStructure.ts34
1 files changed, 22 insertions, 12 deletions
diff --git a/packages/core/src/utils/getFolderStructure.ts b/packages/core/src/utils/getFolderStructure.ts
index 6798a147..15588a4b 100644
--- a/packages/core/src/utils/getFolderStructure.ts
+++ b/packages/core/src/utils/getFolderStructure.ts
@@ -9,6 +9,8 @@ import { Dirent } from 'fs';
import * as path from 'path';
import { getErrorMessage, isNodeError } from './errors.js';
import { FileDiscoveryService } from '../services/fileDiscoveryService.js';
+import { FileFilteringOptions } from '../config/config.js';
+import { DEFAULT_FILE_FILTERING_OPTIONS } from '../config/config.js';
const MAX_ITEMS = 200;
const TRUNCATION_INDICATOR = '...';
@@ -26,16 +28,16 @@ interface FolderStructureOptions {
fileIncludePattern?: RegExp;
/** For filtering files. */
fileService?: FileDiscoveryService;
- /** Whether to use .gitignore patterns. */
- respectGitIgnore?: boolean;
+ /** File filtering ignore options. */
+ fileFilteringOptions?: FileFilteringOptions;
}
-
// Define a type for the merged options where fileIncludePattern remains optional
type MergedFolderStructureOptions = Required<
Omit<FolderStructureOptions, 'fileIncludePattern' | 'fileService'>
> & {
fileIncludePattern?: RegExp;
fileService?: FileDiscoveryService;
+ fileFilteringOptions?: FileFilteringOptions;
};
/** Represents the full, unfiltered information about a folder and its contents. */
@@ -126,8 +128,13 @@ async function readFullStructure(
}
const fileName = entry.name;
const filePath = path.join(currentPath, fileName);
- if (options.respectGitIgnore && options.fileService) {
- if (options.fileService.shouldGitIgnoreFile(filePath)) {
+ if (options.fileService) {
+ const shouldIgnore =
+ (options.fileFilteringOptions.respectGitIgnore &&
+ options.fileService.shouldGitIgnoreFile(filePath)) ||
+ (options.fileFilteringOptions.respectGeminiIgnore &&
+ options.fileService.shouldGeminiIgnoreFile(filePath));
+ if (shouldIgnore) {
continue;
}
}
@@ -160,14 +167,16 @@ async function readFullStructure(
const subFolderName = entry.name;
const subFolderPath = path.join(currentPath, subFolderName);
- let isIgnoredByGit = false;
- if (options.respectGitIgnore && options.fileService) {
- if (options.fileService.shouldGitIgnoreFile(subFolderPath)) {
- isIgnoredByGit = true;
- }
+ let isIgnored = false;
+ if (options.fileService) {
+ isIgnored =
+ (options.fileFilteringOptions.respectGitIgnore &&
+ options.fileService.shouldGitIgnoreFile(subFolderPath)) ||
+ (options.fileFilteringOptions.respectGeminiIgnore &&
+ options.fileService.shouldGeminiIgnoreFile(subFolderPath));
}
- if (options.ignoredFolders.has(subFolderName) || isIgnoredByGit) {
+ if (options.ignoredFolders.has(subFolderName) || isIgnored) {
const ignoredSubFolder: FullFolderInfo = {
name: subFolderName,
path: subFolderPath,
@@ -295,7 +304,8 @@ export async function getFolderStructure(
ignoredFolders: options?.ignoredFolders ?? DEFAULT_IGNORED_FOLDERS,
fileIncludePattern: options?.fileIncludePattern,
fileService: options?.fileService,
- respectGitIgnore: options?.respectGitIgnore ?? true,
+ fileFilteringOptions:
+ options?.fileFilteringOptions ?? DEFAULT_FILE_FILTERING_OPTIONS,
};
try {