Skip to content

Commit 090ebb0

Browse files
committed
Support diff-based file updates and improve error handling for intelligent file processing
1 parent e3367fa commit 090ebb0

7 files changed

Lines changed: 211 additions & 165 deletions

File tree

‎apps/editor/src/commands/apply-chat-response-command/handlers/active-editor-intelligent-update-handler.ts‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import * as vscode from 'vscode'
22
import axios from 'axios'
3-
import { FileItem } from '../utils/clipboard-parser'
3+
import {
4+
FileItem,
5+
DiffItem,
6+
parse_response
7+
} from '../utils/clipboard-parser/clipboard-parser'
48
import { sanitize_file_name, create_safe_path } from '@/utils/path-sanitizer'
59
import { Logger } from '@shared/utils/logger'
610
import { OriginalFileState } from '@/commands/apply-chat-response-command/types/original-file-state'
711
import { ToolConfig } from '@/services/model-providers-manager'
812
import { PanelProvider } from '@/views/panel/backend/panel-provider'
913
import { dictionary } from '@shared/constants/dictionary'
1014
import { process_file } from '@/utils/intelligent-update-utils'
11-
import { parse_multiple_files } from '../utils/clipboard-parser/parsers'
1215

1316
export const handle_active_editor_intelligent_update = async (params: {
1417
endpoint_url: string
@@ -44,13 +47,14 @@ export const handle_active_editor_intelligent_update = async (params: {
4447
message: 'Processing single file update'
4548
})
4649

47-
const raw_items = parse_multiple_files({
50+
const raw_items = parse_response({
4851
response: params.chat_response,
4952
is_single_root_folder_workspace: params.is_single_root_folder_workspace
5053
})
5154

5255
const files = raw_items.filter(
53-
(item): item is FileItem => item.type == 'file'
56+
(item): item is FileItem | DiffItem =>
57+
item.type == 'file' || item.type == 'diff'
5458
)
5559

5660
if (files.length == 0) {
@@ -67,22 +71,27 @@ export const handle_active_editor_intelligent_update = async (params: {
6771
// We only handle the first file as this handler is intended for single-file fallback
6872
const file_item = files[0]
6973

74+
let target_file_path = file_item.file_path
75+
if (file_item.type == 'diff' && file_item.new_file_path) {
76+
target_file_path = file_item.new_file_path
77+
}
78+
7079
let workspace_root = default_workspace_path
7180
if (file_item.workspace_name && workspace_map.has(file_item.workspace_name)) {
7281
workspace_root = workspace_map.get(file_item.workspace_name)!
7382
}
7483

75-
const sanitized_path = sanitize_file_name(file_item.file_path)
84+
const sanitized_path = sanitize_file_name(target_file_path)
7685
const safe_path = create_safe_path(workspace_root, sanitized_path)
7786

7887
if (!safe_path) {
7988
vscode.window.showErrorMessage(
80-
dictionary.error_message.INVALID_FILE_PATH_TRAVERSAL(file_item.file_path)
89+
dictionary.error_message.INVALID_FILE_PATH_TRAVERSAL(target_file_path)
8190
)
8291
Logger.error({
8392
function_name: 'handle_active_editor_intelligent_update',
8493
message: 'Invalid file path',
85-
data: file_item.file_path
94+
data: target_file_path
8695
})
8796
return null
8897
}
@@ -110,7 +119,7 @@ export const handle_active_editor_intelligent_update = async (params: {
110119
model: params.config.model,
111120
temperature: params.config.temperature,
112121
reasoning_effort: params.config.reasoning_effort,
113-
file_path: file_item.file_path,
122+
file_path: target_file_path,
114123
file_content: original_content,
115124
instruction: file_item.content,
116125
cancel_token: cancel_token_source.token,
@@ -172,7 +181,7 @@ export const handle_active_editor_intelligent_update = async (params: {
172181

173182
return [
174183
{
175-
file_path: file_item.file_path,
184+
file_path: target_file_path,
176185
content: original_content,
177186
workspace_name: file_item.workspace_name
178187
}

‎apps/editor/src/utils/intelligent-update-utils.ts‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,8 @@ export const get_intelligent_update_config = async (
3333
let selected_config: ToolConfig | undefined
3434

3535
if (!show_quick_pick) {
36-
const recents = context.workspaceState.get<string[]>(
37-
RECENTLY_USED_INTELLIGENT_UPDATE_CONFIG_IDS_STATE_KEY
38-
)
39-
const last_selected_id = recents?.[0]
40-
41-
if (last_selected_id) {
42-
selected_config = intelligent_update_configs.find(
43-
(c) => get_tool_config_id(c) == last_selected_id
44-
)
45-
}
46-
47-
if (!selected_config) {
48-
selected_config =
49-
await api_providers_manager.get_default_intelligent_update_config()
50-
}
36+
selected_config =
37+
await api_providers_manager.get_default_intelligent_update_config()
5138
}
5239

5340
if (!selected_config || show_quick_pick) {

0 commit comments

Comments
 (0)