Skip to content

Commit b06e20f

Browse files
committed
Refactor response history management to correctly update existing entries
1 parent 02a4ab3 commit b06e20f

10 files changed

Lines changed: 78 additions & 54 deletions

File tree

‎packages/shared/src/constants/dictionary.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ export const dictionary = {
4444
},
4545

4646
warning_message: {
47-
REVIEW_ONGOING:
48-
'Another response review is currently ongoing. Would you like to switch to the new one?',
47+
PREVIEW_ONGOING: 'A new response has been received, switch now?',
4948
SKIPPING_INVALID_PATH: (file_path: string) =>
5049
`Skipping applying change to invalid path: ${file_path}`,
5150
CODE_COMPLETIONS_NO_SELECTION:

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,17 @@ export const ResponsePreview: FC<Props> = (props) => {
132132
}`}
133133
>
134134
<div className={styles['list__file__left']}>
135-
{files_in_preview.length > 1 && (
136-
<Checkbox
137-
checked={file.is_checked}
138-
on_change={(checked) => {
139-
props.on_toggle_file({
140-
file_path: file.file_path,
141-
workspace_name: file.workspace_name,
142-
is_checked: checked
143-
})
144-
}}
145-
/>
146-
)}
135+
<Checkbox
136+
checked={file.is_checked}
137+
disabled={files_in_preview.length == 1}
138+
on_change={(checked) => {
139+
props.on_toggle_file({
140+
file_path: file.file_path,
141+
workspace_name: file.workspace_name,
142+
is_checked: checked
143+
})
144+
}}
145+
/>
147146
<div
148147
className={cn(styles['list__file__left__label'], {
149148
[styles['list__file__left__label--new']]: file.is_new,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
display: flex;
5050
gap: var(--padding-8px);
5151
padding: var(--padding-12px);
52-
border-top: 1px solid var(--vscode-sideBarSectionHeader-border);
52+
border-top: 1px solid var(--cwc-border-color);
5353

5454
> button {
5555
flex: 1;
@@ -60,7 +60,7 @@
6060
position: relative;
6161
z-index: 1;
6262
border-radius: var(--border-radius-12px);
63-
border: 1px solid var(--vscode-sideBarSectionHeader-border);
63+
border: 1px solid var(--cwc-border-color);
6464
width: 100%;
6565
max-width: 320px;
6666
background-color: var(--vscode-quickInput-background);

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { process_chat_response, CommandArgs } from './response-processor'
1919
import { Checkpoint } from '../checkpoints-command/types'
2020
import { CHECKPOINTS_STATE_KEY } from '@/constants/state-keys'
2121

22+
let in_progress = false
23+
2224
export const apply_chat_response_command = (
2325
context: vscode.ExtensionContext,
2426
panel_provider: PanelProvider,
@@ -50,10 +52,24 @@ export const apply_chat_response_command = (
5052
return
5153
}
5254

55+
if (in_progress) {
56+
panel_provider.send_message({
57+
command: 'NEW_RESPONSE_RECEIVED',
58+
response: chat_response,
59+
raw_instructions: args?.raw_instructions
60+
})
61+
}
62+
63+
if (in_progress && !response_preview_promise_resolve) {
64+
// Running intelligent update before response preview...
65+
return
66+
}
67+
in_progress = true
68+
5369
if (response_preview_promise_resolve) {
54-
const choice = await vscode.window.showWarningMessage(
55-
dictionary.warning_message.REVIEW_ONGOING,
56-
{ modal: true },
70+
// Previewing response...
71+
const choice = await vscode.window.showInformationMessage(
72+
dictionary.warning_message.PREVIEW_ONGOING,
5773
'Switch'
5874
)
5975

@@ -204,8 +220,9 @@ export const apply_chat_response_command = (
204220
`An error occurred while applying changes: ${err.message}`
205221
)
206222
} finally {
223+
in_progress = false
207224
if (before_checkpoint) {
208-
await delete_checkpoint({
225+
delete_checkpoint({
209226
context,
210227
checkpoint_to_delete: before_checkpoint
211228
})

‎packages/vscode/src/views/panel/frontend/Main/Main.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ type Props = {
2424
response: string
2525
raw_instructions?: string
2626
created_at: number
27-
lines_added: number
28-
lines_removed: number
27+
lines_added?: number
28+
lines_removed?: number
2929
files?: FileInPreview[]
3030
}[]
3131
selected_history_item_created_at?: number

‎packages/vscode/src/views/panel/frontend/Main/MainView/MainView.module.scss‎

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

7070
&__stats {
7171
display: flex;
72-
gap: var(--padding-4px);
72+
gap: var(--padding-2px);
7373
flex-shrink: 0;
7474

7575
&--added {

‎packages/vscode/src/views/panel/frontend/Main/MainView/MainView.tsx‎

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ type Props = {
8989
response: string
9090
raw_instructions?: string
9191
created_at: number
92-
lines_added: number
93-
lines_removed: number
92+
lines_added?: number
93+
lines_removed?: number
9494
files?: FileInPreview[]
9595
}[]
9696
on_response_history_item_click: (item: {
@@ -208,16 +208,23 @@ export const MainView: React.FC<Props> = (props) => {
208208
{item.raw_instructions || 'Response without instructions'}
209209
</span>
210210
<div className={styles['responses__item__right']}>
211-
<div className={styles['responses__item__stats']}>
212-
<span className={styles['responses__item__stats--added']}>
213-
+{item.lines_added}
214-
</span>
215-
<span
216-
className={styles['responses__item__stats--removed']}
217-
>
218-
-{item.lines_removed}
219-
</span>
220-
</div>
211+
{item.lines_added !== undefined &&
212+
item.lines_removed !== undefined && (
213+
<div className={styles['responses__item__stats']}>
214+
<span
215+
className={styles['responses__item__stats--added']}
216+
>
217+
+{item.lines_added}
218+
</span>
219+
<span
220+
className={
221+
styles['responses__item__stats--removed']
222+
}
223+
>
224+
-{item.lines_removed}
225+
</span>
226+
</div>
227+
)}
221228
<span className={styles['responses__item__date']}>
222229
{dayjs(item.created_at).fromNow()}
223230
</span>

‎packages/vscode/src/views/panel/frontend/components/Footer/Footer.module.scss‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
justify-content: space-between;
77
gap: var(--padding-4px);
88
padding: var(--padding-8px) var(--padding-12px);
9-
border-top: 1px solid var(--vscode-sideBarSectionHeader-border);
9+
border-top: 1px solid var(--cwc-border-color);
1010

1111
> div {
1212
display: flex;

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ type ResponseHistoryItem = {
1414
response: string
1515
raw_instructions?: string
1616
created_at: number
17-
lines_added: number
18-
lines_removed: number
17+
lines_added?: number
18+
lines_removed?: number
1919
files?: FileInPreview[]
2020
}
2121

@@ -160,10 +160,10 @@ export const use_panel = (vscode: any) => {
160160
})
161161
set_response_history((current_history) => {
162162
const history_item_index = current_history.findIndex(
163-
(item) => item.created_at === selected_history_item_created_at
163+
(item) => item.created_at == selected_history_item_created_at
164164
)
165165

166-
if (history_item_index === -1) {
166+
if (history_item_index == -1) {
167167
return current_history
168168
}
169169

@@ -176,11 +176,11 @@ export const use_panel = (vscode: any) => {
176176

177177
const file_in_history_index = files_in_history.findIndex(
178178
(f) =>
179-
f.file_path === message.file.file_path &&
180-
f.workspace_name === message.file.workspace_name
179+
f.file_path == message.file.file_path &&
180+
f.workspace_name == message.file.workspace_name
181181
)
182182

183-
if (file_in_history_index !== -1) {
183+
if (file_in_history_index != -1) {
184184
files_in_history[file_in_history_index] = message.file
185185
} else {
186186
files_in_history.push(message.file)
@@ -242,12 +242,12 @@ export const use_panel = (vscode: any) => {
242242
}
243243
])
244244
} else {
245-
const is_duplicate = response_history.some(
245+
const duplicate_index = response_history.findIndex(
246246
(item) =>
247247
item.response == message.response &&
248248
item.raw_instructions == message.raw_instructions
249249
)
250-
if (!is_duplicate) {
250+
if (duplicate_index == -1) {
251251
const new_item = {
252252
response: message.response,
253253
raw_instructions: message.raw_instructions,
@@ -261,13 +261,15 @@ export const use_panel = (vscode: any) => {
261261
set_selected_history_item_created_at(now)
262262
}
263263
} else {
264-
set_selected_history_item_created_at(
265-
response_history.find(
266-
(item) =>
267-
item.response == message.response &&
268-
item.raw_instructions == message.raw_instructions
269-
)?.created_at
270-
)
264+
const new_history = [...response_history]
265+
const existing_item = new_history[duplicate_index]
266+
new_history[duplicate_index] = {
267+
...existing_item,
268+
...message,
269+
created_at: existing_item.created_at
270+
}
271+
set_response_history(new_history)
272+
set_selected_history_item_created_at(existing_item.created_at)
271273
}
272274
}
273275
} else if (message.command == 'CONTEXT_SIZE_WARNING_THRESHOLD') {

‎packages/vscode/src/views/panel/types/messages.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,8 @@ export interface NewResponseReceivedMessage extends BaseMessage {
571571
command: 'NEW_RESPONSE_RECEIVED'
572572
response: string
573573
raw_instructions?: string
574-
lines_added: number
575-
lines_removed: number
574+
lines_added?: number
575+
lines_removed?: number
576576
files?: FileInPreview[]
577577
}
578578

0 commit comments

Comments
 (0)