|
1 | 1 | import * as vscode from 'vscode' |
2 | 2 | import { FilesCollector } from '../helpers/files-collector' |
3 | 3 | import { WebSocketManager } from '../services/websocket-manager' |
| 4 | +import { replace_selection_placeholder } from '../utils/replace-selection-placeholder' |
4 | 5 | import { apply_preset_affixes_to_instruction } from '../helpers/apply-preset-affixes' |
5 | 6 | import { EditFormat } from '@shared/types/edit-format' |
6 | 7 |
|
@@ -42,8 +43,12 @@ async function handle_chat_command( |
42 | 43 | : '' |
43 | 44 |
|
44 | 45 | if (editor && !editor.selection.isEmpty) { |
45 | | - const selected_text = editor.document.getText(editor.selection) |
46 | | - instructions = `\`${current_file_path}\`\n\`\`\`\n${selected_text}\n\`\`\`\n${instructions}` |
| 46 | + if (instructions.includes('@selection')) { |
| 47 | + instructions = replace_selection_placeholder(instructions) |
| 48 | + } else { |
| 49 | + const selected_text = editor.document.getText(editor.selection) |
| 50 | + instructions = `\`${current_file_path}\`\n\`\`\`\n${selected_text}\n\`\`\`\n${instructions}` |
| 51 | + } |
47 | 52 | } |
48 | 53 |
|
49 | 54 | const files_collector = new FilesCollector( |
@@ -143,8 +148,12 @@ export function chat_using_command( |
143 | 148 |
|
144 | 149 | let processed_instructions = instructions |
145 | 150 | if (editor && !editor.selection.isEmpty) { |
146 | | - const selected_text = editor.document.getText(editor.selection) |
147 | | - processed_instructions = `\`${current_file_path}\`\n\`\`\`\n${selected_text}\n\`\`\`\n${instructions}` |
| 151 | + if (instructions.includes('@selection')) { |
| 152 | + processed_instructions = replace_selection_placeholder(instructions) |
| 153 | + } else { |
| 154 | + const selected_text = editor.document.getText(editor.selection) |
| 155 | + processed_instructions = `\`${current_file_path}\`\n\`\`\`\n${selected_text}\n\`\`\`\n${instructions}` |
| 156 | + } |
148 | 157 | } |
149 | 158 |
|
150 | 159 | const config = vscode.workspace.getConfiguration('codeWebChat') |
|
0 commit comments