Skip to content

Commit 33bfff0

Browse files
committed
Rename diff_fallback_method to diff_application_method and remove is_fallback flag across all files
1 parent 3e41ba3 commit 33bfff0

9 files changed

Lines changed: 36 additions & 64 deletions

File tree

packages/shared/src/types/file-in-preview.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ export type FileInPreview = {
77
is_deleted?: boolean
88
lines_added: number
99
lines_removed: number
10-
is_fallback?: boolean
1110
is_replaced?: boolean
12-
diff_fallback_method?: 'recount' | 'search_and_replace'
11+
diff_application_method?: 'recount' | 'search_and_replace'
1312
content?: string
1413
}
1514

packages/ui/src/components/editor/panel/ResponsePreview/ResponsePreview.stories.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,14 @@ const files_using_fallbacks = [
4545
{
4646
type: 'file',
4747
file_path: 'src/complex-logic.js',
48-
is_fallback: true,
49-
diff_fallback_method: 'recount',
48+
diff_application_method: 'recount',
5049
lines_added: 15,
5150
lines_removed: 12
5251
},
5352
{
5453
type: 'file',
5554
file_path: 'src/aggressive-fallback.css',
56-
is_fallback: true,
57-
diff_fallback_method: 'search_and_replace',
55+
diff_application_method: 'search_and_replace',
5856
lines_added: 8,
5957
lines_removed: 3
6058
}

packages/ui/src/components/editor/panel/ResponsePreview/ResponsePreview.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ export const ResponsePreview: FC<Props> = (props) => {
7272
const files_in_preview = props.items.filter(
7373
(i) => 'file_path' in i
7474
) as FileInPreview[]
75-
const fallback_count = files_in_preview.filter((f) => f.is_fallback).length
75+
const aggressive_fallback_count = files_in_preview.filter(
76+
(f) => f.diff_application_method == 'search_and_replace'
77+
).length
7678

7779
const get_instructions_font_size_class = (text: string): string => {
7880
const length = text.length
@@ -105,13 +107,13 @@ export const ResponsePreview: FC<Props> = (props) => {
105107
{props.raw_instructions}
106108
</div>
107109
)}
108-
{fallback_count > 0 && (
110+
{aggressive_fallback_count > 0 && (
109111
<div className={styles.info}>
110112
{files_in_preview.length > 1
111-
? `${fallback_count} of ${files_in_preview.length} files`
113+
? `${aggressive_fallback_count} of ${files_in_preview.length} files`
112114
: 'The file'}{' '}
113-
required a fallback diff integration method, which may lead to
114-
inaccuracies. Looks off? Click{' '}
115+
required an aggressive fallback diff integration method, which may
116+
lead to inaccuracies. Looks off? Click{' '}
115117
<span className="codicon codicon-sparkle" /> action to fix a file
116118
with the Intelligent Update API tool.
117119
</div>
@@ -142,7 +144,7 @@ export const ResponsePreview: FC<Props> = (props) => {
142144
}}
143145
role="button"
144146
title={`${file.file_path}${
145-
file.diff_fallback_method == 'search_and_replace'
147+
file.diff_application_method == 'search_and_replace'
146148
? '\nUsed aggressive fallback method. Call Intelligent Update API tool, if needed.'
147149
: ''
148150
}`}
@@ -167,7 +169,7 @@ export const ResponsePreview: FC<Props> = (props) => {
167169
})}
168170
>
169171
<span>
170-
{file.diff_fallback_method == 'search_and_replace' &&
172+
{file.diff_application_method == 'search_and_replace' &&
171173
'⚠ '}
172174
{file_name}
173175
</span>
@@ -182,13 +184,13 @@ export const ResponsePreview: FC<Props> = (props) => {
182184
</div>
183185
<div className={styles.list__file__right}>
184186
<div className={styles['list__file__actions']}>
185-
{(file.is_fallback || file.is_replaced) && (
187+
{(file.diff_application_method || file.is_replaced) && (
186188
<IconButton
187189
codicon_icon="sparkle"
188190
title={`Call Intelligent Update API tool${
189-
file.diff_fallback_method == 'recount'
191+
file.diff_application_method == 'recount'
190192
? ' (fallback used: git apply with --recount flag)'
191-
: file.diff_fallback_method ==
193+
: file.diff_application_method ==
192194
'search_and_replace'
193195
? ' (fallback used: search and replace matching fragments)'
194196
: ''

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,8 @@ export const apply_chat_response_command = (params: {
202202
is_deleted,
203203
lines_added: diff_stats.lines_added,
204204
lines_removed: diff_stats.lines_removed,
205-
is_fallback: state.is_fallback,
206205
is_replaced: state.is_replaced,
207-
diff_fallback_method: state.diff_fallback_method,
206+
diff_application_method: state.diff_application_method,
208207
content: current_content,
209208
is_checked: true
210209
})

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

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ const handle_new_file_patch = async (
291291
): Promise<{
292292
success: boolean
293293
original_states?: OriginalFileState[]
294-
diff_fallback_method?: 'recount' | 'search_and_replace'
294+
diff_application_method?: 'recount' | 'search_and_replace'
295295
}> => {
296296
const file_paths = extract_file_paths_from_patch(patch_content)
297297
if (file_paths.length != 1) {
@@ -366,7 +366,7 @@ const handle_deleted_file_patch = async (
366366
): Promise<{
367367
success: boolean
368368
original_states?: OriginalFileState[]
369-
diff_fallback_method?: 'recount' | 'search_and_replace'
369+
diff_application_method?: 'recount' | 'search_and_replace'
370370
}> => {
371371
const file_paths = extract_file_paths_from_patch(patch_content)
372372
if (file_paths.length != 1) {
@@ -435,7 +435,7 @@ export const apply_git_patch = async (
435435
): Promise<{
436436
success: boolean
437437
original_states?: OriginalFileState[]
438-
diff_fallback_method?: 'recount' | 'search_and_replace'
438+
diff_application_method?: 'recount' | 'search_and_replace'
439439
}> => {
440440
const patch_info = parse_patch_header(patch_content, workspace_path)
441441

@@ -474,55 +474,33 @@ export const apply_git_patch = async (
474474

475475
let last_error: any = null
476476
let success = false
477-
let diff_fallback_method: 'recount' | 'search_and_replace' | undefined =
477+
let diff_application_method: 'recount' | 'search_and_replace' | undefined =
478478
undefined
479479

480480
if (patch_info.is_renaming) {
481481
// Skip git apply and fallbacks, renaming here is a base case where no content is changing, just paths. File is already copied.
482482
success = true
483483
}
484484

485-
// Attempt 1: Standard git apply
485+
// Attempt 1: git apply with --recount
486486
if (!success) {
487-
try {
488-
await execAsync(
489-
`git apply --whitespace=fix --ignore-whitespace "${temp_file}"`,
490-
{ cwd: workspace_path }
491-
)
492-
success = true
493-
Logger.info({
494-
function_name: 'apply_git_patch',
495-
message: 'Patch applied successfully with standard git apply.'
496-
})
497-
} catch (error) {
498-
last_error = error
499-
}
500-
}
501-
502-
// Attempt 2: git apply with --recount
503-
if (!success) {
504-
Logger.warn({
505-
function_name: 'apply_git_patch',
506-
message: 'Standard git apply failed, trying with --recount.',
507-
data: { error: last_error }
508-
})
509487
try {
510488
await execAsync(
511489
`git apply --whitespace=fix --ignore-whitespace --recount "${temp_file}"`,
512490
{ cwd: workspace_path }
513491
)
514492
success = true
515-
diff_fallback_method = 'recount'
493+
diff_application_method = 'recount'
516494
Logger.info({
517495
function_name: 'apply_git_patch',
518-
message: 'Patch applied successfully with --recount fallback.'
496+
message: 'Patch applied successfully with --recount.'
519497
})
520498
} catch (error) {
521499
last_error = error
522500
}
523501
}
524502

525-
// Attempt 3: Custom diff processor
503+
// Attempt 2: Custom diff processor
526504
if (!success) {
527505
Logger.warn({
528506
function_name: 'apply_git_patch',
@@ -538,7 +516,7 @@ export const apply_git_patch = async (
538516
diff_path_patch: temp_file
539517
})
540518
success = true
541-
diff_fallback_method = 'search_and_replace'
519+
diff_application_method = 'search_and_replace'
542520
Logger.info({
543521
function_name: 'apply_git_patch',
544522
message: 'Patch applied successfully with custom processor fallback.'
@@ -555,7 +533,7 @@ export const apply_git_patch = async (
555533
return {
556534
success: true,
557535
original_states: original_states,
558-
diff_fallback_method
536+
diff_application_method
559537
}
560538
} else {
561539
// All methods failed, throw the last logged error to be handled by the outer catch

packages/vscode/src/commands/apply-chat-response-command/handlers/restore-preview-handler.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ export const handle_restore_preview = async (
8383
workspace_name: file.workspace_name,
8484
is_deleted: file.is_deleted,
8585
is_checked: file.is_checked,
86-
is_fallback: file.is_fallback,
8786
is_replaced: file.is_replaced,
88-
diff_fallback_method: file.diff_fallback_method
87+
diff_application_method: file.diff_application_method
8988
})
9089

9190
if (file.is_checked !== false) {

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export const process_chat_response = async (
197197
const applied_patches: {
198198
patch: Diff
199199
original_states: OriginalFileState[]
200-
diff_fallback_method?: 'recount' | 'search_and_replace'
200+
diff_application_method?: 'recount' | 'search_and_replace'
201201
}[] = []
202202
let any_patch_used_fallback = false
203203

@@ -214,10 +214,9 @@ export const process_chat_response = async (
214214
const result = await apply_git_patch(patch.content, workspace_path)
215215

216216
if (result.success) {
217-
if (result.diff_fallback_method && result.original_states) {
217+
if (result.diff_application_method && result.original_states) {
218218
for (const state of result.original_states) {
219-
state.is_fallback = true
220-
state.diff_fallback_method = result.diff_fallback_method
219+
state.diff_application_method = result.diff_application_method
221220
}
222221
}
223222
success_count++
@@ -228,10 +227,10 @@ export const process_chat_response = async (
228227
applied_patches.push({
229228
patch,
230229
original_states: result.original_states,
231-
diff_fallback_method: result.diff_fallback_method
230+
diff_application_method: result.diff_application_method
232231
})
233232
}
234-
if (result.diff_fallback_method) {
233+
if (result.diff_application_method) {
235234
any_patch_used_fallback = true
236235
}
237236
} else {
@@ -343,10 +342,10 @@ export const process_chat_response = async (
343342
if (any_patch_used_fallback) {
344343
;(async () => {
345344
const fallback_patches_count = applied_patches.filter(
346-
(p) => p.diff_fallback_method
345+
(p) => p.diff_application_method
347346
).length
348347
const fallback_files = applied_patches
349-
.filter((p) => p.diff_fallback_method)
348+
.filter((p) => p.diff_application_method)
350349
.map((p) => p.patch.file_path)
351350

352351
Logger.info({

packages/vscode/src/commands/apply-chat-response-command/types/original-file-state.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ export type OriginalFileState = {
66
cursor_offset?: number
77
new_file_path?: string
88
file_path_to_restore?: string
9-
is_fallback?: boolean
10-
diff_fallback_method?: 'recount' | 'search_and_replace'
9+
diff_application_method?: 'recount' | 'search_and_replace'
1110
is_replaced?: boolean
1211
is_deleted?: boolean
1312
is_checked?: boolean

packages/vscode/src/commands/apply-chat-response-command/utils/preview/file-preparer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ export const prepare_files_from_original_states = async (params: {
7373
is_deleted,
7474
lines_added: diff_stats.lines_added,
7575
lines_removed: diff_stats.lines_removed,
76-
is_fallback: state.is_fallback,
7776
is_replaced: state.is_replaced,
78-
diff_fallback_method: state.diff_fallback_method,
77+
diff_application_method: state.diff_application_method,
7978
is_checked: state.is_checked ?? true
8079
}
8180

0 commit comments

Comments
 (0)