feat: wrap selected text in code blocks for IDE context

This commit is contained in:
xwj02155382
2026-01-08 16:06:21 +08:00
parent 0f1cb162c9
commit ca4c36f233
2 changed files with 20 additions and 7 deletions

View File

@@ -1066,7 +1066,10 @@ describe('Gemini Client (client.ts)', () => {
Active file:
Path: /path/to/active/file.ts
Cursor: line 5, character 10
Selected text: hello
Selected text:
\`\`\`
hello
\`\`\`
Other open files:
- /path/to/recent/file1.ts
@@ -1174,7 +1177,10 @@ Other open files:
Active file:
Path: /path/to/active/file.ts
Cursor: line 5, character 10
Selected text: hello`;
Selected text:
\`\`\`
hello
\`\`\``;
const expectedRequest = [{ text: expectedContext }];
expect(mockChat.addHistory).toHaveBeenCalledWith({
role: 'user',

View File

@@ -237,7 +237,10 @@ export class GeminiClient {
);
}
if (activeFile.selectedText) {
contextLines.push(` Selected text: ${activeFile.selectedText}`);
contextLines.push(' Selected text:');
contextLines.push('```');
contextLines.push(activeFile.selectedText);
contextLines.push('```');
}
}
@@ -332,9 +335,10 @@ export class GeminiClient {
);
}
if (currentActiveFile.selectedText) {
changeLines.push(
` Selected text: ${currentActiveFile.selectedText}`,
);
changeLines.push(' Selected text:');
changeLines.push('```');
changeLines.push(currentActiveFile.selectedText);
changeLines.push('```');
}
} else {
const lastCursor = lastActiveFile.cursor;
@@ -364,7 +368,10 @@ export class GeminiClient {
changeLines.push('Selection changed:');
changeLines.push(` Path: ${currentActiveFile.path}`);
if (currentSelectedText) {
changeLines.push(` Selected text: ${currentSelectedText}`);
changeLines.push(' Selected text:');
changeLines.push('```');
changeLines.push(currentSelectedText);
changeLines.push('```');
} else {
changeLines.push(' Selected text: (none)');
}