Skip to content

Commit 51f302f

Browse files
committed
Add option to switch to Intelligent Update after successful patch or fast replace operations
1 parent a7cd8df commit 51f302f

1 file changed

Lines changed: 91 additions & 8 deletions

File tree

packages/vscode/src/commands/apply-chat-response-command/apply-chat-response-command.ts

Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,104 @@ export function apply_chat_response_command(context: vscode.ExtensionContext) {
256256
}
257257
}
258258
} else if (success_count > 0) {
259+
// All patches applied successfully - show both options now
259260
const response = await vscode.window.showInformationMessage(
260261
`Successfully applied ${success_count} patch${
261262
success_count != 1 ? 'es' : ''
262263
}.`,
263-
'Revert'
264+
'Revert',
265+
'Looks off, use intelligent mode'
264266
)
265267

266268
if (response == 'Revert' && all_original_states.length > 0) {
267269
await revert_files(all_original_states)
268270
context.workspaceState.update(LAST_APPLIED_CHANGES_STATE_KEY, null)
271+
} else if (response == 'Looks off, use intelligent mode') {
272+
// Revert the applied patches first
273+
await revert_files(all_original_states)
274+
275+
// Then try with intelligent update
276+
const api_providers_manager = new ApiProvidersManager(context)
277+
const file_refactoring_settings =
278+
await api_providers_manager.get_file_refactoring_tool_config()
279+
280+
if (!file_refactoring_settings) {
281+
vscode.window.showErrorMessage(
282+
'API provider or model is not configured for Intelligent update.'
283+
)
284+
return
285+
}
286+
287+
const provider = await api_providers_manager.get_provider(
288+
file_refactoring_settings.provider_name
289+
)
290+
291+
if (!provider) {
292+
vscode.window.showErrorMessage(
293+
'API provider not found for Intelligent update.'
294+
)
295+
return
296+
}
297+
298+
let endpoint_url = ''
299+
if (provider.type == 'built-in') {
300+
const provider_info = PROVIDERS[provider.name]
301+
endpoint_url = provider_info.base_url
302+
} else {
303+
endpoint_url = provider.base_url
304+
}
305+
306+
// Convert all patches to clipboard format for intelligent update
307+
const all_patches_text = clipboard_content.patches
308+
.map((patch) => `// ${patch.file_path}\n${patch.content}`)
309+
.join('\n\n')
310+
311+
try {
312+
const intelligent_update_states = await handle_intelligent_update(
313+
{
314+
endpoint_url,
315+
api_key: provider.api_key,
316+
model: file_refactoring_settings.model,
317+
temperature: file_refactoring_settings.temperature,
318+
clipboard_text: all_patches_text,
319+
context: context,
320+
is_single_root_folder_workspace
321+
}
322+
)
323+
324+
if (intelligent_update_states) {
325+
context.workspaceState.update(
326+
LAST_APPLIED_CHANGES_STATE_KEY,
327+
intelligent_update_states
328+
)
329+
const response = await vscode.window.showInformationMessage(
330+
`Successfully applied patches using intelligent update.`,
331+
'Revert'
332+
)
333+
334+
if (response == 'Revert') {
335+
await revert_files(intelligent_update_states)
336+
context.workspaceState.update(
337+
LAST_APPLIED_CHANGES_STATE_KEY,
338+
null
339+
)
340+
}
341+
} else {
342+
vscode.window.showInformationMessage(
343+
'Intelligent update was canceled. Original changes have been reverted.'
344+
)
345+
}
346+
} catch (error) {
347+
// Handle any errors during intelligent update
348+
Logger.error({
349+
function_name: 'apply_chat_response_command',
350+
message: 'Error during intelligent update of all patches'
351+
})
352+
353+
vscode.window.showErrorMessage(
354+
'Error during intelligent update. Original patches have been reverted.'
355+
)
356+
}
269357
}
270358
}
271359

@@ -453,13 +541,8 @@ export function apply_chat_response_command(context: vscode.ExtensionContext) {
453541

454542
// Show appropriate buttons based on whether any existing files were replaced
455543
if (selected_mode_label == 'Fast replace') {
456-
// Check if any of the affected files were existing files
457-
const has_existing_files = final_original_states.some(
458-
(state) => !state.is_new
459-
)
460-
const buttons = has_existing_files
461-
? ['Revert', 'Looks off, use intelligent mode']
462-
: ['Revert']
544+
// Always show both buttons regardless of whether files are new or existing
545+
const buttons = ['Revert', 'Looks off, use intelligent mode']
463546

464547
const response = await vscode.window.showInformationMessage(
465548
message,

0 commit comments

Comments
 (0)