mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-05 19:01:12 -07:00
refactor: simplify FilterReport and remove unused code (#11681)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
@@ -169,7 +169,7 @@ class GlobToolInvocation extends BaseToolInvocation<
|
||||
path.relative(this.config.getTargetDir(), p.fullpath()),
|
||||
);
|
||||
|
||||
const { filteredPaths, gitIgnoredCount, geminiIgnoredCount } =
|
||||
const { filteredPaths, ignoredCount } =
|
||||
fileDiscovery.filterFilesWithReport(relativePaths, {
|
||||
respectGitIgnore:
|
||||
this.params?.respect_git_ignore ??
|
||||
@@ -196,11 +196,8 @@ class GlobToolInvocation extends BaseToolInvocation<
|
||||
} else {
|
||||
message += ` within ${searchDirectories.length} workspace directories`;
|
||||
}
|
||||
if (gitIgnoredCount > 0) {
|
||||
message += ` (${gitIgnoredCount} files were git-ignored)`;
|
||||
}
|
||||
if (geminiIgnoredCount > 0) {
|
||||
message += ` (${geminiIgnoredCount} files were gemini-ignored)`;
|
||||
if (ignoredCount > 0) {
|
||||
message += ` (${ignoredCount} files were ignored)`;
|
||||
}
|
||||
return {
|
||||
llmContent: message,
|
||||
@@ -231,11 +228,8 @@ class GlobToolInvocation extends BaseToolInvocation<
|
||||
} else {
|
||||
resultMessage += ` across ${searchDirectories.length} workspace directories`;
|
||||
}
|
||||
if (gitIgnoredCount > 0) {
|
||||
resultMessage += ` (${gitIgnoredCount} additional files were git-ignored)`;
|
||||
}
|
||||
if (geminiIgnoredCount > 0) {
|
||||
resultMessage += ` (${geminiIgnoredCount} additional files were gemini-ignored)`;
|
||||
if (ignoredCount > 0) {
|
||||
resultMessage += ` (${ignoredCount} additional files were ignored)`;
|
||||
}
|
||||
resultMessage += `, sorted by modification time (newest first):\n${fileListDescription}`;
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ describe('LSTool', () => {
|
||||
expect(result.llmContent).toContain('file1.txt');
|
||||
expect(result.llmContent).not.toContain('file2.log');
|
||||
// .git is always ignored by default.
|
||||
expect(result.returnDisplay).toBe('Listed 2 item(s). (2 git-ignored)');
|
||||
expect(result.returnDisplay).toBe('Listed 2 item(s). (2 ignored)');
|
||||
});
|
||||
|
||||
it('should respect geminiignore patterns', async () => {
|
||||
@@ -161,7 +161,7 @@ describe('LSTool', () => {
|
||||
|
||||
expect(result.llmContent).toContain('file1.txt');
|
||||
expect(result.llmContent).not.toContain('file2.log');
|
||||
expect(result.returnDisplay).toBe('Listed 2 item(s). (1 gemini-ignored)');
|
||||
expect(result.returnDisplay).toBe('Listed 2 item(s). (1 ignored)');
|
||||
});
|
||||
|
||||
it('should handle non-directory paths', async () => {
|
||||
|
||||
@@ -173,7 +173,7 @@ class LSToolInvocation extends BaseToolInvocation<LSToolParams, ToolResult> {
|
||||
);
|
||||
|
||||
const fileDiscovery = this.config.getFileService();
|
||||
const { filteredPaths, gitIgnoredCount, geminiIgnoredCount } =
|
||||
const { filteredPaths, ignoredCount } =
|
||||
fileDiscovery.filterFilesWithReport(relativePaths, {
|
||||
respectGitIgnore:
|
||||
this.params.file_filtering_options?.respect_git_ignore ??
|
||||
@@ -222,20 +222,13 @@ class LSToolInvocation extends BaseToolInvocation<LSToolParams, ToolResult> {
|
||||
.join('\n');
|
||||
|
||||
let resultMessage = `Directory listing for ${this.params.path}:\n${directoryContent}`;
|
||||
const ignoredMessages = [];
|
||||
if (gitIgnoredCount > 0) {
|
||||
ignoredMessages.push(`${gitIgnoredCount} git-ignored`);
|
||||
}
|
||||
if (geminiIgnoredCount > 0) {
|
||||
ignoredMessages.push(`${geminiIgnoredCount} gemini-ignored`);
|
||||
}
|
||||
if (ignoredMessages.length > 0) {
|
||||
resultMessage += `\n\n(${ignoredMessages.join(', ')})`;
|
||||
if (ignoredCount > 0) {
|
||||
resultMessage += `\n\n(${ignoredCount} ignored)`;
|
||||
}
|
||||
|
||||
let displayMessage = `Listed ${entries.length} item(s).`;
|
||||
if (ignoredMessages.length > 0) {
|
||||
displayMessage += ` (${ignoredMessages.join(', ')})`;
|
||||
if (ignoredCount > 0) {
|
||||
displayMessage += ` (${ignoredCount} ignored)`;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -225,7 +225,7 @@ ${finalExclusionPatternsForDescription
|
||||
);
|
||||
|
||||
const fileDiscovery = this.config.getFileService();
|
||||
const { filteredPaths, gitIgnoredCount, geminiIgnoredCount } =
|
||||
const { filteredPaths, ignoredCount } =
|
||||
fileDiscovery.filterFilesWithReport(relativeEntries, {
|
||||
respectGitIgnore:
|
||||
this.params.file_filtering_options?.respect_git_ignore ??
|
||||
@@ -253,19 +253,11 @@ ${finalExclusionPatternsForDescription
|
||||
filesToConsider.add(fullPath);
|
||||
}
|
||||
|
||||
// Add info about git-ignored files if any were filtered
|
||||
if (gitIgnoredCount > 0) {
|
||||
// Add info about ignored files if any were filtered
|
||||
if (ignoredCount > 0) {
|
||||
skippedFiles.push({
|
||||
path: `${gitIgnoredCount} file(s)`,
|
||||
reason: 'git ignored',
|
||||
});
|
||||
}
|
||||
|
||||
// Add info about gemini-ignored files if any were filtered
|
||||
if (geminiIgnoredCount > 0) {
|
||||
skippedFiles.push({
|
||||
path: `${geminiIgnoredCount} file(s)`,
|
||||
reason: 'gemini ignored',
|
||||
path: `${ignoredCount} file(s)`,
|
||||
reason: 'ignored by project ignore files',
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user