mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-14 07:10:34 -07:00
fix(core): auto-correct file paths in smart edit where possible (#9526)
This commit is contained in:
@@ -4,7 +4,9 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import fs from 'node:fs/promises';
|
||||
import * as fs from 'node:fs/promises';
|
||||
import * as path from 'node:path';
|
||||
import { globSync } from 'glob';
|
||||
|
||||
/**
|
||||
* Interface for file system operations that may be delegated to different implementations
|
||||
@@ -25,6 +27,15 @@ export interface FileSystemService {
|
||||
* @param content - The content to write
|
||||
*/
|
||||
writeTextFile(filePath: string, content: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* Finds files with a given name within specified search paths.
|
||||
*
|
||||
* @param fileName - The name of the file to find.
|
||||
* @param searchPaths - An array of directory paths to search within.
|
||||
* @returns An array of absolute paths to the found files.
|
||||
*/
|
||||
findFiles(fileName: string, searchPaths: readonly string[]): string[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,4 +49,17 @@ export class StandardFileSystemService implements FileSystemService {
|
||||
async writeTextFile(filePath: string, content: string): Promise<void> {
|
||||
await fs.writeFile(filePath, content, 'utf-8');
|
||||
}
|
||||
|
||||
findFiles(fileName: string, searchPaths: readonly string[]): string[] {
|
||||
const foundFiles: string[] = [];
|
||||
for (const searchPath of searchPaths) {
|
||||
const pattern = path.join(searchPath, '**', fileName);
|
||||
const matches = globSync(pattern, {
|
||||
nodir: true,
|
||||
absolute: true,
|
||||
});
|
||||
foundFiles.push(...matches);
|
||||
}
|
||||
return foundFiles;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user