Skip to content

Commit 297ce00

Browse files
committed
Merge branch 'dev'
2 parents 651500e + eff2acb commit 297ce00

40 files changed

Lines changed: 1133 additions & 947 deletions

File tree

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

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,15 @@ type Props = {
2525
raw_instructions?: string
2626
}
2727

28-
export const ResponseReview: FC<Props> = ({
29-
files,
30-
has_multiple_workspaces,
31-
on_discard,
32-
on_approve,
33-
on_focus_file,
34-
on_go_to_file,
35-
on_toggle_file,
36-
on_intelligent_update,
37-
raw_instructions
38-
}) => {
28+
export const ResponseReview: FC<Props> = (props) => {
3929
const [last_clicked_file_index, set_last_clicked_file_index] = useState(0)
4030

4131
const handle_approve = () => {
42-
const accepted_files = files.filter((f) => f.is_checked)
43-
on_approve(accepted_files)
32+
const accepted_files = props.files.filter((f) => f.is_checked)
33+
props.on_approve(accepted_files)
4434
}
4535

46-
const fallback_count = files.filter((f) => f.is_fallback).length
36+
const fallback_count = props.files.filter((f) => f.is_fallback).length
4737

4838
const sorted_files = useMemo(() => {
4939
const get_sort_score = (file: FileInReview): number => {
@@ -55,20 +45,22 @@ export const ResponseReview: FC<Props> = ({
5545
}
5646
return 2
5747
}
58-
return [...files].sort((a, b) => get_sort_score(a) - get_sort_score(b))
59-
}, [files])
48+
return [...props.files].sort(
49+
(a, b) => get_sort_score(a) - get_sort_score(b)
50+
)
51+
}, [props.files])
6052

6153
return (
6254
<div className={styles.container}>
63-
{raw_instructions && (
64-
<div className={styles.instructions} title={raw_instructions}>
65-
{raw_instructions}
55+
{props.raw_instructions && (
56+
<div className={styles.instructions} title={props.raw_instructions}>
57+
{props.raw_instructions}
6658
</div>
6759
)}
6860
{fallback_count > 0 && (
6961
<div className={styles.info}>
70-
{files.length > 1
71-
? `${fallback_count} of ${files.length} files`
62+
{props.files.length > 1
63+
? `${fallback_count} of ${props.files.length} files`
7264
: 'The file'}{' '}
7365
required a fallback diff integration method, which may lead to
7466
inaccuracies. Looks off? Click{' '}
@@ -92,7 +84,7 @@ export const ResponseReview: FC<Props> = ({
9284
})}
9385
onClick={() => {
9486
set_last_clicked_file_index(index)
95-
on_focus_file({
87+
props.on_focus_file({
9688
file_path: file.file_path,
9789
workspace_name: file.workspace_name
9890
})
@@ -105,11 +97,11 @@ export const ResponseReview: FC<Props> = ({
10597
}`}
10698
>
10799
<div className={styles['item__left']}>
108-
{files.length > 1 && (
100+
{props.files.length > 1 && (
109101
<Checkbox
110102
checked={file.is_checked}
111103
on_change={(checked) => {
112-
on_toggle_file({
104+
props.on_toggle_file({
113105
file_path: file.file_path,
114106
workspace_name: file.workspace_name,
115107
is_checked: checked
@@ -129,7 +121,7 @@ export const ResponseReview: FC<Props> = ({
129121
</span>
130122

131123
<span>
132-
{has_multiple_workspaces && file.workspace_name
124+
{props.has_multiple_workspaces && file.workspace_name
133125
? `${file.workspace_name}/`
134126
: ''}
135127
{dir_path}
@@ -151,7 +143,7 @@ export const ResponseReview: FC<Props> = ({
151143
on_click={(e) => {
152144
e.stopPropagation()
153145
set_last_clicked_file_index(index)
154-
on_intelligent_update({
146+
props.on_intelligent_update({
155147
file_path: file.file_path,
156148
workspace_name: file.workspace_name
157149
})
@@ -164,7 +156,7 @@ export const ResponseReview: FC<Props> = ({
164156
on_click={(e) => {
165157
e.stopPropagation()
166158
set_last_clicked_file_index(index)
167-
on_focus_file({
159+
props.on_focus_file({
168160
file_path: file.file_path,
169161
workspace_name: file.workspace_name
170162
})
@@ -175,7 +167,7 @@ export const ResponseReview: FC<Props> = ({
175167
title="Go To File"
176168
on_click={(e) => {
177169
e.stopPropagation()
178-
on_go_to_file({
170+
props.on_go_to_file({
179171
file_path: file.file_path,
180172
workspace_name: file.workspace_name
181173
})
@@ -198,12 +190,12 @@ export const ResponseReview: FC<Props> = ({
198190
})}
199191
</div>
200192
<div className={styles.footer}>
201-
<Button on_click={on_discard} is_secondary>
193+
<Button on_click={props.on_discard} is_secondary>
202194
Discard
203195
</Button>
204196
<Button
205197
on_click={handle_approve}
206-
disabled={files.filter((f) => f.is_checked).length == 0}
198+
disabled={props.files.filter((f) => f.is_checked).length == 0}
207199
>
208200
Approve
209201
</Button>

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ export const store_original_file_states = async (
146146
return original_states
147147
}
148148

149-
// Helper function to extract content from patch for preview
150149
export const extract_content_from_patch = (
151150
patch_content: string,
152151
original_content: string
@@ -166,7 +165,6 @@ export const extract_content_from_patch = (
166165
}
167166
}
168167

169-
// Ensures all target files are closed before applying patches
170168
async function close_files_in_all_editor_groups(
171169
file_paths: string[],
172170
workspace_path: string
@@ -209,7 +207,6 @@ async function close_files_in_all_editor_groups(
209207
return [...new Map(closed_files.map((item) => [item.fsPath, item])).values()]
210208
}
211209

212-
// Reopens files that were closed before patch application
213210
async function reopen_closed_files(closed_files: vscode.Uri[]): Promise<void> {
214211
for (const uri of closed_files) {
215212
try {
@@ -225,7 +222,6 @@ async function reopen_closed_files(closed_files: vscode.Uri[]): Promise<void> {
225222
}
226223
}
227224

228-
// Opens, formats, and saves a list of files.
229225
async function process_modified_files(
230226
file_paths: string[],
231227
workspace_path: string
@@ -464,10 +460,15 @@ export const apply_git_patch = async (
464460
workspace_path
465461
)
466462

467-
await vscode.workspace.fs.writeFile(
468-
vscode.Uri.file(temp_file),
469-
Buffer.from(patch_content)
470-
)
463+
// Write patch file and ensure it's synced to disk before git apply reads it
464+
const patch_buffer = Buffer.from(patch_content)
465+
const fd = await fs.promises.open(temp_file, 'w')
466+
try {
467+
await fd.write(patch_buffer)
468+
await fd.sync() // Ensure data is flushed to disk
469+
} finally {
470+
await fd.close()
471+
}
471472

472473
let last_error: any = null
473474
let success = false
@@ -546,7 +547,6 @@ export const apply_git_patch = async (
546547
}
547548
}
548549

549-
// Cleanup and return
550550
if (success) {
551551
await process_modified_files(file_paths, workspace_path)
552552
await reopen_closed_files(closed_files)

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from 'vscode'
22
import axios from 'axios'
33
import * as path from 'path'
44
import * as fs from 'fs'
5-
import { ClipboardFile, parse_multiple_files } from '../utils/clipboard-parser'
5+
import { ClipboardFile } from '../utils/clipboard-parser'
66
import { sanitize_file_name, create_safe_path } from '@/utils/path-sanitizer'
77
import { Logger } from '@shared/utils/logger'
88
import { OriginalFileState } from '@/commands/apply-chat-response-command/types/original-file-state'
@@ -12,6 +12,7 @@ import { PanelProvider } from '@/views/panel/backend/panel-provider'
1212
import { dictionary } from '@shared/constants/dictionary'
1313
import { process_file } from '@/utils/intelligent-update-utils'
1414
import { FileProgress } from '@/views/panel/types/messages'
15+
import { parse_multiple_files } from '../utils/clipboard-parser/parsers'
1516

1617
export const handle_intelligent_update = async (params: {
1718
endpoint_url: string
@@ -46,11 +47,15 @@ export const handle_intelligent_update = async (params: {
4647
function_name: 'handle_intelligent_update',
4748
message: 'Processing multiple files'
4849
})
49-
const raw_files = parse_multiple_files({
50+
const raw_items = parse_multiple_files({
5051
response: params.chat_response,
5152
is_single_root_folder_workspace: params.is_single_root_folder_workspace
5253
})
5354

55+
const raw_files = raw_items.filter(
56+
(item): item is ClipboardFile => 'file_path' in item
57+
)
58+
5459
const files: ClipboardFile[] = []
5560
const skipped_files: string[] = []
5661

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ export const process_chat_response = async (
153153
]
154154
}
155155

156-
const item_type = clipboard_items.length > 0 ? clipboard_items[0].type : null
157-
158-
if (item_type == 'diff') {
159-
const patches = clipboard_items as DiffItem[]
156+
if (clipboard_items.some((item) => item.type == 'diff')) {
157+
const patches = clipboard_items.filter(
158+
(item): item is DiffItem => item.type == 'diff'
159+
)
160160
const rename_map = new Map<string, string>()
161161
patches.forEach((patch) => {
162162
if (patch.new_file_path && patch.file_path) {

0 commit comments

Comments
 (0)