|
1 | 1 | import * as vscode from 'vscode' |
2 | 2 | import * as fs from 'fs' |
| 3 | +import * as path from 'path' |
3 | 4 | import { parse_response, ClipboardFile } from './utils/clipboard-parser' |
4 | 5 | import { |
5 | 6 | LAST_APPLIED_CHANGES_EDITOR_STATE_STATE_KEY, |
@@ -728,6 +729,87 @@ export const apply_chat_response_command = ( |
728 | 729 | return null |
729 | 730 | } else { |
730 | 731 | if (!clipboard_content.files || clipboard_content.files.length == 0) { |
| 732 | + const editor = vscode.window.activeTextEditor |
| 733 | + if (editor) { |
| 734 | + const choice = await vscode.window.showWarningMessage( |
| 735 | + 'No valid code blocks found in the clipboard text. Apply it to the active editor with the Intelligent Update API tool?', |
| 736 | + { modal: true }, |
| 737 | + 'Apply' |
| 738 | + ) |
| 739 | + |
| 740 | + if (choice == 'Apply') { |
| 741 | + const document = editor.document |
| 742 | + const workspaceFolder = vscode.workspace.getWorkspaceFolder( |
| 743 | + document.uri |
| 744 | + ) |
| 745 | + const relativePath = ( |
| 746 | + workspaceFolder |
| 747 | + ? path.relative( |
| 748 | + workspaceFolder.uri.fsPath, |
| 749 | + document.uri.fsPath |
| 750 | + ) |
| 751 | + : path.basename(document.uri.fsPath) |
| 752 | + ).replace(/\\/g, '/') |
| 753 | + |
| 754 | + const workspace_name = workspaceFolder?.name |
| 755 | + |
| 756 | + const file_path_for_block = |
| 757 | + workspace_name && !is_single_root_folder_workspace |
| 758 | + ? `${workspace_name}/${relativePath}` |
| 759 | + : relativePath |
| 760 | + |
| 761 | + const fake_chat_response = `\`\`\`\n// ${file_path_for_block}\n${chat_response}\n\`\`\`` |
| 762 | + |
| 763 | + const api_providers_manager = new ModelProvidersManager(context) |
| 764 | + const config_result = await get_intelligent_update_config( |
| 765 | + api_providers_manager, |
| 766 | + false, |
| 767 | + context |
| 768 | + ) |
| 769 | + |
| 770 | + if (!config_result) { |
| 771 | + return null |
| 772 | + } |
| 773 | + |
| 774 | + const { provider, config: intelligent_update_config } = |
| 775 | + config_result |
| 776 | + |
| 777 | + let endpoint_url = '' |
| 778 | + if (provider.type == 'built-in') { |
| 779 | + const provider_info = |
| 780 | + PROVIDERS[provider.name as keyof typeof PROVIDERS] |
| 781 | + endpoint_url = provider_info.base_url |
| 782 | + } else { |
| 783 | + endpoint_url = provider.base_url |
| 784 | + } |
| 785 | + |
| 786 | + const intelligent_update_states = |
| 787 | + await handle_intelligent_update({ |
| 788 | + endpoint_url, |
| 789 | + api_key: provider.api_key, |
| 790 | + config: intelligent_update_config, |
| 791 | + chat_response: fake_chat_response, |
| 792 | + context: context, |
| 793 | + is_single_root_folder_workspace, |
| 794 | + view_provider |
| 795 | + }) |
| 796 | + |
| 797 | + if (intelligent_update_states) { |
| 798 | + update_undo_button_state( |
| 799 | + intelligent_update_states, |
| 800 | + chat_response, |
| 801 | + args?.original_editor_state |
| 802 | + ) |
| 803 | + |
| 804 | + return { |
| 805 | + original_states: intelligent_update_states, |
| 806 | + chat_response |
| 807 | + } |
| 808 | + } |
| 809 | + return null |
| 810 | + } |
| 811 | + } |
| 812 | + |
731 | 813 | vscode.window.showWarningMessage( |
732 | 814 | dictionary.warning_message.NO_VALID_CODE_BLOCKS_IN_CLIPBOARD |
733 | 815 | ) |
|
0 commit comments