[ide-mode] Add active file to user model request (#4312)

This commit is contained in:
christine betts 2025-07-17 14:35:23 +00:00 committed by GitHub
parent 0d64355be6
commit cbda781f73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -198,6 +198,7 @@ describe('Gemini Client (client.ts)', () => {
getQuotaErrorOccurred: vi.fn().mockReturnValue(false),
setQuotaErrorOccurred: vi.fn(),
getNoBrowser: vi.fn().mockReturnValue(false),
getIdeMode: vi.fn().mockReturnValue(false),
};
return mock as unknown as Config;
});

View File

@ -41,6 +41,7 @@ import {
import { ProxyAgent, setGlobalDispatcher } from 'undici';
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
import { LoopDetectionService } from '../services/loopDetectionService.js';
import { ideContext } from '../services/ideContext.js';
function isThinkingSupported(model: string) {
if (model.startsWith('gemini-2.5')) return true;
@ -303,6 +304,25 @@ export class GeminiClient {
if (compressed) {
yield { type: GeminiEventType.ChatCompressed, value: compressed };
}
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}`;
}
request = [
{ text: context },
...(Array.isArray(request) ? request : [request]),
];
}
}
const turn = new Turn(this.getChat(), prompt_id);
const resultStream = turn.run(request, signal);
for await (const event of resultStream) {