Skip to content

Commit 839123b

Browse files
committed
Update patch application logic to track proposed content across fallback methods and refine response preview UI components
1 parent d88d16b commit 839123b

7 files changed

Lines changed: 37 additions & 20 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
**Code Web Chat is a free and open-source AI coding extension designed for speed**, built for VS Code family of editors (Cursor, Antigravity, VSCodium, etc.).
1616

17-
👉️ **Simple coding prompts for...**
17+
👉️ **Construct coding prompts for...**
1818

1919
- Chatbots—_ChatGPT, Gemini, Claude, Grok, DeepSeek, etc._
2020
- APIs—_Gemini API, OpenRouter, local Ollama, etc._

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const get_file_message = (file: FileInPreview): FileMessage | null => {
4343
if (file.fixed_with_intelligent_update) {
4444
return {
4545
type: 'success',
46-
text: 'Fixed with successfully'
46+
text: 'Fixed successfully'
4747
}
4848
} else if (file.apply_failed) {
4949
return {
@@ -115,7 +115,9 @@ export const ResponsePreview: FC<Props> = (props) => {
115115
const aggressive_fallback_count = useMemo(
116116
() =>
117117
files_in_preview.filter(
118-
(f) => f.diff_application_method == 'search_and_replace'
118+
(f) =>
119+
f.diff_application_method == 'search_and_replace' &&
120+
!f.fixed_with_intelligent_update
119121
).length,
120122
[files_in_preview]
121123
)
@@ -203,7 +205,7 @@ export const ResponsePreview: FC<Props> = (props) => {
203205
onClick={() => props.on_fix_all_failed()}
204206
>
205207
<span className="codicon codicon-sparkle" />
206-
<span>Fix all</span>
208+
<span>{error_count > 1 ? 'Fix all' : 'Fix'}</span>
207209
</div>
208210
</div>
209211
)}
@@ -250,7 +252,8 @@ export const ResponsePreview: FC<Props> = (props) => {
250252
file.apply_failed &&
251253
!file.fixed_with_intelligent_update,
252254
[styles['list__item__file--warning']]:
253-
file.diff_application_method == 'search_and_replace'
255+
file.diff_application_method == 'search_and_replace' &&
256+
!file.fixed_with_intelligent_update
254257
})}
255258
onClick={() => {
256259
set_last_clicked_file_index(index)
@@ -405,7 +408,7 @@ export const ResponsePreview: FC<Props> = (props) => {
405408
{'show_actions' in message_obj &&
406409
message_obj.show_actions && (
407410
<div className={styles['list__message__actions']}>
408-
{file.ai_content && (
411+
{file.ai_content && !file.is_applying && (
409412
<div
410413
className={
411414
styles['list__message__actions__item']

‎packages/ui/src/components/editor/panel/modals/ApiManagerModal/ApiManagerModal.module.scss‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
display: flex;
88
align-items: flex-end;
99
justify-content: flex-end;
10-
padding: 0 12px 48px 12px;
10+
padding: 0 12px 48px 8px;
1111
pointer-events: none;
1212
}
1313

@@ -17,7 +17,7 @@
1717
position: relative;
1818
pointer-events: all;
1919
z-index: 1;
20-
border-radius: 12px;
20+
border-radius: 8px;
2121
color: var(--vscode-quickInput-foreground);
2222
background-color: var(--vscode-quickInput-background);
2323
border: 1px solid var(--vscode-focusBorder);
@@ -35,7 +35,7 @@
3535
text-transform: uppercase;
3636
display: flex;
3737
align-items: center;
38-
padding: 0 10px;
38+
padding: 0 8px;
3939
height: 28px;
4040
transform: translateY(3px);
4141
transition: transform var(--transition-duration-250)
@@ -70,7 +70,7 @@
7070
align-items: center;
7171
justify-content: space-between;
7272
gap: 4px;
73-
padding: 0 10px;
73+
padding: 0 8px;
7474
height: 22px;
7575
width: 100%;
7676
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ export const apply_git_patch = async (
476476
let success = false
477477
let diff_application_method: 'recount' | 'search_and_replace' | undefined =
478478
undefined
479+
let applied_content: string | undefined
479480

480481
if (patch_info.is_renaming) {
481482
// Skip git apply and fallbacks, renaming here is a base case where no content is changing, just paths. File is already copied.
@@ -521,7 +522,7 @@ export const apply_git_patch = async (
521522
try {
522523
const file_path_safe = create_safe_path(workspace_path, file_paths[0])
523524
if (file_path_safe == null) throw new Error('File path is null')
524-
await process_diff({
525+
applied_content = await process_diff({
525526
file_path: file_path_safe,
526527
diff_path_patch: temp_file
527528
})
@@ -540,6 +541,17 @@ export const apply_git_patch = async (
540541
await process_modified_files(file_paths, workspace_path)
541542
await reopen_closed_files(closed_files)
542543
await vscode.workspace.fs.delete(vscode.Uri.file(temp_file))
544+
545+
if (original_states && applied_content && file_paths.length > 0) {
546+
const processed_path = file_paths[0]
547+
const state = original_states.find(
548+
(s) => s.file_path === processed_path
549+
)
550+
if (state) {
551+
state.proposed_content = applied_content
552+
}
553+
}
554+
543555
return {
544556
success: true,
545557
original_states: original_states,

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ export const process_chat_response = async (
5959
return {
6060
...state,
6161
ai_content:
62-
file_in_preview?.content ??
62+
file_in_preview?.ai_content ??
6363
file_in_preview?.proposed_content ??
64-
file_in_preview?.ai_content,
64+
file_in_preview?.content,
6565
proposed_content: file_in_preview?.proposed_content,
6666
is_checked: file_in_preview?.is_checked,
6767
apply_failed: file_in_preview?.apply_failed,
@@ -219,6 +219,9 @@ export const process_chat_response = async (
219219
if (result.diff_application_method && result.original_states) {
220220
for (const state of result.original_states) {
221221
state.diff_application_method = result.diff_application_method
222+
if (result.diff_application_method == 'search_and_replace') {
223+
state.ai_content = patch.content
224+
}
222225
}
223226
}
224227
if (result.original_states) {
@@ -236,9 +239,10 @@ export const process_chat_response = async (
236239
}
237240
} else {
238241
if (result.original_states) {
239-
result.original_states.forEach((state) => {
242+
for (const state of result.original_states) {
240243
state.apply_failed = true
241-
})
244+
state.ai_content = patch.content
245+
}
242246
all_original_states = all_original_states.concat(
243247
result.original_states
244248
)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SearchBlock {
2828
export const process_diff = async (params: {
2929
file_path: string
3030
diff_path_patch: string
31-
}): Promise<void> => {
31+
}): Promise<string> => {
3232
const file_content = fs.readFileSync(params.file_path, 'utf8')
3333
const diff_patch_content = fs.readFileSync(params.diff_path_patch, 'utf8')
3434

@@ -46,6 +46,7 @@ export const process_diff = async (params: {
4646
function_name: 'process_diff',
4747
message: 'File saved successfully'
4848
})
49+
return result
4950
} catch (error) {
5051
throw new Error('Failed to save file after applying diff patch')
5152
}

‎packages/vscode/src/commands/apply-chat-response-command/utils/preview/workspace-listener.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,10 +657,6 @@ export const setup_workspace_listeners = (
657657
return
658658
}
659659

660-
if (file_to_discard.previewable_file.fixed_with_intelligent_update) {
661-
file_to_discard.previewable_file.fixed_with_intelligent_update = false
662-
}
663-
664660
const proposed = file_to_discard.previewable_file.proposed_content
665661

666662
await vscode.workspace.fs.writeFile(
@@ -772,6 +768,7 @@ export const setup_workspace_listeners = (
772768
)
773769
if (file) {
774770
file.previewable_file.fixed_with_intelligent_update = true
771+
update_response_history(panel_provider, created_at, file.previewable_file)
775772
}
776773
}
777774

0 commit comments

Comments
 (0)