mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Add support for .geminiignore file (#757)
This commit is contained in:
@@ -5,10 +5,12 @@
|
||||
*/
|
||||
|
||||
import path from 'path';
|
||||
import micromatch from 'micromatch';
|
||||
import { SchemaValidator } from '../utils/schemaValidator.js';
|
||||
import { makeRelative, shortenPath } from '../utils/paths.js';
|
||||
import { BaseTool, ToolResult } from './tools.js';
|
||||
import { isWithinRoot, processSingleFileContent } from '../utils/fileUtils.js';
|
||||
import { Config } from '../config/config.js';
|
||||
|
||||
/**
|
||||
* Parameters for the ReadFile tool
|
||||
@@ -35,8 +37,12 @@ export interface ReadFileToolParams {
|
||||
*/
|
||||
export class ReadFileTool extends BaseTool<ReadFileToolParams, ToolResult> {
|
||||
static readonly Name: string = 'read_file';
|
||||
private readonly geminiIgnorePatterns: string[];
|
||||
|
||||
constructor(private rootDirectory: string) {
|
||||
constructor(
|
||||
private rootDirectory: string,
|
||||
config: Config,
|
||||
) {
|
||||
super(
|
||||
ReadFileTool.Name,
|
||||
'ReadFile',
|
||||
@@ -64,6 +70,7 @@ export class ReadFileTool extends BaseTool<ReadFileToolParams, ToolResult> {
|
||||
},
|
||||
);
|
||||
this.rootDirectory = path.resolve(rootDirectory);
|
||||
this.geminiIgnorePatterns = config.getGeminiIgnorePatterns() || [];
|
||||
}
|
||||
|
||||
validateToolParams(params: ReadFileToolParams): string | null {
|
||||
@@ -89,6 +96,19 @@ export class ReadFileTool extends BaseTool<ReadFileToolParams, ToolResult> {
|
||||
if (params.limit !== undefined && params.limit <= 0) {
|
||||
return 'Limit must be a positive number';
|
||||
}
|
||||
|
||||
// Check against .geminiignore patterns
|
||||
if (this.geminiIgnorePatterns.length > 0) {
|
||||
const relativePath = makeRelative(params.path, this.rootDirectory);
|
||||
if (micromatch.isMatch(relativePath, this.geminiIgnorePatterns)) {
|
||||
// Get patterns that matched to show in the error message
|
||||
const matchingPatterns = this.geminiIgnorePatterns.filter((p) =>
|
||||
micromatch.isMatch(relativePath, p),
|
||||
);
|
||||
return `File path '${shortenPath(relativePath)}' is ignored by the following .geminiignore pattern(s):\n\n${matchingPatterns.join('\n')}`;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user