Skip to content

Commit a07c80d

Browse files
committed
Stabilize patch application by correcting the logic for detecting diff items and introducing a brief delay before executing external git commands
1 parent c204fbd commit a07c80d

4 files changed

Lines changed: 28 additions & 37 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ export const apply_git_patch = async (
468468
vscode.Uri.file(temp_file),
469469
Buffer.from(patch_content)
470470
)
471+
await new Promise((r) => setTimeout(r, 100))
471472

472473
let last_error: any = null
473474
let success = false

‎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) {

‎packages/vscode/src/views/panel/frontend/hooks/use-panel.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { ApiMode, WebMode } from '@shared/types/modes'
1010
import { post_message } from '../utils/post_message'
1111
import { FileInReview } from '@shared/types/file-in-review'
1212

13-
type CheckedFileInReview = FileInReview & { is_checked: boolean }
1413
type ResponseHistoryItem = {
1514
response: string
1615
raw_instructions?: string
@@ -26,8 +25,7 @@ export const use_panel = (vscode: any) => {
2625
useState(0)
2726
const [version, set_version] = useState<string>('')
2827
const [updating_preset, set_updating_preset] = useState<Preset>()
29-
const [files_to_review, set_files_to_review] =
30-
useState<CheckedFileInReview[]>()
28+
const [files_to_review, set_files_to_review] = useState<FileInReview[]>()
3129
const [raw_instructions, set_raw_instructions] = useState<string>()
3230
const [progress_state, set_progress_state] = useState<{
3331
title: string

0 commit comments

Comments
 (0)