mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-22 19:14:33 -07:00
[ide-mode] Use active files and selected text in user prompt (#4614)
This commit is contained in:
@@ -311,20 +311,40 @@ export class GeminiClient {
|
||||
}
|
||||
|
||||
if (this.config.getIdeMode()) {
|
||||
const activeFile = ideContext.getActiveFileContext();
|
||||
if (activeFile?.filePath) {
|
||||
let context = `
|
||||
This is the file that the user was most recently looking at:
|
||||
- Path: ${activeFile.filePath}`;
|
||||
if (activeFile.cursor) {
|
||||
context += `
|
||||
This is the cursor position in the file:
|
||||
- Cursor Position: Line ${activeFile.cursor.line}, Character ${activeFile.cursor.character}`;
|
||||
const openFiles = ideContext.getOpenFilesContext();
|
||||
if (openFiles) {
|
||||
const contextParts: string[] = [];
|
||||
if (openFiles.activeFile) {
|
||||
contextParts.push(
|
||||
`This is the file that the user was most recently looking at:\n- Path: ${openFiles.activeFile}`,
|
||||
);
|
||||
if (openFiles.cursor) {
|
||||
contextParts.push(
|
||||
`This is the cursor position in the file:\n- Cursor Position: Line ${openFiles.cursor.line}, Character ${openFiles.cursor.character}`,
|
||||
);
|
||||
}
|
||||
if (openFiles.selectedText) {
|
||||
contextParts.push(
|
||||
`This is the selected text in the active file:\n- ${openFiles.selectedText}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (openFiles.recentOpenFiles && openFiles.recentOpenFiles.length > 0) {
|
||||
const recentFiles = openFiles.recentOpenFiles
|
||||
.map((file) => `- ${file.filePath}`)
|
||||
.join('\n');
|
||||
contextParts.push(
|
||||
`Here are files the user has recently opened, with the most recent at the top:\n${recentFiles}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (contextParts.length > 0) {
|
||||
request = [
|
||||
{ text: contextParts.join('\n') },
|
||||
...(Array.isArray(request) ? request : [request]),
|
||||
];
|
||||
}
|
||||
request = [
|
||||
{ text: context },
|
||||
...(Array.isArray(request) ? request : [request]),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user